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.

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