p2p: implement new Transport interface (#5791)

This implements a new `Transport` interface and related types for the P2P refactor in #5670. Previously, `conn.MConnection` was very tightly coupled to the `Peer` implementation -- in order to allow alternative non-multiplexed transports (e.g. QUIC), MConnection has now been moved below the `Transport` interface, as `MConnTransport`, and decoupled from the peer. Since the `p2p` package is not covered by our Go API stability, this is not considered a breaking change, and not listed in the changelog.

The initial approach was to implement the new interface in its final form (which also involved possible protocol changes, see https://github.com/tendermint/spec/pull/227). However, it turned out that this would require a large amount of changes to existing P2P code because of the previous tight coupling between `Peer` and `MConnection` and the reliance on subtleties in the MConnection behavior. Instead, I have broadened the `Transport` interface to expose much of the existing MConnection interface, preserved much of the existing MConnection logic and behavior in the transport implementation, and tried to make as few changes to the rest of the P2P stack as possible. We will instead reduce this interface gradually as we refactor other parts of the P2P stack.

The low-level transport code and protocol (e.g. MConnection, SecretConnection and so on) has not been significantly changed, and refactoring this is not a priority until we come up with a plan for QUIC adoption, as we may end up discarding the MConnection code entirely.

There are no tests of the new `MConnTransport`, as this code is likely to evolve as we proceed with the P2P refactor, but tests should be added before a final release. The E2E tests are sufficient for basic validation in the meanwhile.
This commit is contained in:
Erik Grinaker
2020-12-15 16:08:16 +01:00
committed by GitHub
parent 6dce4ef701
commit bcfc889f25
16 changed files with 1102 additions and 1595 deletions

View File

@@ -3,6 +3,7 @@ package log
import (
"io"
"os"
"sync"
"testing"
"github.com/go-kit/kit/log/term"
@@ -10,7 +11,8 @@ import (
var (
// reuse the same logger across all tests
_testingLogger Logger
_testingLoggerMutex = sync.Mutex{}
_testingLogger Logger
)
// TestingLogger returns a TMLogger which writes to STDOUT if testing being run
@@ -30,6 +32,8 @@ func TestingLogger() Logger {
// inside a test (not in the init func) because
// verbose flag only set at the time of testing.
func TestingLoggerWithOutput(w io.Writer) Logger {
_testingLoggerMutex.Lock()
defer _testingLoggerMutex.Unlock()
if _testingLogger != nil {
return _testingLogger
}
@@ -46,6 +50,8 @@ func TestingLoggerWithOutput(w io.Writer) Logger {
// TestingLoggerWithColorFn allow you to provide your own color function. See
// TestingLogger for documentation.
func TestingLoggerWithColorFn(colorFn func(keyvals ...interface{}) term.FgBgColor) Logger {
_testingLoggerMutex.Lock()
defer _testingLoggerMutex.Unlock()
if _testingLogger != nil {
return _testingLogger
}