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.

615 lines
11 KiB

p2p: Implement PeerTransport This is the implementation for the design described in ADR 12[0]. It's the first step of a larger refactor of the p2p package as tracked in interface bundling all concerns of low-level connection handling and isolating the rest of peer lifecycle management from the specifics of the low-level internet protocols. Even if the swappable implementation will never be utilised, already the isolation of conn related code in one place will help with the reasoning about execution path and addressation of security sensitive issues surfaced through bounty programs and audits. We deliberately decided to not have Peer filtering and other management in the Transport, its sole responsibility is the translation of connections to Peers, handing those to the caller fully setup. It's the responsibility of the caller to reject those and or keep track. Peer filtering will take place in the Switch and can be inspected in a the following commit. This changeset additionally is an exercise in clean separation of logic and other infrastructural concerns like logging and instrumentation. By leveraging a clean and minimal interface. How this looks can be seen in a follow-up change. Design #2069[2] Refs #2067[3] Fixes #2047[4] Fixes #2046[5] changes: * describe Transport interface * implement new default Transport: MultiplexTransport * test MultiplexTransport with new constraints * implement ConnSet for concurrent management of net.Conn, synchronous to PeerSet * implement and expose duplicate IP filter * implemnt TransportOption for optional parametirisation [0] https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-012-peer-transport.md [1] https://github.com/tendermint/tendermint/issues/2067 [2] https://github.com/tendermint/tendermint/pull/2069 [3] https://github.com/tendermint/tendermint/issues/2067 [4] https://github.com/tendermint/tendermint/issues/2047 [5] https://github.com/tendermint/tendermint/issues/2046
6 years ago
p2p: Implement PeerTransport This is the implementation for the design described in ADR 12[0]. It's the first step of a larger refactor of the p2p package as tracked in interface bundling all concerns of low-level connection handling and isolating the rest of peer lifecycle management from the specifics of the low-level internet protocols. Even if the swappable implementation will never be utilised, already the isolation of conn related code in one place will help with the reasoning about execution path and addressation of security sensitive issues surfaced through bounty programs and audits. We deliberately decided to not have Peer filtering and other management in the Transport, its sole responsibility is the translation of connections to Peers, handing those to the caller fully setup. It's the responsibility of the caller to reject those and or keep track. Peer filtering will take place in the Switch and can be inspected in a the following commit. This changeset additionally is an exercise in clean separation of logic and other infrastructural concerns like logging and instrumentation. By leveraging a clean and minimal interface. How this looks can be seen in a follow-up change. Design #2069[2] Refs #2067[3] Fixes #2047[4] Fixes #2046[5] changes: * describe Transport interface * implement new default Transport: MultiplexTransport * test MultiplexTransport with new constraints * implement ConnSet for concurrent management of net.Conn, synchronous to PeerSet * implement and expose duplicate IP filter * implemnt TransportOption for optional parametirisation [0] https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-012-peer-transport.md [1] https://github.com/tendermint/tendermint/issues/2067 [2] https://github.com/tendermint/tendermint/pull/2069 [3] https://github.com/tendermint/tendermint/issues/2067 [4] https://github.com/tendermint/tendermint/issues/2047 [5] https://github.com/tendermint/tendermint/issues/2046
6 years ago
p2p: Implement PeerTransport This is the implementation for the design described in ADR 12[0]. It's the first step of a larger refactor of the p2p package as tracked in interface bundling all concerns of low-level connection handling and isolating the rest of peer lifecycle management from the specifics of the low-level internet protocols. Even if the swappable implementation will never be utilised, already the isolation of conn related code in one place will help with the reasoning about execution path and addressation of security sensitive issues surfaced through bounty programs and audits. We deliberately decided to not have Peer filtering and other management in the Transport, its sole responsibility is the translation of connections to Peers, handing those to the caller fully setup. It's the responsibility of the caller to reject those and or keep track. Peer filtering will take place in the Switch and can be inspected in a the following commit. This changeset additionally is an exercise in clean separation of logic and other infrastructural concerns like logging and instrumentation. By leveraging a clean and minimal interface. How this looks can be seen in a follow-up change. Design #2069[2] Refs #2067[3] Fixes #2047[4] Fixes #2046[5] changes: * describe Transport interface * implement new default Transport: MultiplexTransport * test MultiplexTransport with new constraints * implement ConnSet for concurrent management of net.Conn, synchronous to PeerSet * implement and expose duplicate IP filter * implemnt TransportOption for optional parametirisation [0] https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-012-peer-transport.md [1] https://github.com/tendermint/tendermint/issues/2067 [2] https://github.com/tendermint/tendermint/pull/2069 [3] https://github.com/tendermint/tendermint/issues/2067 [4] https://github.com/tendermint/tendermint/issues/2047 [5] https://github.com/tendermint/tendermint/issues/2046
6 years ago
p2p: Implement PeerTransport This is the implementation for the design described in ADR 12[0]. It's the first step of a larger refactor of the p2p package as tracked in interface bundling all concerns of low-level connection handling and isolating the rest of peer lifecycle management from the specifics of the low-level internet protocols. Even if the swappable implementation will never be utilised, already the isolation of conn related code in one place will help with the reasoning about execution path and addressation of security sensitive issues surfaced through bounty programs and audits. We deliberately decided to not have Peer filtering and other management in the Transport, its sole responsibility is the translation of connections to Peers, handing those to the caller fully setup. It's the responsibility of the caller to reject those and or keep track. Peer filtering will take place in the Switch and can be inspected in a the following commit. This changeset additionally is an exercise in clean separation of logic and other infrastructural concerns like logging and instrumentation. By leveraging a clean and minimal interface. How this looks can be seen in a follow-up change. Design #2069[2] Refs #2067[3] Fixes #2047[4] Fixes #2046[5] changes: * describe Transport interface * implement new default Transport: MultiplexTransport * test MultiplexTransport with new constraints * implement ConnSet for concurrent management of net.Conn, synchronous to PeerSet * implement and expose duplicate IP filter * implemnt TransportOption for optional parametirisation [0] https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-012-peer-transport.md [1] https://github.com/tendermint/tendermint/issues/2067 [2] https://github.com/tendermint/tendermint/pull/2069 [3] https://github.com/tendermint/tendermint/issues/2067 [4] https://github.com/tendermint/tendermint/issues/2047 [5] https://github.com/tendermint/tendermint/issues/2046
6 years ago
p2p: Implement PeerTransport This is the implementation for the design described in ADR 12[0]. It's the first step of a larger refactor of the p2p package as tracked in interface bundling all concerns of low-level connection handling and isolating the rest of peer lifecycle management from the specifics of the low-level internet protocols. Even if the swappable implementation will never be utilised, already the isolation of conn related code in one place will help with the reasoning about execution path and addressation of security sensitive issues surfaced through bounty programs and audits. We deliberately decided to not have Peer filtering and other management in the Transport, its sole responsibility is the translation of connections to Peers, handing those to the caller fully setup. It's the responsibility of the caller to reject those and or keep track. Peer filtering will take place in the Switch and can be inspected in a the following commit. This changeset additionally is an exercise in clean separation of logic and other infrastructural concerns like logging and instrumentation. By leveraging a clean and minimal interface. How this looks can be seen in a follow-up change. Design #2069[2] Refs #2067[3] Fixes #2047[4] Fixes #2046[5] changes: * describe Transport interface * implement new default Transport: MultiplexTransport * test MultiplexTransport with new constraints * implement ConnSet for concurrent management of net.Conn, synchronous to PeerSet * implement and expose duplicate IP filter * implemnt TransportOption for optional parametirisation [0] https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-012-peer-transport.md [1] https://github.com/tendermint/tendermint/issues/2067 [2] https://github.com/tendermint/tendermint/pull/2069 [3] https://github.com/tendermint/tendermint/issues/2067 [4] https://github.com/tendermint/tendermint/issues/2047 [5] https://github.com/tendermint/tendermint/issues/2046
6 years ago
p2p: Implement PeerTransport This is the implementation for the design described in ADR 12[0]. It's the first step of a larger refactor of the p2p package as tracked in interface bundling all concerns of low-level connection handling and isolating the rest of peer lifecycle management from the specifics of the low-level internet protocols. Even if the swappable implementation will never be utilised, already the isolation of conn related code in one place will help with the reasoning about execution path and addressation of security sensitive issues surfaced through bounty programs and audits. We deliberately decided to not have Peer filtering and other management in the Transport, its sole responsibility is the translation of connections to Peers, handing those to the caller fully setup. It's the responsibility of the caller to reject those and or keep track. Peer filtering will take place in the Switch and can be inspected in a the following commit. This changeset additionally is an exercise in clean separation of logic and other infrastructural concerns like logging and instrumentation. By leveraging a clean and minimal interface. How this looks can be seen in a follow-up change. Design #2069[2] Refs #2067[3] Fixes #2047[4] Fixes #2046[5] changes: * describe Transport interface * implement new default Transport: MultiplexTransport * test MultiplexTransport with new constraints * implement ConnSet for concurrent management of net.Conn, synchronous to PeerSet * implement and expose duplicate IP filter * implemnt TransportOption for optional parametirisation [0] https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-012-peer-transport.md [1] https://github.com/tendermint/tendermint/issues/2067 [2] https://github.com/tendermint/tendermint/pull/2069 [3] https://github.com/tendermint/tendermint/issues/2067 [4] https://github.com/tendermint/tendermint/issues/2047 [5] https://github.com/tendermint/tendermint/issues/2046
6 years ago
p2p: Implement PeerTransport This is the implementation for the design described in ADR 12[0]. It's the first step of a larger refactor of the p2p package as tracked in interface bundling all concerns of low-level connection handling and isolating the rest of peer lifecycle management from the specifics of the low-level internet protocols. Even if the swappable implementation will never be utilised, already the isolation of conn related code in one place will help with the reasoning about execution path and addressation of security sensitive issues surfaced through bounty programs and audits. We deliberately decided to not have Peer filtering and other management in the Transport, its sole responsibility is the translation of connections to Peers, handing those to the caller fully setup. It's the responsibility of the caller to reject those and or keep track. Peer filtering will take place in the Switch and can be inspected in a the following commit. This changeset additionally is an exercise in clean separation of logic and other infrastructural concerns like logging and instrumentation. By leveraging a clean and minimal interface. How this looks can be seen in a follow-up change. Design #2069[2] Refs #2067[3] Fixes #2047[4] Fixes #2046[5] changes: * describe Transport interface * implement new default Transport: MultiplexTransport * test MultiplexTransport with new constraints * implement ConnSet for concurrent management of net.Conn, synchronous to PeerSet * implement and expose duplicate IP filter * implemnt TransportOption for optional parametirisation [0] https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-012-peer-transport.md [1] https://github.com/tendermint/tendermint/issues/2067 [2] https://github.com/tendermint/tendermint/pull/2069 [3] https://github.com/tendermint/tendermint/issues/2067 [4] https://github.com/tendermint/tendermint/issues/2047 [5] https://github.com/tendermint/tendermint/issues/2046
6 years ago
p2p: Implement PeerTransport This is the implementation for the design described in ADR 12[0]. It's the first step of a larger refactor of the p2p package as tracked in interface bundling all concerns of low-level connection handling and isolating the rest of peer lifecycle management from the specifics of the low-level internet protocols. Even if the swappable implementation will never be utilised, already the isolation of conn related code in one place will help with the reasoning about execution path and addressation of security sensitive issues surfaced through bounty programs and audits. We deliberately decided to not have Peer filtering and other management in the Transport, its sole responsibility is the translation of connections to Peers, handing those to the caller fully setup. It's the responsibility of the caller to reject those and or keep track. Peer filtering will take place in the Switch and can be inspected in a the following commit. This changeset additionally is an exercise in clean separation of logic and other infrastructural concerns like logging and instrumentation. By leveraging a clean and minimal interface. How this looks can be seen in a follow-up change. Design #2069[2] Refs #2067[3] Fixes #2047[4] Fixes #2046[5] changes: * describe Transport interface * implement new default Transport: MultiplexTransport * test MultiplexTransport with new constraints * implement ConnSet for concurrent management of net.Conn, synchronous to PeerSet * implement and expose duplicate IP filter * implemnt TransportOption for optional parametirisation [0] https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-012-peer-transport.md [1] https://github.com/tendermint/tendermint/issues/2067 [2] https://github.com/tendermint/tendermint/pull/2069 [3] https://github.com/tendermint/tendermint/issues/2067 [4] https://github.com/tendermint/tendermint/issues/2047 [5] https://github.com/tendermint/tendermint/issues/2046
6 years ago
p2p: Implement PeerTransport This is the implementation for the design described in ADR 12[0]. It's the first step of a larger refactor of the p2p package as tracked in interface bundling all concerns of low-level connection handling and isolating the rest of peer lifecycle management from the specifics of the low-level internet protocols. Even if the swappable implementation will never be utilised, already the isolation of conn related code in one place will help with the reasoning about execution path and addressation of security sensitive issues surfaced through bounty programs and audits. We deliberately decided to not have Peer filtering and other management in the Transport, its sole responsibility is the translation of connections to Peers, handing those to the caller fully setup. It's the responsibility of the caller to reject those and or keep track. Peer filtering will take place in the Switch and can be inspected in a the following commit. This changeset additionally is an exercise in clean separation of logic and other infrastructural concerns like logging and instrumentation. By leveraging a clean and minimal interface. How this looks can be seen in a follow-up change. Design #2069[2] Refs #2067[3] Fixes #2047[4] Fixes #2046[5] changes: * describe Transport interface * implement new default Transport: MultiplexTransport * test MultiplexTransport with new constraints * implement ConnSet for concurrent management of net.Conn, synchronous to PeerSet * implement and expose duplicate IP filter * implemnt TransportOption for optional parametirisation [0] https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-012-peer-transport.md [1] https://github.com/tendermint/tendermint/issues/2067 [2] https://github.com/tendermint/tendermint/pull/2069 [3] https://github.com/tendermint/tendermint/issues/2067 [4] https://github.com/tendermint/tendermint/issues/2047 [5] https://github.com/tendermint/tendermint/issues/2046
6 years ago
p2p: Implement PeerTransport This is the implementation for the design described in ADR 12[0]. It's the first step of a larger refactor of the p2p package as tracked in interface bundling all concerns of low-level connection handling and isolating the rest of peer lifecycle management from the specifics of the low-level internet protocols. Even if the swappable implementation will never be utilised, already the isolation of conn related code in one place will help with the reasoning about execution path and addressation of security sensitive issues surfaced through bounty programs and audits. We deliberately decided to not have Peer filtering and other management in the Transport, its sole responsibility is the translation of connections to Peers, handing those to the caller fully setup. It's the responsibility of the caller to reject those and or keep track. Peer filtering will take place in the Switch and can be inspected in a the following commit. This changeset additionally is an exercise in clean separation of logic and other infrastructural concerns like logging and instrumentation. By leveraging a clean and minimal interface. How this looks can be seen in a follow-up change. Design #2069[2] Refs #2067[3] Fixes #2047[4] Fixes #2046[5] changes: * describe Transport interface * implement new default Transport: MultiplexTransport * test MultiplexTransport with new constraints * implement ConnSet for concurrent management of net.Conn, synchronous to PeerSet * implement and expose duplicate IP filter * implemnt TransportOption for optional parametirisation [0] https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-012-peer-transport.md [1] https://github.com/tendermint/tendermint/issues/2067 [2] https://github.com/tendermint/tendermint/pull/2069 [3] https://github.com/tendermint/tendermint/issues/2067 [4] https://github.com/tendermint/tendermint/issues/2047 [5] https://github.com/tendermint/tendermint/issues/2046
6 years ago
p2p: Implement PeerTransport This is the implementation for the design described in ADR 12[0]. It's the first step of a larger refactor of the p2p package as tracked in interface bundling all concerns of low-level connection handling and isolating the rest of peer lifecycle management from the specifics of the low-level internet protocols. Even if the swappable implementation will never be utilised, already the isolation of conn related code in one place will help with the reasoning about execution path and addressation of security sensitive issues surfaced through bounty programs and audits. We deliberately decided to not have Peer filtering and other management in the Transport, its sole responsibility is the translation of connections to Peers, handing those to the caller fully setup. It's the responsibility of the caller to reject those and or keep track. Peer filtering will take place in the Switch and can be inspected in a the following commit. This changeset additionally is an exercise in clean separation of logic and other infrastructural concerns like logging and instrumentation. By leveraging a clean and minimal interface. How this looks can be seen in a follow-up change. Design #2069[2] Refs #2067[3] Fixes #2047[4] Fixes #2046[5] changes: * describe Transport interface * implement new default Transport: MultiplexTransport * test MultiplexTransport with new constraints * implement ConnSet for concurrent management of net.Conn, synchronous to PeerSet * implement and expose duplicate IP filter * implemnt TransportOption for optional parametirisation [0] https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-012-peer-transport.md [1] https://github.com/tendermint/tendermint/issues/2067 [2] https://github.com/tendermint/tendermint/pull/2069 [3] https://github.com/tendermint/tendermint/issues/2067 [4] https://github.com/tendermint/tendermint/issues/2047 [5] https://github.com/tendermint/tendermint/issues/2046
6 years ago
p2p: Implement PeerTransport This is the implementation for the design described in ADR 12[0]. It's the first step of a larger refactor of the p2p package as tracked in interface bundling all concerns of low-level connection handling and isolating the rest of peer lifecycle management from the specifics of the low-level internet protocols. Even if the swappable implementation will never be utilised, already the isolation of conn related code in one place will help with the reasoning about execution path and addressation of security sensitive issues surfaced through bounty programs and audits. We deliberately decided to not have Peer filtering and other management in the Transport, its sole responsibility is the translation of connections to Peers, handing those to the caller fully setup. It's the responsibility of the caller to reject those and or keep track. Peer filtering will take place in the Switch and can be inspected in a the following commit. This changeset additionally is an exercise in clean separation of logic and other infrastructural concerns like logging and instrumentation. By leveraging a clean and minimal interface. How this looks can be seen in a follow-up change. Design #2069[2] Refs #2067[3] Fixes #2047[4] Fixes #2046[5] changes: * describe Transport interface * implement new default Transport: MultiplexTransport * test MultiplexTransport with new constraints * implement ConnSet for concurrent management of net.Conn, synchronous to PeerSet * implement and expose duplicate IP filter * implemnt TransportOption for optional parametirisation [0] https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-012-peer-transport.md [1] https://github.com/tendermint/tendermint/issues/2067 [2] https://github.com/tendermint/tendermint/pull/2069 [3] https://github.com/tendermint/tendermint/issues/2067 [4] https://github.com/tendermint/tendermint/issues/2047 [5] https://github.com/tendermint/tendermint/issues/2046
6 years ago
p2p: Implement PeerTransport This is the implementation for the design described in ADR 12[0]. It's the first step of a larger refactor of the p2p package as tracked in interface bundling all concerns of low-level connection handling and isolating the rest of peer lifecycle management from the specifics of the low-level internet protocols. Even if the swappable implementation will never be utilised, already the isolation of conn related code in one place will help with the reasoning about execution path and addressation of security sensitive issues surfaced through bounty programs and audits. We deliberately decided to not have Peer filtering and other management in the Transport, its sole responsibility is the translation of connections to Peers, handing those to the caller fully setup. It's the responsibility of the caller to reject those and or keep track. Peer filtering will take place in the Switch and can be inspected in a the following commit. This changeset additionally is an exercise in clean separation of logic and other infrastructural concerns like logging and instrumentation. By leveraging a clean and minimal interface. How this looks can be seen in a follow-up change. Design #2069[2] Refs #2067[3] Fixes #2047[4] Fixes #2046[5] changes: * describe Transport interface * implement new default Transport: MultiplexTransport * test MultiplexTransport with new constraints * implement ConnSet for concurrent management of net.Conn, synchronous to PeerSet * implement and expose duplicate IP filter * implemnt TransportOption for optional parametirisation [0] https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-012-peer-transport.md [1] https://github.com/tendermint/tendermint/issues/2067 [2] https://github.com/tendermint/tendermint/pull/2069 [3] https://github.com/tendermint/tendermint/issues/2067 [4] https://github.com/tendermint/tendermint/issues/2047 [5] https://github.com/tendermint/tendermint/issues/2046
6 years ago
p2p: Implement PeerTransport This is the implementation for the design described in ADR 12[0]. It's the first step of a larger refactor of the p2p package as tracked in interface bundling all concerns of low-level connection handling and isolating the rest of peer lifecycle management from the specifics of the low-level internet protocols. Even if the swappable implementation will never be utilised, already the isolation of conn related code in one place will help with the reasoning about execution path and addressation of security sensitive issues surfaced through bounty programs and audits. We deliberately decided to not have Peer filtering and other management in the Transport, its sole responsibility is the translation of connections to Peers, handing those to the caller fully setup. It's the responsibility of the caller to reject those and or keep track. Peer filtering will take place in the Switch and can be inspected in a the following commit. This changeset additionally is an exercise in clean separation of logic and other infrastructural concerns like logging and instrumentation. By leveraging a clean and minimal interface. How this looks can be seen in a follow-up change. Design #2069[2] Refs #2067[3] Fixes #2047[4] Fixes #2046[5] changes: * describe Transport interface * implement new default Transport: MultiplexTransport * test MultiplexTransport with new constraints * implement ConnSet for concurrent management of net.Conn, synchronous to PeerSet * implement and expose duplicate IP filter * implemnt TransportOption for optional parametirisation [0] https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-012-peer-transport.md [1] https://github.com/tendermint/tendermint/issues/2067 [2] https://github.com/tendermint/tendermint/pull/2069 [3] https://github.com/tendermint/tendermint/issues/2067 [4] https://github.com/tendermint/tendermint/issues/2047 [5] https://github.com/tendermint/tendermint/issues/2046
6 years ago
p2p: Implement PeerTransport This is the implementation for the design described in ADR 12[0]. It's the first step of a larger refactor of the p2p package as tracked in interface bundling all concerns of low-level connection handling and isolating the rest of peer lifecycle management from the specifics of the low-level internet protocols. Even if the swappable implementation will never be utilised, already the isolation of conn related code in one place will help with the reasoning about execution path and addressation of security sensitive issues surfaced through bounty programs and audits. We deliberately decided to not have Peer filtering and other management in the Transport, its sole responsibility is the translation of connections to Peers, handing those to the caller fully setup. It's the responsibility of the caller to reject those and or keep track. Peer filtering will take place in the Switch and can be inspected in a the following commit. This changeset additionally is an exercise in clean separation of logic and other infrastructural concerns like logging and instrumentation. By leveraging a clean and minimal interface. How this looks can be seen in a follow-up change. Design #2069[2] Refs #2067[3] Fixes #2047[4] Fixes #2046[5] changes: * describe Transport interface * implement new default Transport: MultiplexTransport * test MultiplexTransport with new constraints * implement ConnSet for concurrent management of net.Conn, synchronous to PeerSet * implement and expose duplicate IP filter * implemnt TransportOption for optional parametirisation [0] https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-012-peer-transport.md [1] https://github.com/tendermint/tendermint/issues/2067 [2] https://github.com/tendermint/tendermint/pull/2069 [3] https://github.com/tendermint/tendermint/issues/2067 [4] https://github.com/tendermint/tendermint/issues/2047 [5] https://github.com/tendermint/tendermint/issues/2046
6 years ago
p2p: Implement PeerTransport This is the implementation for the design described in ADR 12[0]. It's the first step of a larger refactor of the p2p package as tracked in interface bundling all concerns of low-level connection handling and isolating the rest of peer lifecycle management from the specifics of the low-level internet protocols. Even if the swappable implementation will never be utilised, already the isolation of conn related code in one place will help with the reasoning about execution path and addressation of security sensitive issues surfaced through bounty programs and audits. We deliberately decided to not have Peer filtering and other management in the Transport, its sole responsibility is the translation of connections to Peers, handing those to the caller fully setup. It's the responsibility of the caller to reject those and or keep track. Peer filtering will take place in the Switch and can be inspected in a the following commit. This changeset additionally is an exercise in clean separation of logic and other infrastructural concerns like logging and instrumentation. By leveraging a clean and minimal interface. How this looks can be seen in a follow-up change. Design #2069[2] Refs #2067[3] Fixes #2047[4] Fixes #2046[5] changes: * describe Transport interface * implement new default Transport: MultiplexTransport * test MultiplexTransport with new constraints * implement ConnSet for concurrent management of net.Conn, synchronous to PeerSet * implement and expose duplicate IP filter * implemnt TransportOption for optional parametirisation [0] https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-012-peer-transport.md [1] https://github.com/tendermint/tendermint/issues/2067 [2] https://github.com/tendermint/tendermint/pull/2069 [3] https://github.com/tendermint/tendermint/issues/2067 [4] https://github.com/tendermint/tendermint/issues/2047 [5] https://github.com/tendermint/tendermint/issues/2046
6 years ago
  1. package p2p
  2. import (
  3. "fmt"
  4. "math/rand"
  5. "net"
  6. "reflect"
  7. "testing"
  8. "time"
  9. "github.com/tendermint/tendermint/crypto/ed25519"
  10. )
  11. var defaultNodeName = "host_peer"
  12. func emptyNodeInfo() NodeInfo {
  13. return DefaultNodeInfo{}
  14. }
  15. func TestTransportMultiplexConnFilter(t *testing.T) {
  16. mt := NewMultiplexTransport(
  17. emptyNodeInfo(),
  18. NodeKey{
  19. PrivKey: ed25519.GenPrivKey(),
  20. },
  21. )
  22. MultiplexTransportConnFilters(
  23. func(_ ConnSet, _ net.Conn, _ []net.IP) error { return nil },
  24. func(_ ConnSet, _ net.Conn, _ []net.IP) error { return nil },
  25. func(_ ConnSet, _ net.Conn, _ []net.IP) error {
  26. return fmt.Errorf("rejected")
  27. },
  28. )(mt)
  29. addr, err := NewNetAddressStringWithOptionalID("127.0.0.1:0")
  30. if err != nil {
  31. t.Fatal(err)
  32. }
  33. if err := mt.Listen(*addr); err != nil {
  34. t.Fatal(err)
  35. }
  36. errc := make(chan error)
  37. go func() {
  38. addr, err := NewNetAddressStringWithOptionalID(mt.listener.Addr().String())
  39. if err != nil {
  40. errc <- err
  41. return
  42. }
  43. _, err = addr.Dial()
  44. if err != nil {
  45. errc <- err
  46. return
  47. }
  48. close(errc)
  49. }()
  50. if err := <-errc; err != nil {
  51. t.Errorf("connection failed: %v", err)
  52. }
  53. _, err = mt.Accept(peerConfig{})
  54. if err, ok := err.(ErrRejected); ok {
  55. if !err.IsFiltered() {
  56. t.Errorf("expected peer to be filtered")
  57. }
  58. } else {
  59. t.Errorf("expected ErrRejected")
  60. }
  61. }
  62. func TestTransportMultiplexConnFilterTimeout(t *testing.T) {
  63. mt := NewMultiplexTransport(
  64. emptyNodeInfo(),
  65. NodeKey{
  66. PrivKey: ed25519.GenPrivKey(),
  67. },
  68. )
  69. MultiplexTransportFilterTimeout(5 * time.Millisecond)(mt)
  70. MultiplexTransportConnFilters(
  71. func(_ ConnSet, _ net.Conn, _ []net.IP) error {
  72. time.Sleep(10 * time.Millisecond)
  73. return nil
  74. },
  75. )(mt)
  76. addr, err := NewNetAddressStringWithOptionalID("127.0.0.1:0")
  77. if err != nil {
  78. t.Fatal(err)
  79. }
  80. if err := mt.Listen(*addr); err != nil {
  81. t.Fatal(err)
  82. }
  83. errc := make(chan error)
  84. go func() {
  85. addr, err := NewNetAddressStringWithOptionalID(mt.listener.Addr().String())
  86. if err != nil {
  87. errc <- err
  88. return
  89. }
  90. _, err = addr.Dial()
  91. if err != nil {
  92. errc <- err
  93. return
  94. }
  95. close(errc)
  96. }()
  97. if err := <-errc; err != nil {
  98. t.Errorf("connection failed: %v", err)
  99. }
  100. _, err = mt.Accept(peerConfig{})
  101. if _, ok := err.(ErrFilterTimeout); !ok {
  102. t.Errorf("expected ErrFilterTimeout")
  103. }
  104. }
  105. func TestTransportMultiplexAcceptMultiple(t *testing.T) {
  106. mt := testSetupMultiplexTransport(t)
  107. var (
  108. seed = rand.New(rand.NewSource(time.Now().UnixNano()))
  109. errc = make(chan error, seed.Intn(64)+64)
  110. )
  111. // Setup dialers.
  112. for i := 0; i < cap(errc); i++ {
  113. go func() {
  114. var (
  115. pv = ed25519.GenPrivKey()
  116. dialer = NewMultiplexTransport(
  117. testNodeInfo(PubKeyToID(pv.PubKey()), defaultNodeName),
  118. NodeKey{
  119. PrivKey: pv,
  120. },
  121. )
  122. )
  123. addr, err := NewNetAddressStringWithOptionalID(mt.listener.Addr().String())
  124. if err != nil {
  125. errc <- err
  126. return
  127. }
  128. _, err = dialer.Dial(*addr, peerConfig{})
  129. if err != nil {
  130. errc <- err
  131. return
  132. }
  133. // Signal that the connection was established.
  134. errc <- nil
  135. }()
  136. }
  137. // Catch connection errors.
  138. for i := 0; i < cap(errc); i++ {
  139. if err := <-errc; err != nil {
  140. t.Fatal(err)
  141. }
  142. }
  143. ps := []Peer{}
  144. // Accept all peers.
  145. for i := 0; i < cap(errc); i++ {
  146. p, err := mt.Accept(peerConfig{})
  147. if err != nil {
  148. t.Fatal(err)
  149. }
  150. if err := p.Start(); err != nil {
  151. t.Fatal(err)
  152. }
  153. ps = append(ps, p)
  154. }
  155. if have, want := len(ps), cap(errc); have != want {
  156. t.Errorf("have %v, want %v", have, want)
  157. }
  158. // Stop all peers.
  159. for _, p := range ps {
  160. if err := p.Stop(); err != nil {
  161. t.Fatal(err)
  162. }
  163. }
  164. if err := mt.Close(); err != nil {
  165. t.Errorf("close errored: %v", err)
  166. }
  167. }
  168. func TestTransportMultiplexAcceptNonBlocking(t *testing.T) {
  169. mt := testSetupMultiplexTransport(t)
  170. var (
  171. fastNodePV = ed25519.GenPrivKey()
  172. fastNodeInfo = testNodeInfo(PubKeyToID(fastNodePV.PubKey()), "fastnode")
  173. errc = make(chan error)
  174. fastc = make(chan struct{})
  175. slowc = make(chan struct{})
  176. )
  177. // Simulate slow Peer.
  178. go func() {
  179. addr, err := NewNetAddressStringWithOptionalID(mt.listener.Addr().String())
  180. if err != nil {
  181. errc <- err
  182. return
  183. }
  184. c, err := addr.Dial()
  185. if err != nil {
  186. errc <- err
  187. return
  188. }
  189. close(slowc)
  190. select {
  191. case <-fastc:
  192. // Fast peer connected.
  193. case <-time.After(50 * time.Millisecond):
  194. // We error if the fast peer didn't succeed.
  195. errc <- fmt.Errorf("Fast peer timed out")
  196. }
  197. sc, err := upgradeSecretConn(c, 20*time.Millisecond, ed25519.GenPrivKey())
  198. if err != nil {
  199. errc <- err
  200. return
  201. }
  202. _, err = handshake(sc, 20*time.Millisecond,
  203. testNodeInfo(
  204. PubKeyToID(ed25519.GenPrivKey().PubKey()),
  205. "slow_peer",
  206. ))
  207. if err != nil {
  208. errc <- err
  209. return
  210. }
  211. }()
  212. // Simulate fast Peer.
  213. go func() {
  214. <-slowc
  215. var (
  216. dialer = NewMultiplexTransport(
  217. fastNodeInfo,
  218. NodeKey{
  219. PrivKey: fastNodePV,
  220. },
  221. )
  222. )
  223. addr, err := NewNetAddressStringWithOptionalID(mt.listener.Addr().String())
  224. if err != nil {
  225. errc <- err
  226. return
  227. }
  228. _, err = dialer.Dial(*addr, peerConfig{})
  229. if err != nil {
  230. errc <- err
  231. return
  232. }
  233. close(errc)
  234. close(fastc)
  235. }()
  236. if err := <-errc; err != nil {
  237. t.Errorf("connection failed: %v", err)
  238. }
  239. p, err := mt.Accept(peerConfig{})
  240. if err != nil {
  241. t.Fatal(err)
  242. }
  243. if have, want := p.NodeInfo(), fastNodeInfo; !reflect.DeepEqual(have, want) {
  244. t.Errorf("have %v, want %v", have, want)
  245. }
  246. }
  247. func TestTransportMultiplexValidateNodeInfo(t *testing.T) {
  248. mt := testSetupMultiplexTransport(t)
  249. errc := make(chan error)
  250. go func() {
  251. var (
  252. pv = ed25519.GenPrivKey()
  253. dialer = NewMultiplexTransport(
  254. testNodeInfo(PubKeyToID(pv.PubKey()), ""), // Should not be empty
  255. NodeKey{
  256. PrivKey: pv,
  257. },
  258. )
  259. )
  260. addr, err := NewNetAddressStringWithOptionalID(mt.listener.Addr().String())
  261. if err != nil {
  262. errc <- err
  263. return
  264. }
  265. _, err = dialer.Dial(*addr, peerConfig{})
  266. if err != nil {
  267. errc <- err
  268. return
  269. }
  270. close(errc)
  271. }()
  272. if err := <-errc; err != nil {
  273. t.Errorf("connection failed: %v", err)
  274. }
  275. _, err := mt.Accept(peerConfig{})
  276. if err, ok := err.(ErrRejected); ok {
  277. if !err.IsNodeInfoInvalid() {
  278. t.Errorf("expected NodeInfo to be invalid")
  279. }
  280. } else {
  281. t.Errorf("expected ErrRejected")
  282. }
  283. }
  284. func TestTransportMultiplexRejectMissmatchID(t *testing.T) {
  285. mt := testSetupMultiplexTransport(t)
  286. errc := make(chan error)
  287. go func() {
  288. dialer := NewMultiplexTransport(
  289. testNodeInfo(
  290. PubKeyToID(ed25519.GenPrivKey().PubKey()), "dialer",
  291. ),
  292. NodeKey{
  293. PrivKey: ed25519.GenPrivKey(),
  294. },
  295. )
  296. addr, err := NewNetAddressStringWithOptionalID(mt.listener.Addr().String())
  297. if err != nil {
  298. errc <- err
  299. return
  300. }
  301. _, err = dialer.Dial(*addr, peerConfig{})
  302. if err != nil {
  303. errc <- err
  304. return
  305. }
  306. close(errc)
  307. }()
  308. if err := <-errc; err != nil {
  309. t.Errorf("connection failed: %v", err)
  310. }
  311. _, err := mt.Accept(peerConfig{})
  312. if err, ok := err.(ErrRejected); ok {
  313. if !err.IsAuthFailure() {
  314. t.Errorf("expected auth failure")
  315. }
  316. } else {
  317. t.Errorf("expected ErrRejected")
  318. }
  319. }
  320. func TestTransportMultiplexRejectIncompatible(t *testing.T) {
  321. mt := testSetupMultiplexTransport(t)
  322. errc := make(chan error)
  323. go func() {
  324. var (
  325. pv = ed25519.GenPrivKey()
  326. dialer = NewMultiplexTransport(
  327. testNodeInfoWithNetwork(PubKeyToID(pv.PubKey()), "dialer", "incompatible-network"),
  328. NodeKey{
  329. PrivKey: pv,
  330. },
  331. )
  332. )
  333. addr, err := NewNetAddressStringWithOptionalID(mt.listener.Addr().String())
  334. if err != nil {
  335. errc <- err
  336. return
  337. }
  338. _, err = dialer.Dial(*addr, peerConfig{})
  339. if err != nil {
  340. errc <- err
  341. return
  342. }
  343. close(errc)
  344. }()
  345. _, err := mt.Accept(peerConfig{})
  346. if err, ok := err.(ErrRejected); ok {
  347. if !err.IsIncompatible() {
  348. t.Errorf("expected to reject incompatible")
  349. }
  350. } else {
  351. t.Errorf("expected ErrRejected")
  352. }
  353. }
  354. func TestTransportMultiplexRejectSelf(t *testing.T) {
  355. mt := testSetupMultiplexTransport(t)
  356. errc := make(chan error)
  357. go func() {
  358. addr, err := NewNetAddressStringWithOptionalID(mt.listener.Addr().String())
  359. if err != nil {
  360. errc <- err
  361. return
  362. }
  363. _, err = mt.Dial(*addr, peerConfig{})
  364. if err != nil {
  365. errc <- err
  366. return
  367. }
  368. close(errc)
  369. }()
  370. if err := <-errc; err != nil {
  371. if err, ok := err.(ErrRejected); ok {
  372. if !err.IsSelf() {
  373. t.Errorf("expected to reject self")
  374. }
  375. } else {
  376. t.Errorf("expected ErrRejected")
  377. }
  378. } else {
  379. t.Errorf("expected connection failure")
  380. }
  381. _, err := mt.Accept(peerConfig{})
  382. if err, ok := err.(ErrRejected); ok {
  383. if !err.IsSelf() {
  384. t.Errorf("expected to reject self")
  385. }
  386. } else {
  387. t.Errorf("expected ErrRejected")
  388. }
  389. }
  390. func TestTransportConnDuplicateIPFilter(t *testing.T) {
  391. filter := ConnDuplicateIPFilter()
  392. if err := filter(nil, &testTransportConn{}, nil); err != nil {
  393. t.Fatal(err)
  394. }
  395. var (
  396. c = &testTransportConn{}
  397. cs = NewConnSet()
  398. )
  399. cs.Set(c, []net.IP{
  400. net.IP{10, 0, 10, 1},
  401. net.IP{10, 0, 10, 2},
  402. net.IP{10, 0, 10, 3},
  403. })
  404. if err := filter(cs, c, []net.IP{
  405. net.IP{10, 0, 10, 2},
  406. }); err == nil {
  407. t.Errorf("expected Peer to be rejected as duplicate")
  408. }
  409. }
  410. func TestTransportHandshake(t *testing.T) {
  411. ln, err := net.Listen("tcp", "127.0.0.1:0")
  412. if err != nil {
  413. t.Fatal(err)
  414. }
  415. var (
  416. peerPV = ed25519.GenPrivKey()
  417. peerNodeInfo = testNodeInfo(PubKeyToID(peerPV.PubKey()), defaultNodeName)
  418. )
  419. go func() {
  420. c, err := net.Dial(ln.Addr().Network(), ln.Addr().String())
  421. if err != nil {
  422. t.Error(err)
  423. return
  424. }
  425. go func(c net.Conn) {
  426. _, err := cdc.MarshalBinaryWriter(c, peerNodeInfo.(DefaultNodeInfo))
  427. if err != nil {
  428. t.Error(err)
  429. }
  430. }(c)
  431. go func(c net.Conn) {
  432. var ni DefaultNodeInfo
  433. _, err := cdc.UnmarshalBinaryReader(
  434. c,
  435. &ni,
  436. int64(MaxNodeInfoSize()),
  437. )
  438. if err != nil {
  439. t.Error(err)
  440. }
  441. }(c)
  442. }()
  443. c, err := ln.Accept()
  444. if err != nil {
  445. t.Fatal(err)
  446. }
  447. ni, err := handshake(c, 20*time.Millisecond, emptyNodeInfo())
  448. if err != nil {
  449. t.Fatal(err)
  450. }
  451. if have, want := ni, peerNodeInfo; !reflect.DeepEqual(have, want) {
  452. t.Errorf("have %v, want %v", have, want)
  453. }
  454. }
  455. func testSetupMultiplexTransport(t *testing.T) *MultiplexTransport {
  456. var (
  457. pv = ed25519.GenPrivKey()
  458. mt = NewMultiplexTransport(
  459. testNodeInfo(
  460. PubKeyToID(pv.PubKey()), "transport",
  461. ),
  462. NodeKey{
  463. PrivKey: pv,
  464. },
  465. )
  466. )
  467. addr, err := NewNetAddressStringWithOptionalID("127.0.0.1:0")
  468. if err != nil {
  469. t.Fatal(err)
  470. }
  471. if err := mt.Listen(*addr); err != nil {
  472. t.Fatal(err)
  473. }
  474. return mt
  475. }
  476. type testTransportAddr struct{}
  477. func (a *testTransportAddr) Network() string { return "tcp" }
  478. func (a *testTransportAddr) String() string { return "test.local:1234" }
  479. type testTransportConn struct{}
  480. func (c *testTransportConn) Close() error {
  481. return fmt.Errorf("Close() not implemented")
  482. }
  483. func (c *testTransportConn) LocalAddr() net.Addr {
  484. return &testTransportAddr{}
  485. }
  486. func (c *testTransportConn) RemoteAddr() net.Addr {
  487. return &testTransportAddr{}
  488. }
  489. func (c *testTransportConn) Read(_ []byte) (int, error) {
  490. return -1, fmt.Errorf("Read() not implemented")
  491. }
  492. func (c *testTransportConn) SetDeadline(_ time.Time) error {
  493. return fmt.Errorf("SetDeadline() not implemented")
  494. }
  495. func (c *testTransportConn) SetReadDeadline(_ time.Time) error {
  496. return fmt.Errorf("SetReadDeadline() not implemented")
  497. }
  498. func (c *testTransportConn) SetWriteDeadline(_ time.Time) error {
  499. return fmt.Errorf("SetWriteDeadline() not implemented")
  500. }
  501. func (c *testTransportConn) Write(_ []byte) (int, error) {
  502. return -1, fmt.Errorf("Write() not implemented")
  503. }