You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

932 lines
23 KiB

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.
4 years ago
p2p: file descriptor leaks (#3150) * close peer's connection to avoid fd leak Fixes #2967 * rename peer#Addr to RemoteAddr * fix test * fixes after Ethan's review * bring back the check * changelog entry * write a test for switch#acceptRoutine * increase timeouts? :( * remove extra assertNPeersWithTimeout * simplify test * assert number of peers (just to be safe) * Cleanup in OnStop * run tests with verbose flag on CircleCI * spawn a reading routine to prevent connection from closing * get port from the listener random port is faster, but often results in ``` panic: listen tcp 127.0.0.1:44068: bind: address already in use [recovered] panic: listen tcp 127.0.0.1:44068: bind: address already in use goroutine 79 [running]: testing.tRunner.func1(0xc0001bd600) /usr/local/go/src/testing/testing.go:792 +0x387 panic(0x974d20, 0xc0001b0500) /usr/local/go/src/runtime/panic.go:513 +0x1b9 github.com/tendermint/tendermint/p2p.MakeSwitch(0xc0000f42a0, 0x0, 0x9fb9cc, 0x9, 0x9fc346, 0xb, 0xb42128, 0x0, 0x0, 0x0, ...) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:182 +0xa28 github.com/tendermint/tendermint/p2p.MakeConnectedSwitches(0xc0000f42a0, 0x2, 0xb42128, 0xb41eb8, 0x4f1205, 0xc0001bed80, 0x4f16ed) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:75 +0xf9 github.com/tendermint/tendermint/p2p.MakeSwitchPair(0xbb8d20, 0xc0001bd600, 0xb42128, 0x2f7, 0x4f16c0) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:94 +0x4c github.com/tendermint/tendermint/p2p.TestSwitches(0xc0001bd600) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:117 +0x58 testing.tRunner(0xc0001bd600, 0xb42038) /usr/local/go/src/testing/testing.go:827 +0xbf created by testing.(*T).Run /usr/local/go/src/testing/testing.go:878 +0x353 exit status 2 FAIL github.com/tendermint/tendermint/p2p 0.350s ```
6 years ago
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.
4 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
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.
4 years ago
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.
4 years ago
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.
4 years ago
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.
4 years ago
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.
4 years ago
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.
4 years ago
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.
4 years ago
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.
4 years ago
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.
4 years ago
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.
4 years ago
p2p: file descriptor leaks (#3150) * close peer's connection to avoid fd leak Fixes #2967 * rename peer#Addr to RemoteAddr * fix test * fixes after Ethan's review * bring back the check * changelog entry * write a test for switch#acceptRoutine * increase timeouts? :( * remove extra assertNPeersWithTimeout * simplify test * assert number of peers (just to be safe) * Cleanup in OnStop * run tests with verbose flag on CircleCI * spawn a reading routine to prevent connection from closing * get port from the listener random port is faster, but often results in ``` panic: listen tcp 127.0.0.1:44068: bind: address already in use [recovered] panic: listen tcp 127.0.0.1:44068: bind: address already in use goroutine 79 [running]: testing.tRunner.func1(0xc0001bd600) /usr/local/go/src/testing/testing.go:792 +0x387 panic(0x974d20, 0xc0001b0500) /usr/local/go/src/runtime/panic.go:513 +0x1b9 github.com/tendermint/tendermint/p2p.MakeSwitch(0xc0000f42a0, 0x0, 0x9fb9cc, 0x9, 0x9fc346, 0xb, 0xb42128, 0x0, 0x0, 0x0, ...) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:182 +0xa28 github.com/tendermint/tendermint/p2p.MakeConnectedSwitches(0xc0000f42a0, 0x2, 0xb42128, 0xb41eb8, 0x4f1205, 0xc0001bed80, 0x4f16ed) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:75 +0xf9 github.com/tendermint/tendermint/p2p.MakeSwitchPair(0xbb8d20, 0xc0001bd600, 0xb42128, 0x2f7, 0x4f16c0) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:94 +0x4c github.com/tendermint/tendermint/p2p.TestSwitches(0xc0001bd600) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:117 +0x58 testing.tRunner(0xc0001bd600, 0xb42038) /usr/local/go/src/testing/testing.go:827 +0xbf created by testing.(*T).Run /usr/local/go/src/testing/testing.go:878 +0x353 exit status 2 FAIL github.com/tendermint/tendermint/p2p 0.350s ```
6 years ago
p2p: file descriptor leaks (#3150) * close peer's connection to avoid fd leak Fixes #2967 * rename peer#Addr to RemoteAddr * fix test * fixes after Ethan's review * bring back the check * changelog entry * write a test for switch#acceptRoutine * increase timeouts? :( * remove extra assertNPeersWithTimeout * simplify test * assert number of peers (just to be safe) * Cleanup in OnStop * run tests with verbose flag on CircleCI * spawn a reading routine to prevent connection from closing * get port from the listener random port is faster, but often results in ``` panic: listen tcp 127.0.0.1:44068: bind: address already in use [recovered] panic: listen tcp 127.0.0.1:44068: bind: address already in use goroutine 79 [running]: testing.tRunner.func1(0xc0001bd600) /usr/local/go/src/testing/testing.go:792 +0x387 panic(0x974d20, 0xc0001b0500) /usr/local/go/src/runtime/panic.go:513 +0x1b9 github.com/tendermint/tendermint/p2p.MakeSwitch(0xc0000f42a0, 0x0, 0x9fb9cc, 0x9, 0x9fc346, 0xb, 0xb42128, 0x0, 0x0, 0x0, ...) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:182 +0xa28 github.com/tendermint/tendermint/p2p.MakeConnectedSwitches(0xc0000f42a0, 0x2, 0xb42128, 0xb41eb8, 0x4f1205, 0xc0001bed80, 0x4f16ed) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:75 +0xf9 github.com/tendermint/tendermint/p2p.MakeSwitchPair(0xbb8d20, 0xc0001bd600, 0xb42128, 0x2f7, 0x4f16c0) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:94 +0x4c github.com/tendermint/tendermint/p2p.TestSwitches(0xc0001bd600) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:117 +0x58 testing.tRunner(0xc0001bd600, 0xb42038) /usr/local/go/src/testing/testing.go:827 +0xbf created by testing.(*T).Run /usr/local/go/src/testing/testing.go:878 +0x353 exit status 2 FAIL github.com/tendermint/tendermint/p2p 0.350s ```
6 years ago
p2p: file descriptor leaks (#3150) * close peer's connection to avoid fd leak Fixes #2967 * rename peer#Addr to RemoteAddr * fix test * fixes after Ethan's review * bring back the check * changelog entry * write a test for switch#acceptRoutine * increase timeouts? :( * remove extra assertNPeersWithTimeout * simplify test * assert number of peers (just to be safe) * Cleanup in OnStop * run tests with verbose flag on CircleCI * spawn a reading routine to prevent connection from closing * get port from the listener random port is faster, but often results in ``` panic: listen tcp 127.0.0.1:44068: bind: address already in use [recovered] panic: listen tcp 127.0.0.1:44068: bind: address already in use goroutine 79 [running]: testing.tRunner.func1(0xc0001bd600) /usr/local/go/src/testing/testing.go:792 +0x387 panic(0x974d20, 0xc0001b0500) /usr/local/go/src/runtime/panic.go:513 +0x1b9 github.com/tendermint/tendermint/p2p.MakeSwitch(0xc0000f42a0, 0x0, 0x9fb9cc, 0x9, 0x9fc346, 0xb, 0xb42128, 0x0, 0x0, 0x0, ...) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:182 +0xa28 github.com/tendermint/tendermint/p2p.MakeConnectedSwitches(0xc0000f42a0, 0x2, 0xb42128, 0xb41eb8, 0x4f1205, 0xc0001bed80, 0x4f16ed) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:75 +0xf9 github.com/tendermint/tendermint/p2p.MakeSwitchPair(0xbb8d20, 0xc0001bd600, 0xb42128, 0x2f7, 0x4f16c0) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:94 +0x4c github.com/tendermint/tendermint/p2p.TestSwitches(0xc0001bd600) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:117 +0x58 testing.tRunner(0xc0001bd600, 0xb42038) /usr/local/go/src/testing/testing.go:827 +0xbf created by testing.(*T).Run /usr/local/go/src/testing/testing.go:878 +0x353 exit status 2 FAIL github.com/tendermint/tendermint/p2p 0.350s ```
6 years ago
p2p: file descriptor leaks (#3150) * close peer's connection to avoid fd leak Fixes #2967 * rename peer#Addr to RemoteAddr * fix test * fixes after Ethan's review * bring back the check * changelog entry * write a test for switch#acceptRoutine * increase timeouts? :( * remove extra assertNPeersWithTimeout * simplify test * assert number of peers (just to be safe) * Cleanup in OnStop * run tests with verbose flag on CircleCI * spawn a reading routine to prevent connection from closing * get port from the listener random port is faster, but often results in ``` panic: listen tcp 127.0.0.1:44068: bind: address already in use [recovered] panic: listen tcp 127.0.0.1:44068: bind: address already in use goroutine 79 [running]: testing.tRunner.func1(0xc0001bd600) /usr/local/go/src/testing/testing.go:792 +0x387 panic(0x974d20, 0xc0001b0500) /usr/local/go/src/runtime/panic.go:513 +0x1b9 github.com/tendermint/tendermint/p2p.MakeSwitch(0xc0000f42a0, 0x0, 0x9fb9cc, 0x9, 0x9fc346, 0xb, 0xb42128, 0x0, 0x0, 0x0, ...) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:182 +0xa28 github.com/tendermint/tendermint/p2p.MakeConnectedSwitches(0xc0000f42a0, 0x2, 0xb42128, 0xb41eb8, 0x4f1205, 0xc0001bed80, 0x4f16ed) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:75 +0xf9 github.com/tendermint/tendermint/p2p.MakeSwitchPair(0xbb8d20, 0xc0001bd600, 0xb42128, 0x2f7, 0x4f16c0) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:94 +0x4c github.com/tendermint/tendermint/p2p.TestSwitches(0xc0001bd600) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:117 +0x58 testing.tRunner(0xc0001bd600, 0xb42038) /usr/local/go/src/testing/testing.go:827 +0xbf created by testing.(*T).Run /usr/local/go/src/testing/testing.go:878 +0x353 exit status 2 FAIL github.com/tendermint/tendermint/p2p 0.350s ```
6 years ago
p2p: file descriptor leaks (#3150) * close peer's connection to avoid fd leak Fixes #2967 * rename peer#Addr to RemoteAddr * fix test * fixes after Ethan's review * bring back the check * changelog entry * write a test for switch#acceptRoutine * increase timeouts? :( * remove extra assertNPeersWithTimeout * simplify test * assert number of peers (just to be safe) * Cleanup in OnStop * run tests with verbose flag on CircleCI * spawn a reading routine to prevent connection from closing * get port from the listener random port is faster, but often results in ``` panic: listen tcp 127.0.0.1:44068: bind: address already in use [recovered] panic: listen tcp 127.0.0.1:44068: bind: address already in use goroutine 79 [running]: testing.tRunner.func1(0xc0001bd600) /usr/local/go/src/testing/testing.go:792 +0x387 panic(0x974d20, 0xc0001b0500) /usr/local/go/src/runtime/panic.go:513 +0x1b9 github.com/tendermint/tendermint/p2p.MakeSwitch(0xc0000f42a0, 0x0, 0x9fb9cc, 0x9, 0x9fc346, 0xb, 0xb42128, 0x0, 0x0, 0x0, ...) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:182 +0xa28 github.com/tendermint/tendermint/p2p.MakeConnectedSwitches(0xc0000f42a0, 0x2, 0xb42128, 0xb41eb8, 0x4f1205, 0xc0001bed80, 0x4f16ed) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:75 +0xf9 github.com/tendermint/tendermint/p2p.MakeSwitchPair(0xbb8d20, 0xc0001bd600, 0xb42128, 0x2f7, 0x4f16c0) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:94 +0x4c github.com/tendermint/tendermint/p2p.TestSwitches(0xc0001bd600) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:117 +0x58 testing.tRunner(0xc0001bd600, 0xb42038) /usr/local/go/src/testing/testing.go:827 +0xbf created by testing.(*T).Run /usr/local/go/src/testing/testing.go:878 +0x353 exit status 2 FAIL github.com/tendermint/tendermint/p2p 0.350s ```
6 years ago
p2p: file descriptor leaks (#3150) * close peer's connection to avoid fd leak Fixes #2967 * rename peer#Addr to RemoteAddr * fix test * fixes after Ethan's review * bring back the check * changelog entry * write a test for switch#acceptRoutine * increase timeouts? :( * remove extra assertNPeersWithTimeout * simplify test * assert number of peers (just to be safe) * Cleanup in OnStop * run tests with verbose flag on CircleCI * spawn a reading routine to prevent connection from closing * get port from the listener random port is faster, but often results in ``` panic: listen tcp 127.0.0.1:44068: bind: address already in use [recovered] panic: listen tcp 127.0.0.1:44068: bind: address already in use goroutine 79 [running]: testing.tRunner.func1(0xc0001bd600) /usr/local/go/src/testing/testing.go:792 +0x387 panic(0x974d20, 0xc0001b0500) /usr/local/go/src/runtime/panic.go:513 +0x1b9 github.com/tendermint/tendermint/p2p.MakeSwitch(0xc0000f42a0, 0x0, 0x9fb9cc, 0x9, 0x9fc346, 0xb, 0xb42128, 0x0, 0x0, 0x0, ...) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:182 +0xa28 github.com/tendermint/tendermint/p2p.MakeConnectedSwitches(0xc0000f42a0, 0x2, 0xb42128, 0xb41eb8, 0x4f1205, 0xc0001bed80, 0x4f16ed) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:75 +0xf9 github.com/tendermint/tendermint/p2p.MakeSwitchPair(0xbb8d20, 0xc0001bd600, 0xb42128, 0x2f7, 0x4f16c0) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:94 +0x4c github.com/tendermint/tendermint/p2p.TestSwitches(0xc0001bd600) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:117 +0x58 testing.tRunner(0xc0001bd600, 0xb42038) /usr/local/go/src/testing/testing.go:827 +0xbf created by testing.(*T).Run /usr/local/go/src/testing/testing.go:878 +0x353 exit status 2 FAIL github.com/tendermint/tendermint/p2p 0.350s ```
6 years ago
p2p: file descriptor leaks (#3150) * close peer's connection to avoid fd leak Fixes #2967 * rename peer#Addr to RemoteAddr * fix test * fixes after Ethan's review * bring back the check * changelog entry * write a test for switch#acceptRoutine * increase timeouts? :( * remove extra assertNPeersWithTimeout * simplify test * assert number of peers (just to be safe) * Cleanup in OnStop * run tests with verbose flag on CircleCI * spawn a reading routine to prevent connection from closing * get port from the listener random port is faster, but often results in ``` panic: listen tcp 127.0.0.1:44068: bind: address already in use [recovered] panic: listen tcp 127.0.0.1:44068: bind: address already in use goroutine 79 [running]: testing.tRunner.func1(0xc0001bd600) /usr/local/go/src/testing/testing.go:792 +0x387 panic(0x974d20, 0xc0001b0500) /usr/local/go/src/runtime/panic.go:513 +0x1b9 github.com/tendermint/tendermint/p2p.MakeSwitch(0xc0000f42a0, 0x0, 0x9fb9cc, 0x9, 0x9fc346, 0xb, 0xb42128, 0x0, 0x0, 0x0, ...) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:182 +0xa28 github.com/tendermint/tendermint/p2p.MakeConnectedSwitches(0xc0000f42a0, 0x2, 0xb42128, 0xb41eb8, 0x4f1205, 0xc0001bed80, 0x4f16ed) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:75 +0xf9 github.com/tendermint/tendermint/p2p.MakeSwitchPair(0xbb8d20, 0xc0001bd600, 0xb42128, 0x2f7, 0x4f16c0) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:94 +0x4c github.com/tendermint/tendermint/p2p.TestSwitches(0xc0001bd600) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:117 +0x58 testing.tRunner(0xc0001bd600, 0xb42038) /usr/local/go/src/testing/testing.go:827 +0xbf created by testing.(*T).Run /usr/local/go/src/testing/testing.go:878 +0x353 exit status 2 FAIL github.com/tendermint/tendermint/p2p 0.350s ```
6 years ago
p2p: file descriptor leaks (#3150) * close peer's connection to avoid fd leak Fixes #2967 * rename peer#Addr to RemoteAddr * fix test * fixes after Ethan's review * bring back the check * changelog entry * write a test for switch#acceptRoutine * increase timeouts? :( * remove extra assertNPeersWithTimeout * simplify test * assert number of peers (just to be safe) * Cleanup in OnStop * run tests with verbose flag on CircleCI * spawn a reading routine to prevent connection from closing * get port from the listener random port is faster, but often results in ``` panic: listen tcp 127.0.0.1:44068: bind: address already in use [recovered] panic: listen tcp 127.0.0.1:44068: bind: address already in use goroutine 79 [running]: testing.tRunner.func1(0xc0001bd600) /usr/local/go/src/testing/testing.go:792 +0x387 panic(0x974d20, 0xc0001b0500) /usr/local/go/src/runtime/panic.go:513 +0x1b9 github.com/tendermint/tendermint/p2p.MakeSwitch(0xc0000f42a0, 0x0, 0x9fb9cc, 0x9, 0x9fc346, 0xb, 0xb42128, 0x0, 0x0, 0x0, ...) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:182 +0xa28 github.com/tendermint/tendermint/p2p.MakeConnectedSwitches(0xc0000f42a0, 0x2, 0xb42128, 0xb41eb8, 0x4f1205, 0xc0001bed80, 0x4f16ed) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:75 +0xf9 github.com/tendermint/tendermint/p2p.MakeSwitchPair(0xbb8d20, 0xc0001bd600, 0xb42128, 0x2f7, 0x4f16c0) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:94 +0x4c github.com/tendermint/tendermint/p2p.TestSwitches(0xc0001bd600) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:117 +0x58 testing.tRunner(0xc0001bd600, 0xb42038) /usr/local/go/src/testing/testing.go:827 +0xbf created by testing.(*T).Run /usr/local/go/src/testing/testing.go:878 +0x353 exit status 2 FAIL github.com/tendermint/tendermint/p2p 0.350s ```
6 years ago
p2p: file descriptor leaks (#3150) * close peer's connection to avoid fd leak Fixes #2967 * rename peer#Addr to RemoteAddr * fix test * fixes after Ethan's review * bring back the check * changelog entry * write a test for switch#acceptRoutine * increase timeouts? :( * remove extra assertNPeersWithTimeout * simplify test * assert number of peers (just to be safe) * Cleanup in OnStop * run tests with verbose flag on CircleCI * spawn a reading routine to prevent connection from closing * get port from the listener random port is faster, but often results in ``` panic: listen tcp 127.0.0.1:44068: bind: address already in use [recovered] panic: listen tcp 127.0.0.1:44068: bind: address already in use goroutine 79 [running]: testing.tRunner.func1(0xc0001bd600) /usr/local/go/src/testing/testing.go:792 +0x387 panic(0x974d20, 0xc0001b0500) /usr/local/go/src/runtime/panic.go:513 +0x1b9 github.com/tendermint/tendermint/p2p.MakeSwitch(0xc0000f42a0, 0x0, 0x9fb9cc, 0x9, 0x9fc346, 0xb, 0xb42128, 0x0, 0x0, 0x0, ...) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:182 +0xa28 github.com/tendermint/tendermint/p2p.MakeConnectedSwitches(0xc0000f42a0, 0x2, 0xb42128, 0xb41eb8, 0x4f1205, 0xc0001bed80, 0x4f16ed) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:75 +0xf9 github.com/tendermint/tendermint/p2p.MakeSwitchPair(0xbb8d20, 0xc0001bd600, 0xb42128, 0x2f7, 0x4f16c0) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:94 +0x4c github.com/tendermint/tendermint/p2p.TestSwitches(0xc0001bd600) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:117 +0x58 testing.tRunner(0xc0001bd600, 0xb42038) /usr/local/go/src/testing/testing.go:827 +0xbf created by testing.(*T).Run /usr/local/go/src/testing/testing.go:878 +0x353 exit status 2 FAIL github.com/tendermint/tendermint/p2p 0.350s ```
6 years ago
p2p: file descriptor leaks (#3150) * close peer's connection to avoid fd leak Fixes #2967 * rename peer#Addr to RemoteAddr * fix test * fixes after Ethan's review * bring back the check * changelog entry * write a test for switch#acceptRoutine * increase timeouts? :( * remove extra assertNPeersWithTimeout * simplify test * assert number of peers (just to be safe) * Cleanup in OnStop * run tests with verbose flag on CircleCI * spawn a reading routine to prevent connection from closing * get port from the listener random port is faster, but often results in ``` panic: listen tcp 127.0.0.1:44068: bind: address already in use [recovered] panic: listen tcp 127.0.0.1:44068: bind: address already in use goroutine 79 [running]: testing.tRunner.func1(0xc0001bd600) /usr/local/go/src/testing/testing.go:792 +0x387 panic(0x974d20, 0xc0001b0500) /usr/local/go/src/runtime/panic.go:513 +0x1b9 github.com/tendermint/tendermint/p2p.MakeSwitch(0xc0000f42a0, 0x0, 0x9fb9cc, 0x9, 0x9fc346, 0xb, 0xb42128, 0x0, 0x0, 0x0, ...) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:182 +0xa28 github.com/tendermint/tendermint/p2p.MakeConnectedSwitches(0xc0000f42a0, 0x2, 0xb42128, 0xb41eb8, 0x4f1205, 0xc0001bed80, 0x4f16ed) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:75 +0xf9 github.com/tendermint/tendermint/p2p.MakeSwitchPair(0xbb8d20, 0xc0001bd600, 0xb42128, 0x2f7, 0x4f16c0) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:94 +0x4c github.com/tendermint/tendermint/p2p.TestSwitches(0xc0001bd600) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:117 +0x58 testing.tRunner(0xc0001bd600, 0xb42038) /usr/local/go/src/testing/testing.go:827 +0xbf created by testing.(*T).Run /usr/local/go/src/testing/testing.go:878 +0x353 exit status 2 FAIL github.com/tendermint/tendermint/p2p 0.350s ```
6 years ago
p2p: file descriptor leaks (#3150) * close peer's connection to avoid fd leak Fixes #2967 * rename peer#Addr to RemoteAddr * fix test * fixes after Ethan's review * bring back the check * changelog entry * write a test for switch#acceptRoutine * increase timeouts? :( * remove extra assertNPeersWithTimeout * simplify test * assert number of peers (just to be safe) * Cleanup in OnStop * run tests with verbose flag on CircleCI * spawn a reading routine to prevent connection from closing * get port from the listener random port is faster, but often results in ``` panic: listen tcp 127.0.0.1:44068: bind: address already in use [recovered] panic: listen tcp 127.0.0.1:44068: bind: address already in use goroutine 79 [running]: testing.tRunner.func1(0xc0001bd600) /usr/local/go/src/testing/testing.go:792 +0x387 panic(0x974d20, 0xc0001b0500) /usr/local/go/src/runtime/panic.go:513 +0x1b9 github.com/tendermint/tendermint/p2p.MakeSwitch(0xc0000f42a0, 0x0, 0x9fb9cc, 0x9, 0x9fc346, 0xb, 0xb42128, 0x0, 0x0, 0x0, ...) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:182 +0xa28 github.com/tendermint/tendermint/p2p.MakeConnectedSwitches(0xc0000f42a0, 0x2, 0xb42128, 0xb41eb8, 0x4f1205, 0xc0001bed80, 0x4f16ed) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:75 +0xf9 github.com/tendermint/tendermint/p2p.MakeSwitchPair(0xbb8d20, 0xc0001bd600, 0xb42128, 0x2f7, 0x4f16c0) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:94 +0x4c github.com/tendermint/tendermint/p2p.TestSwitches(0xc0001bd600) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:117 +0x58 testing.tRunner(0xc0001bd600, 0xb42038) /usr/local/go/src/testing/testing.go:827 +0xbf created by testing.(*T).Run /usr/local/go/src/testing/testing.go:878 +0x353 exit status 2 FAIL github.com/tendermint/tendermint/p2p 0.350s ```
6 years ago
p2p: file descriptor leaks (#3150) * close peer's connection to avoid fd leak Fixes #2967 * rename peer#Addr to RemoteAddr * fix test * fixes after Ethan's review * bring back the check * changelog entry * write a test for switch#acceptRoutine * increase timeouts? :( * remove extra assertNPeersWithTimeout * simplify test * assert number of peers (just to be safe) * Cleanup in OnStop * run tests with verbose flag on CircleCI * spawn a reading routine to prevent connection from closing * get port from the listener random port is faster, but often results in ``` panic: listen tcp 127.0.0.1:44068: bind: address already in use [recovered] panic: listen tcp 127.0.0.1:44068: bind: address already in use goroutine 79 [running]: testing.tRunner.func1(0xc0001bd600) /usr/local/go/src/testing/testing.go:792 +0x387 panic(0x974d20, 0xc0001b0500) /usr/local/go/src/runtime/panic.go:513 +0x1b9 github.com/tendermint/tendermint/p2p.MakeSwitch(0xc0000f42a0, 0x0, 0x9fb9cc, 0x9, 0x9fc346, 0xb, 0xb42128, 0x0, 0x0, 0x0, ...) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:182 +0xa28 github.com/tendermint/tendermint/p2p.MakeConnectedSwitches(0xc0000f42a0, 0x2, 0xb42128, 0xb41eb8, 0x4f1205, 0xc0001bed80, 0x4f16ed) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:75 +0xf9 github.com/tendermint/tendermint/p2p.MakeSwitchPair(0xbb8d20, 0xc0001bd600, 0xb42128, 0x2f7, 0x4f16c0) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:94 +0x4c github.com/tendermint/tendermint/p2p.TestSwitches(0xc0001bd600) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:117 +0x58 testing.tRunner(0xc0001bd600, 0xb42038) /usr/local/go/src/testing/testing.go:827 +0xbf created by testing.(*T).Run /usr/local/go/src/testing/testing.go:878 +0x353 exit status 2 FAIL github.com/tendermint/tendermint/p2p 0.350s ```
6 years ago
p2p: file descriptor leaks (#3150) * close peer's connection to avoid fd leak Fixes #2967 * rename peer#Addr to RemoteAddr * fix test * fixes after Ethan's review * bring back the check * changelog entry * write a test for switch#acceptRoutine * increase timeouts? :( * remove extra assertNPeersWithTimeout * simplify test * assert number of peers (just to be safe) * Cleanup in OnStop * run tests with verbose flag on CircleCI * spawn a reading routine to prevent connection from closing * get port from the listener random port is faster, but often results in ``` panic: listen tcp 127.0.0.1:44068: bind: address already in use [recovered] panic: listen tcp 127.0.0.1:44068: bind: address already in use goroutine 79 [running]: testing.tRunner.func1(0xc0001bd600) /usr/local/go/src/testing/testing.go:792 +0x387 panic(0x974d20, 0xc0001b0500) /usr/local/go/src/runtime/panic.go:513 +0x1b9 github.com/tendermint/tendermint/p2p.MakeSwitch(0xc0000f42a0, 0x0, 0x9fb9cc, 0x9, 0x9fc346, 0xb, 0xb42128, 0x0, 0x0, 0x0, ...) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:182 +0xa28 github.com/tendermint/tendermint/p2p.MakeConnectedSwitches(0xc0000f42a0, 0x2, 0xb42128, 0xb41eb8, 0x4f1205, 0xc0001bed80, 0x4f16ed) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:75 +0xf9 github.com/tendermint/tendermint/p2p.MakeSwitchPair(0xbb8d20, 0xc0001bd600, 0xb42128, 0x2f7, 0x4f16c0) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:94 +0x4c github.com/tendermint/tendermint/p2p.TestSwitches(0xc0001bd600) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:117 +0x58 testing.tRunner(0xc0001bd600, 0xb42038) /usr/local/go/src/testing/testing.go:827 +0xbf created by testing.(*T).Run /usr/local/go/src/testing/testing.go:878 +0x353 exit status 2 FAIL github.com/tendermint/tendermint/p2p 0.350s ```
6 years ago
p2p: file descriptor leaks (#3150) * close peer's connection to avoid fd leak Fixes #2967 * rename peer#Addr to RemoteAddr * fix test * fixes after Ethan's review * bring back the check * changelog entry * write a test for switch#acceptRoutine * increase timeouts? :( * remove extra assertNPeersWithTimeout * simplify test * assert number of peers (just to be safe) * Cleanup in OnStop * run tests with verbose flag on CircleCI * spawn a reading routine to prevent connection from closing * get port from the listener random port is faster, but often results in ``` panic: listen tcp 127.0.0.1:44068: bind: address already in use [recovered] panic: listen tcp 127.0.0.1:44068: bind: address already in use goroutine 79 [running]: testing.tRunner.func1(0xc0001bd600) /usr/local/go/src/testing/testing.go:792 +0x387 panic(0x974d20, 0xc0001b0500) /usr/local/go/src/runtime/panic.go:513 +0x1b9 github.com/tendermint/tendermint/p2p.MakeSwitch(0xc0000f42a0, 0x0, 0x9fb9cc, 0x9, 0x9fc346, 0xb, 0xb42128, 0x0, 0x0, 0x0, ...) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:182 +0xa28 github.com/tendermint/tendermint/p2p.MakeConnectedSwitches(0xc0000f42a0, 0x2, 0xb42128, 0xb41eb8, 0x4f1205, 0xc0001bed80, 0x4f16ed) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:75 +0xf9 github.com/tendermint/tendermint/p2p.MakeSwitchPair(0xbb8d20, 0xc0001bd600, 0xb42128, 0x2f7, 0x4f16c0) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:94 +0x4c github.com/tendermint/tendermint/p2p.TestSwitches(0xc0001bd600) /home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:117 +0x58 testing.tRunner(0xc0001bd600, 0xb42038) /usr/local/go/src/testing/testing.go:827 +0xbf created by testing.(*T).Run /usr/local/go/src/testing/testing.go:878 +0x353 exit status 2 FAIL github.com/tendermint/tendermint/p2p 0.350s ```
6 years ago
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.
4 years ago
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.
4 years ago
  1. package p2p
  2. import (
  3. "bytes"
  4. "context"
  5. "errors"
  6. "fmt"
  7. "io/ioutil"
  8. "net"
  9. "net/http"
  10. "net/http/httptest"
  11. "regexp"
  12. "strconv"
  13. "sync/atomic"
  14. "testing"
  15. "time"
  16. "github.com/prometheus/client_golang/prometheus/promhttp"
  17. "github.com/stretchr/testify/assert"
  18. "github.com/stretchr/testify/require"
  19. "github.com/tendermint/tendermint/config"
  20. "github.com/tendermint/tendermint/crypto/ed25519"
  21. tmsync "github.com/tendermint/tendermint/internal/libs/sync"
  22. "github.com/tendermint/tendermint/internal/p2p/conn"
  23. "github.com/tendermint/tendermint/libs/log"
  24. "github.com/tendermint/tendermint/types"
  25. )
  26. var (
  27. cfg *config.P2PConfig
  28. ctx = context.Background()
  29. )
  30. func init() {
  31. cfg = config.DefaultP2PConfig()
  32. cfg.PexReactor = true
  33. cfg.AllowDuplicateIP = true
  34. }
  35. type PeerMessage struct {
  36. PeerID types.NodeID
  37. Bytes []byte
  38. Counter int
  39. }
  40. type TestReactor struct {
  41. BaseReactor
  42. mtx tmsync.Mutex
  43. channels []*conn.ChannelDescriptor
  44. logMessages bool
  45. msgsCounter int
  46. msgsReceived map[byte][]PeerMessage
  47. }
  48. func NewTestReactor(channels []*conn.ChannelDescriptor, logMessages bool) *TestReactor {
  49. tr := &TestReactor{
  50. channels: channels,
  51. logMessages: logMessages,
  52. msgsReceived: make(map[byte][]PeerMessage),
  53. }
  54. tr.BaseReactor = *NewBaseReactor("TestReactor", tr)
  55. tr.SetLogger(log.TestingLogger())
  56. return tr
  57. }
  58. func (tr *TestReactor) GetChannels() []*conn.ChannelDescriptor {
  59. return tr.channels
  60. }
  61. func (tr *TestReactor) AddPeer(peer Peer) {}
  62. func (tr *TestReactor) RemovePeer(peer Peer, reason interface{}) {}
  63. func (tr *TestReactor) Receive(chID byte, peer Peer, msgBytes []byte) {
  64. if tr.logMessages {
  65. tr.mtx.Lock()
  66. defer tr.mtx.Unlock()
  67. // fmt.Printf("Received: %X, %X\n", chID, msgBytes)
  68. tr.msgsReceived[chID] = append(tr.msgsReceived[chID], PeerMessage{peer.ID(), msgBytes, tr.msgsCounter})
  69. tr.msgsCounter++
  70. }
  71. }
  72. func (tr *TestReactor) getMsgs(chID byte) []PeerMessage {
  73. tr.mtx.Lock()
  74. defer tr.mtx.Unlock()
  75. return tr.msgsReceived[chID]
  76. }
  77. //-----------------------------------------------------------------------------
  78. // convenience method for creating two switches connected to each other.
  79. // XXX: note this uses net.Pipe and not a proper TCP conn
  80. func MakeSwitchPair(t testing.TB, initSwitch func(int, *Switch) *Switch) (*Switch, *Switch) {
  81. // Create two switches that will be interconnected.
  82. switches := MakeConnectedSwitches(cfg, 2, initSwitch, Connect2Switches)
  83. return switches[0], switches[1]
  84. }
  85. func initSwitchFunc(i int, sw *Switch) *Switch {
  86. sw.SetAddrBook(&AddrBookMock{
  87. Addrs: make(map[string]struct{}),
  88. OurAddrs: make(map[string]struct{})})
  89. // Make two reactors of two channels each
  90. sw.AddReactor("foo", NewTestReactor([]*conn.ChannelDescriptor{
  91. {ID: byte(0x00), Priority: 10},
  92. {ID: byte(0x01), Priority: 10},
  93. }, true))
  94. sw.AddReactor("bar", NewTestReactor([]*conn.ChannelDescriptor{
  95. {ID: byte(0x02), Priority: 10},
  96. {ID: byte(0x03), Priority: 10},
  97. }, true))
  98. return sw
  99. }
  100. func TestSwitches(t *testing.T) {
  101. s1, s2 := MakeSwitchPair(t, initSwitchFunc)
  102. t.Cleanup(func() {
  103. if err := s1.Stop(); err != nil {
  104. t.Error(err)
  105. }
  106. })
  107. t.Cleanup(func() {
  108. if err := s2.Stop(); err != nil {
  109. t.Error(err)
  110. }
  111. })
  112. if s1.Peers().Size() != 1 {
  113. t.Errorf("expected exactly 1 peer in s1, got %v", s1.Peers().Size())
  114. }
  115. if s2.Peers().Size() != 1 {
  116. t.Errorf("expected exactly 1 peer in s2, got %v", s2.Peers().Size())
  117. }
  118. // Lets send some messages
  119. ch0Msg := []byte("channel zero")
  120. ch1Msg := []byte("channel foo")
  121. ch2Msg := []byte("channel bar")
  122. s1.Broadcast(byte(0x00), ch0Msg)
  123. s1.Broadcast(byte(0x01), ch1Msg)
  124. s1.Broadcast(byte(0x02), ch2Msg)
  125. assertMsgReceivedWithTimeout(t,
  126. ch0Msg,
  127. byte(0x00),
  128. s2.Reactor("foo").(*TestReactor), 10*time.Millisecond, 5*time.Second)
  129. assertMsgReceivedWithTimeout(t,
  130. ch1Msg,
  131. byte(0x01),
  132. s2.Reactor("foo").(*TestReactor), 10*time.Millisecond, 5*time.Second)
  133. assertMsgReceivedWithTimeout(t,
  134. ch2Msg,
  135. byte(0x02),
  136. s2.Reactor("bar").(*TestReactor), 10*time.Millisecond, 5*time.Second)
  137. }
  138. func assertMsgReceivedWithTimeout(
  139. t *testing.T,
  140. msgBytes []byte,
  141. channel byte,
  142. reactor *TestReactor,
  143. checkPeriod,
  144. timeout time.Duration,
  145. ) {
  146. ticker := time.NewTicker(checkPeriod)
  147. for {
  148. select {
  149. case <-ticker.C:
  150. msgs := reactor.getMsgs(channel)
  151. if len(msgs) > 0 {
  152. if !bytes.Equal(msgs[0].Bytes, msgBytes) {
  153. t.Fatalf("Unexpected message bytes. Wanted: %X, Got: %X", msgBytes, msgs[0].Bytes)
  154. }
  155. return
  156. }
  157. case <-time.After(timeout):
  158. t.Fatalf("Expected to have received 1 message in channel #%v, got zero", channel)
  159. }
  160. }
  161. }
  162. func TestSwitchFiltersOutItself(t *testing.T) {
  163. s1 := MakeSwitch(cfg, 1, "127.0.0.1", "123.123.123", initSwitchFunc, log.TestingLogger())
  164. // simulate s1 having a public IP by creating a remote peer with the same ID
  165. rp := &remotePeer{PrivKey: s1.nodeKey.PrivKey, Config: cfg}
  166. rp.Start()
  167. // addr should be rejected in addPeer based on the same ID
  168. err := s1.DialPeerWithAddress(rp.Addr())
  169. if assert.Error(t, err) {
  170. if err, ok := err.(ErrRejected); ok {
  171. if !err.IsSelf() {
  172. t.Errorf("expected self to be rejected")
  173. }
  174. } else {
  175. t.Errorf("expected ErrRejected")
  176. }
  177. }
  178. assert.True(t, s1.addrBook.OurAddress(rp.Addr()))
  179. assert.False(t, s1.addrBook.HasAddress(rp.Addr()))
  180. rp.Stop()
  181. assertNoPeersAfterTimeout(t, s1, 100*time.Millisecond)
  182. }
  183. func TestSwitchDialFailsOnIncompatiblePeer(t *testing.T) {
  184. s1 := MakeSwitch(cfg, 1, "127.0.0.1", "123.123.123", initSwitchFunc, log.TestingLogger())
  185. ni := s1.NodeInfo()
  186. ni.Network = "network-a"
  187. s1.SetNodeInfo(ni)
  188. rp := &remotePeer{PrivKey: ed25519.GenPrivKey(), Config: cfg, Network: "network-b"}
  189. rp.Start()
  190. defer rp.Stop()
  191. err := s1.DialPeerWithAddress(rp.Addr())
  192. require.Error(t, err)
  193. errRejected, ok := err.(ErrRejected)
  194. require.True(t, ok, "expected error to be of type IsRejected")
  195. require.True(t, errRejected.IsIncompatible(), "expected error to be IsIncompatible")
  196. // remote peer should not have been added to the addressbook
  197. require.False(t, s1.addrBook.HasAddress(rp.Addr()))
  198. }
  199. func TestSwitchPeerFilter(t *testing.T) {
  200. var (
  201. filters = []PeerFilterFunc{
  202. func(_ IPeerSet, _ Peer) error { return nil },
  203. func(_ IPeerSet, _ Peer) error { return fmt.Errorf("denied") },
  204. func(_ IPeerSet, _ Peer) error { return nil },
  205. }
  206. sw = MakeSwitch(
  207. cfg,
  208. 1,
  209. "testing",
  210. "123.123.123",
  211. initSwitchFunc,
  212. log.TestingLogger(),
  213. SwitchPeerFilters(filters...),
  214. )
  215. )
  216. err := sw.Start()
  217. require.NoError(t, err)
  218. t.Cleanup(func() {
  219. if err := sw.Stop(); err != nil {
  220. t.Error(err)
  221. }
  222. })
  223. // simulate remote peer
  224. rp := &remotePeer{PrivKey: ed25519.GenPrivKey(), Config: cfg}
  225. rp.Start()
  226. t.Cleanup(rp.Stop)
  227. c, err := sw.transport.Dial(ctx, NewEndpoint(rp.Addr()))
  228. if err != nil {
  229. t.Fatal(err)
  230. }
  231. peerInfo, _, err := c.Handshake(ctx, sw.nodeInfo, sw.nodeKey.PrivKey)
  232. if err != nil {
  233. t.Fatal(err)
  234. }
  235. p := newPeer(
  236. peerInfo,
  237. newPeerConn(true, false, c),
  238. sw.reactorsByCh,
  239. sw.StopPeerForError,
  240. )
  241. err = sw.addPeer(p)
  242. if err, ok := err.(ErrRejected); ok {
  243. if !err.IsFiltered() {
  244. t.Errorf("expected peer to be filtered")
  245. }
  246. } else {
  247. t.Errorf("expected ErrRejected")
  248. }
  249. }
  250. func TestSwitchPeerFilterTimeout(t *testing.T) {
  251. var (
  252. filters = []PeerFilterFunc{
  253. func(_ IPeerSet, _ Peer) error {
  254. time.Sleep(10 * time.Millisecond)
  255. return nil
  256. },
  257. }
  258. sw = MakeSwitch(
  259. cfg,
  260. 1,
  261. "testing",
  262. "123.123.123",
  263. initSwitchFunc,
  264. log.TestingLogger(),
  265. SwitchFilterTimeout(5*time.Millisecond),
  266. SwitchPeerFilters(filters...),
  267. )
  268. )
  269. err := sw.Start()
  270. require.NoError(t, err)
  271. t.Cleanup(func() {
  272. if err := sw.Stop(); err != nil {
  273. t.Log(err)
  274. }
  275. })
  276. // simulate remote peer
  277. rp := &remotePeer{PrivKey: ed25519.GenPrivKey(), Config: cfg}
  278. rp.Start()
  279. defer rp.Stop()
  280. c, err := sw.transport.Dial(ctx, NewEndpoint(rp.Addr()))
  281. if err != nil {
  282. t.Fatal(err)
  283. }
  284. peerInfo, _, err := c.Handshake(ctx, sw.nodeInfo, sw.nodeKey.PrivKey)
  285. if err != nil {
  286. t.Fatal(err)
  287. }
  288. p := newPeer(
  289. peerInfo,
  290. newPeerConn(true, false, c),
  291. sw.reactorsByCh,
  292. sw.StopPeerForError,
  293. )
  294. err = sw.addPeer(p)
  295. if _, ok := err.(ErrFilterTimeout); !ok {
  296. t.Errorf("expected ErrFilterTimeout")
  297. }
  298. }
  299. func TestSwitchPeerFilterDuplicate(t *testing.T) {
  300. sw := MakeSwitch(cfg, 1, "testing", "123.123.123", initSwitchFunc, log.TestingLogger())
  301. err := sw.Start()
  302. require.NoError(t, err)
  303. t.Cleanup(func() {
  304. if err := sw.Stop(); err != nil {
  305. t.Error(err)
  306. }
  307. })
  308. // simulate remote peer
  309. rp := &remotePeer{PrivKey: ed25519.GenPrivKey(), Config: cfg}
  310. rp.Start()
  311. defer rp.Stop()
  312. c, err := sw.transport.Dial(ctx, NewEndpoint(rp.Addr()))
  313. if err != nil {
  314. t.Fatal(err)
  315. }
  316. peerInfo, _, err := c.Handshake(ctx, sw.nodeInfo, sw.nodeKey.PrivKey)
  317. if err != nil {
  318. t.Fatal(err)
  319. }
  320. p := newPeer(
  321. peerInfo,
  322. newPeerConn(true, false, c),
  323. sw.reactorsByCh,
  324. sw.StopPeerForError,
  325. )
  326. if err := sw.addPeer(p); err != nil {
  327. t.Fatal(err)
  328. }
  329. err = sw.addPeer(p)
  330. if errRej, ok := err.(ErrRejected); ok {
  331. if !errRej.IsDuplicate() {
  332. t.Errorf("expected peer to be duplicate. got %v", errRej)
  333. }
  334. } else {
  335. t.Errorf("expected ErrRejected, got %v", err)
  336. }
  337. }
  338. func assertNoPeersAfterTimeout(t *testing.T, sw *Switch, timeout time.Duration) {
  339. time.Sleep(timeout)
  340. if sw.Peers().Size() != 0 {
  341. t.Fatalf("Expected %v to not connect to some peers, got %d", sw, sw.Peers().Size())
  342. }
  343. }
  344. func TestSwitchStopsNonPersistentPeerOnError(t *testing.T) {
  345. assert, require := assert.New(t), require.New(t)
  346. sw := MakeSwitch(cfg, 1, "testing", "123.123.123", initSwitchFunc, log.TestingLogger())
  347. err := sw.Start()
  348. if err != nil {
  349. t.Error(err)
  350. }
  351. t.Cleanup(func() {
  352. if err := sw.Stop(); err != nil {
  353. t.Error(err)
  354. }
  355. })
  356. // simulate remote peer
  357. rp := &remotePeer{PrivKey: ed25519.GenPrivKey(), Config: cfg}
  358. rp.Start()
  359. defer rp.Stop()
  360. c, err := sw.transport.Dial(ctx, NewEndpoint(rp.Addr()))
  361. if err != nil {
  362. t.Fatal(err)
  363. }
  364. peerInfo, _, err := c.Handshake(ctx, sw.nodeInfo, sw.nodeKey.PrivKey)
  365. if err != nil {
  366. t.Fatal(err)
  367. }
  368. p := newPeer(
  369. peerInfo,
  370. newPeerConn(true, false, c),
  371. sw.reactorsByCh,
  372. sw.StopPeerForError,
  373. )
  374. err = sw.addPeer(p)
  375. require.Nil(err)
  376. require.NotNil(sw.Peers().Get(rp.ID()))
  377. // simulate failure by closing connection
  378. err = p.CloseConn()
  379. require.NoError(err)
  380. assertNoPeersAfterTimeout(t, sw, 100*time.Millisecond)
  381. assert.False(p.IsRunning())
  382. }
  383. func TestSwitchStopPeerForError(t *testing.T) {
  384. s := httptest.NewServer(promhttp.Handler())
  385. defer s.Close()
  386. scrapeMetrics := func() string {
  387. resp, err := http.Get(s.URL)
  388. require.NoError(t, err)
  389. defer resp.Body.Close()
  390. buf, _ := ioutil.ReadAll(resp.Body)
  391. return string(buf)
  392. }
  393. namespace, subsystem, name := config.TestInstrumentationConfig().Namespace, MetricsSubsystem, "peers"
  394. re := regexp.MustCompile(namespace + `_` + subsystem + `_` + name + ` ([0-9\.]+)`)
  395. peersMetricValue := func() float64 {
  396. matches := re.FindStringSubmatch(scrapeMetrics())
  397. f, _ := strconv.ParseFloat(matches[1], 64)
  398. return f
  399. }
  400. p2pMetrics := PrometheusMetrics(namespace)
  401. // make two connected switches
  402. sw1, sw2 := MakeSwitchPair(t, func(i int, sw *Switch) *Switch {
  403. // set metrics on sw1
  404. if i == 0 {
  405. opt := WithMetrics(p2pMetrics)
  406. opt(sw)
  407. }
  408. return initSwitchFunc(i, sw)
  409. })
  410. assert.Equal(t, len(sw1.Peers().List()), 1)
  411. assert.EqualValues(t, 1, peersMetricValue())
  412. // send messages to the peer from sw1
  413. p := sw1.Peers().List()[0]
  414. p.Send(0x1, []byte("here's a message to send"))
  415. // stop sw2. this should cause the p to fail,
  416. // which results in calling StopPeerForError internally
  417. t.Cleanup(func() {
  418. if err := sw2.Stop(); err != nil {
  419. t.Error(err)
  420. }
  421. })
  422. // now call StopPeerForError explicitly, eg. from a reactor
  423. sw1.StopPeerForError(p, fmt.Errorf("some err"))
  424. assert.Equal(t, len(sw1.Peers().List()), 0)
  425. assert.EqualValues(t, 0, peersMetricValue())
  426. }
  427. func TestSwitchReconnectsToOutboundPersistentPeer(t *testing.T) {
  428. sw := MakeSwitch(cfg, 1, "testing", "123.123.123", initSwitchFunc, log.TestingLogger())
  429. err := sw.Start()
  430. require.NoError(t, err)
  431. t.Cleanup(func() {
  432. if err := sw.Stop(); err != nil {
  433. t.Error(err)
  434. }
  435. })
  436. // 1. simulate failure by closing connection
  437. rp := &remotePeer{PrivKey: ed25519.GenPrivKey(), Config: cfg}
  438. rp.Start()
  439. defer rp.Stop()
  440. err = sw.AddPersistentPeers([]string{rp.Addr().String()})
  441. require.NoError(t, err)
  442. err = sw.DialPeerWithAddress(rp.Addr())
  443. require.Nil(t, err)
  444. require.NotNil(t, sw.Peers().Get(rp.ID()))
  445. p := sw.Peers().List()[0]
  446. err = p.(*peer).CloseConn()
  447. require.NoError(t, err)
  448. waitUntilSwitchHasAtLeastNPeers(sw, 1)
  449. assert.False(t, p.IsRunning()) // old peer instance
  450. assert.Equal(t, 1, sw.Peers().Size()) // new peer instance
  451. // 2. simulate first time dial failure
  452. rp = &remotePeer{
  453. PrivKey: ed25519.GenPrivKey(),
  454. Config: cfg,
  455. // Use different interface to prevent duplicate IP filter, this will break
  456. // beyond two peers.
  457. listenAddr: "127.0.0.1:0",
  458. }
  459. rp.Start()
  460. defer rp.Stop()
  461. conf := config.DefaultP2PConfig()
  462. conf.TestDialFail = true // will trigger a reconnect
  463. err = sw.addOutboundPeerWithConfig(rp.Addr(), conf)
  464. require.NotNil(t, err)
  465. // DialPeerWithAddres - sw.peerConfig resets the dialer
  466. waitUntilSwitchHasAtLeastNPeers(sw, 2)
  467. assert.Equal(t, 2, sw.Peers().Size())
  468. }
  469. func TestSwitchReconnectsToInboundPersistentPeer(t *testing.T) {
  470. sw := MakeSwitch(cfg, 1, "testing", "123.123.123", initSwitchFunc, log.TestingLogger())
  471. err := sw.Start()
  472. require.NoError(t, err)
  473. t.Cleanup(func() {
  474. if err := sw.Stop(); err != nil {
  475. t.Error(err)
  476. }
  477. })
  478. // 1. simulate failure by closing the connection
  479. rp := &remotePeer{PrivKey: ed25519.GenPrivKey(), Config: cfg}
  480. rp.Start()
  481. defer rp.Stop()
  482. err = sw.AddPersistentPeers([]string{rp.Addr().String()})
  483. require.NoError(t, err)
  484. conn, err := rp.Dial(sw.NetAddress())
  485. require.NoError(t, err)
  486. time.Sleep(50 * time.Millisecond)
  487. require.NotNil(t, sw.Peers().Get(rp.ID()))
  488. conn.Close()
  489. waitUntilSwitchHasAtLeastNPeers(sw, 1)
  490. assert.Equal(t, 1, sw.Peers().Size())
  491. }
  492. func TestSwitchDialPeersAsync(t *testing.T) {
  493. if testing.Short() {
  494. return
  495. }
  496. sw := MakeSwitch(cfg, 1, "testing", "123.123.123", initSwitchFunc, log.TestingLogger())
  497. err := sw.Start()
  498. require.NoError(t, err)
  499. t.Cleanup(func() {
  500. if err := sw.Stop(); err != nil {
  501. t.Error(err)
  502. }
  503. })
  504. rp := &remotePeer{PrivKey: ed25519.GenPrivKey(), Config: cfg}
  505. rp.Start()
  506. defer rp.Stop()
  507. err = sw.DialPeersAsync([]string{rp.Addr().String()})
  508. require.NoError(t, err)
  509. time.Sleep(dialRandomizerIntervalMilliseconds * time.Millisecond)
  510. require.NotNil(t, sw.Peers().Get(rp.ID()))
  511. }
  512. func waitUntilSwitchHasAtLeastNPeers(sw *Switch, n int) {
  513. for i := 0; i < 20; i++ {
  514. time.Sleep(250 * time.Millisecond)
  515. has := sw.Peers().Size()
  516. if has >= n {
  517. break
  518. }
  519. }
  520. }
  521. func TestSwitchFullConnectivity(t *testing.T) {
  522. switches := MakeConnectedSwitches(cfg, 3, initSwitchFunc, Connect2Switches)
  523. defer func() {
  524. for _, sw := range switches {
  525. sw := sw
  526. t.Cleanup(func() {
  527. if err := sw.Stop(); err != nil {
  528. t.Error(err)
  529. }
  530. })
  531. }
  532. }()
  533. for i, sw := range switches {
  534. if sw.Peers().Size() != 2 {
  535. t.Fatalf("Expected each switch to be connected to 2 other, but %d switch only connected to %d", sw.Peers().Size(), i)
  536. }
  537. }
  538. }
  539. func TestSwitchAcceptRoutine(t *testing.T) {
  540. cfg.MaxNumInboundPeers = 5
  541. // Create some unconditional peers.
  542. const unconditionalPeersNum = 2
  543. var (
  544. unconditionalPeers = make([]*remotePeer, unconditionalPeersNum)
  545. unconditionalPeerIDs = make([]string, unconditionalPeersNum)
  546. )
  547. for i := 0; i < unconditionalPeersNum; i++ {
  548. peer := &remotePeer{PrivKey: ed25519.GenPrivKey(), Config: cfg}
  549. peer.Start()
  550. unconditionalPeers[i] = peer
  551. unconditionalPeerIDs[i] = string(peer.ID())
  552. }
  553. // make switch
  554. sw := MakeSwitch(cfg, 1, "testing", "123.123.123", initSwitchFunc, log.TestingLogger())
  555. err := sw.AddUnconditionalPeerIDs(unconditionalPeerIDs)
  556. require.NoError(t, err)
  557. err = sw.Start()
  558. require.NoError(t, err)
  559. t.Cleanup(func() {
  560. err := sw.Stop()
  561. require.NoError(t, err)
  562. })
  563. // 0. check there are no peers
  564. assert.Equal(t, 0, sw.Peers().Size())
  565. // 1. check we connect up to MaxNumInboundPeers
  566. peers := make([]*remotePeer, 0)
  567. for i := 0; i < cfg.MaxNumInboundPeers; i++ {
  568. peer := &remotePeer{PrivKey: ed25519.GenPrivKey(), Config: cfg}
  569. peers = append(peers, peer)
  570. peer.Start()
  571. c, err := peer.Dial(sw.NetAddress())
  572. require.NoError(t, err)
  573. // spawn a reading routine to prevent connection from closing
  574. go func(c net.Conn) {
  575. for {
  576. one := make([]byte, 1)
  577. _, err := c.Read(one)
  578. if err != nil {
  579. return
  580. }
  581. }
  582. }(c)
  583. }
  584. time.Sleep(100 * time.Millisecond)
  585. assert.Equal(t, cfg.MaxNumInboundPeers, sw.Peers().Size())
  586. // 2. check we close new connections if we already have MaxNumInboundPeers peers
  587. peer := &remotePeer{PrivKey: ed25519.GenPrivKey(), Config: cfg}
  588. peer.Start()
  589. conn, err := peer.Dial(sw.NetAddress())
  590. require.NoError(t, err)
  591. // check conn is closed
  592. one := make([]byte, 1)
  593. _ = conn.SetReadDeadline(time.Now().Add(10 * time.Millisecond))
  594. _, err = conn.Read(one)
  595. assert.Error(t, err)
  596. assert.Equal(t, cfg.MaxNumInboundPeers, sw.Peers().Size())
  597. peer.Stop()
  598. // 3. check we connect to unconditional peers despite the limit.
  599. for _, peer := range unconditionalPeers {
  600. c, err := peer.Dial(sw.NetAddress())
  601. require.NoError(t, err)
  602. // spawn a reading routine to prevent connection from closing
  603. go func(c net.Conn) {
  604. for {
  605. one := make([]byte, 1)
  606. _, err := c.Read(one)
  607. if err != nil {
  608. return
  609. }
  610. }
  611. }(c)
  612. }
  613. time.Sleep(10 * time.Millisecond)
  614. assert.Equal(t, cfg.MaxNumInboundPeers+unconditionalPeersNum, sw.Peers().Size())
  615. for _, peer := range peers {
  616. peer.Stop()
  617. }
  618. for _, peer := range unconditionalPeers {
  619. peer.Stop()
  620. }
  621. }
  622. func TestSwitchRejectsIncompatiblePeers(t *testing.T) {
  623. sw := MakeSwitch(cfg, 1, "127.0.0.1", "123.123.123", initSwitchFunc, log.TestingLogger())
  624. ni := sw.NodeInfo()
  625. ni.Network = "network-a"
  626. sw.SetNodeInfo(ni)
  627. err := sw.Start()
  628. require.NoError(t, err)
  629. t.Cleanup(func() {
  630. err := sw.Stop()
  631. require.NoError(t, err)
  632. })
  633. rp := &remotePeer{PrivKey: ed25519.GenPrivKey(), Config: cfg, Network: "network-b"}
  634. rp.Start()
  635. defer rp.Stop()
  636. assert.Equal(t, 0, sw.Peers().Size())
  637. conn, err := rp.Dial(sw.NetAddress())
  638. assert.Nil(t, err)
  639. one := make([]byte, 1)
  640. _ = conn.SetReadDeadline(time.Now().Add(10 * time.Millisecond))
  641. _, err = conn.Read(one)
  642. assert.Error(t, err)
  643. assert.Equal(t, 0, sw.Peers().Size())
  644. }
  645. type errorTransport struct {
  646. acceptErr error
  647. }
  648. func (et errorTransport) String() string {
  649. return "error"
  650. }
  651. func (et errorTransport) Protocols() []Protocol {
  652. return []Protocol{"error"}
  653. }
  654. func (et errorTransport) Accept() (Connection, error) {
  655. return nil, et.acceptErr
  656. }
  657. func (errorTransport) Dial(context.Context, Endpoint) (Connection, error) {
  658. panic("not implemented")
  659. }
  660. func (errorTransport) Close() error { panic("not implemented") }
  661. func (errorTransport) FlushClose() error { panic("not implemented") }
  662. func (errorTransport) Endpoints() []Endpoint { panic("not implemented") }
  663. func TestSwitchAcceptRoutineErrorCases(t *testing.T) {
  664. sw := NewSwitch(cfg, errorTransport{ErrFilterTimeout{}})
  665. assert.NotPanics(t, func() {
  666. err := sw.Start()
  667. require.NoError(t, err)
  668. err = sw.Stop()
  669. require.NoError(t, err)
  670. })
  671. sw = NewSwitch(cfg, errorTransport{ErrRejected{conn: nil, err: errors.New("filtered"), isFiltered: true}})
  672. assert.NotPanics(t, func() {
  673. err := sw.Start()
  674. require.NoError(t, err)
  675. err = sw.Stop()
  676. require.NoError(t, err)
  677. })
  678. // TODO(melekes) check we remove our address from addrBook
  679. sw = NewSwitch(cfg, errorTransport{ErrTransportClosed{}})
  680. assert.NotPanics(t, func() {
  681. err := sw.Start()
  682. require.NoError(t, err)
  683. err = sw.Stop()
  684. require.NoError(t, err)
  685. })
  686. }
  687. // mockReactor checks that InitPeer never called before RemovePeer. If that's
  688. // not true, InitCalledBeforeRemoveFinished will return true.
  689. type mockReactor struct {
  690. *BaseReactor
  691. // atomic
  692. removePeerInProgress uint32
  693. initCalledBeforeRemoveFinished uint32
  694. }
  695. func (r *mockReactor) GetChannels() []*ChannelDescriptor {
  696. return []*ChannelDescriptor{{ID: testCh, Priority: 10}}
  697. }
  698. func (r *mockReactor) RemovePeer(peer Peer, reason interface{}) {
  699. atomic.StoreUint32(&r.removePeerInProgress, 1)
  700. defer atomic.StoreUint32(&r.removePeerInProgress, 0)
  701. time.Sleep(100 * time.Millisecond)
  702. }
  703. func (r *mockReactor) InitPeer(peer Peer) Peer {
  704. if atomic.LoadUint32(&r.removePeerInProgress) == 1 {
  705. atomic.StoreUint32(&r.initCalledBeforeRemoveFinished, 1)
  706. }
  707. return peer
  708. }
  709. func (r *mockReactor) InitCalledBeforeRemoveFinished() bool {
  710. return atomic.LoadUint32(&r.initCalledBeforeRemoveFinished) == 1
  711. }
  712. // see stopAndRemovePeer
  713. func TestSwitchInitPeerIsNotCalledBeforeRemovePeer(t *testing.T) {
  714. // make reactor
  715. reactor := &mockReactor{}
  716. reactor.BaseReactor = NewBaseReactor("mockReactor", reactor)
  717. // make switch
  718. sw := MakeSwitch(cfg, 1, "testing", "123.123.123", func(i int, sw *Switch) *Switch {
  719. sw.AddReactor("mock", reactor)
  720. return sw
  721. }, log.TestingLogger())
  722. err := sw.Start()
  723. require.NoError(t, err)
  724. t.Cleanup(func() {
  725. if err := sw.Stop(); err != nil {
  726. t.Error(err)
  727. }
  728. })
  729. // add peer
  730. rp := &remotePeer{PrivKey: ed25519.GenPrivKey(), Config: cfg}
  731. rp.Start()
  732. defer rp.Stop()
  733. _, err = rp.Dial(sw.NetAddress())
  734. require.NoError(t, err)
  735. // wait till the switch adds rp to the peer set, then stop the peer asynchronously
  736. for {
  737. time.Sleep(20 * time.Millisecond)
  738. if peer := sw.Peers().Get(rp.ID()); peer != nil {
  739. go sw.StopPeerForError(peer, "test")
  740. break
  741. }
  742. }
  743. // simulate peer reconnecting to us
  744. _, err = rp.Dial(sw.NetAddress())
  745. require.NoError(t, err)
  746. // wait till the switch adds rp to the peer set
  747. time.Sleep(50 * time.Millisecond)
  748. // make sure reactor.RemovePeer is finished before InitPeer is called
  749. assert.False(t, reactor.InitCalledBeforeRemoveFinished())
  750. }
  751. func BenchmarkSwitchBroadcast(b *testing.B) {
  752. s1, s2 := MakeSwitchPair(b, func(i int, sw *Switch) *Switch {
  753. // Make bar reactors of bar channels each
  754. sw.AddReactor("foo", NewTestReactor([]*conn.ChannelDescriptor{
  755. {ID: byte(0x00), Priority: 10},
  756. {ID: byte(0x01), Priority: 10},
  757. }, false))
  758. sw.AddReactor("bar", NewTestReactor([]*conn.ChannelDescriptor{
  759. {ID: byte(0x02), Priority: 10},
  760. {ID: byte(0x03), Priority: 10},
  761. }, false))
  762. return sw
  763. })
  764. b.Cleanup(func() {
  765. if err := s1.Stop(); err != nil {
  766. b.Error(err)
  767. }
  768. })
  769. b.Cleanup(func() {
  770. if err := s2.Stop(); err != nil {
  771. b.Error(err)
  772. }
  773. })
  774. // Allow time for goroutines to boot up
  775. time.Sleep(1 * time.Second)
  776. b.ResetTimer()
  777. numSuccess, numFailure := 0, 0
  778. // Send random message from foo channel to another
  779. for i := 0; i < b.N; i++ {
  780. chID := byte(i % 4)
  781. successChan := s1.Broadcast(chID, []byte("test data"))
  782. for s := range successChan {
  783. if s {
  784. numSuccess++
  785. } else {
  786. numFailure++
  787. }
  788. }
  789. }
  790. b.Logf("success: %v, failure: %v", numSuccess, numFailure)
  791. }
  792. func TestNewNetAddressStrings(t *testing.T) {
  793. addrs, errs := NewNetAddressStrings([]string{
  794. "127.0.0.1:8080",
  795. "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef@127.0.0.1:8080",
  796. "deadbeefdeadbeefdeadbeefdeadbeefdeadbeed@127.0.0.2:8080"})
  797. assert.Len(t, errs, 1)
  798. assert.Equal(t, 2, len(addrs))
  799. }