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.

34 lines
1.8 KiB

  1. /*
  2. Package PEX (Peer exchange) handles all the logic necessary for nodes to share
  3. information about their peers to other nodes. Specifically, this is the exchange
  4. of addresses that a peer can use to discover more peers within the network.
  5. The PEX reactor is a continuous service which periodically requests addresses
  6. and serves addresses to other peers. There are two versions of this service
  7. aligning with the two p2p frameworks that Tendermint currently supports.
  8. V1 is coupled with the Switch (which handles peer connections and routing of
  9. messages) and, alongside exchanging peer information in the form of port/IP
  10. pairs, also has the responsibility of dialing peers and ensuring that a
  11. node has a sufficient amount of peers connected.
  12. V2 is embedded with the new p2p stack and uses the peer manager to advertise
  13. peers as well as add new peers to the peer store. The V2 reactor passes a
  14. different set of proto messages which include a list of
  15. [urls](https://golang.org/pkg/net/url/#URL).These can be used to save a set of
  16. endpoints that each peer uses. The V2 reactor has backwards compatibility with
  17. V1. It can also handle V1 messages.
  18. The V2 reactor is able to tweak the intensity of it's search by decreasing or
  19. increasing the interval between each request. It tracks connected peers via a
  20. linked list, sending a request to the node at the front of the list and adding
  21. it to the back of the list once a response is received. Using this method, a
  22. node is able to spread out the load of requesting peers across all the peers it
  23. is currently connected with.
  24. With each inbound set of addresses, the reactor monitors the amount of new
  25. addresses to already seen addresses and uses the information to dynamically
  26. build a picture of the size of the network in order to ascertain how often the
  27. node needs to search for new peers.
  28. */
  29. package pex