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.

184 lines
4.2 KiB

7 years ago
7 years ago
p2p: seed mode refactoring (#3011) ListOfKnownAddresses is removed panic if addrbook size is less than zero CrawlPeers does not attempt to connect to existing or peers we're currently dialing various perf. fixes improved tests (though not complete) move IsDialingOrExistingAddress check into DialPeerWithAddress (Fixes #2716) * addrbook: preallocate memory when saving addrbook to file * addrbook: remove oldestFirst struct and check for ID * oldestFirst replaced with sort.Slice * ID is now mandatory, so no need to check * addrbook: remove ListOfKnownAddresses GetSelection is used instead in seed mode. * addrbook: panic if size is less than 0 * rewrite addrbook#saveToFile to not use a counter * test AttemptDisconnects func * move IsDialingOrExistingAddress check into DialPeerWithAddress * save and cleanup crawl peer data * get rid of DefaultSeedDisconnectWaitPeriod * make linter happy * fix TestPEXReactorSeedMode * fix comment * add a changelog entry * Apply suggestions from code review Co-Authored-By: melekes <anton.kalyaev@gmail.com> * rename ErrDialingOrExistingAddress to ErrCurrentlyDialingOrExistingAddress * lowercase errors * do not persist seed data pros: - no extra files - less IO cons: - if the node crashes, seed might crawl a peer too soon * fixes after Ethan's review * add a changelog entry * we should only consult Switch about peers checking addrbook size does not make sense since only PEX reactor uses it for dialing peers! https://github.com/tendermint/tendermint/pull/3011#discussion_r270948875
6 years ago
7 years ago
7 years ago
p2p: seed mode refactoring (#3011) ListOfKnownAddresses is removed panic if addrbook size is less than zero CrawlPeers does not attempt to connect to existing or peers we're currently dialing various perf. fixes improved tests (though not complete) move IsDialingOrExistingAddress check into DialPeerWithAddress (Fixes #2716) * addrbook: preallocate memory when saving addrbook to file * addrbook: remove oldestFirst struct and check for ID * oldestFirst replaced with sort.Slice * ID is now mandatory, so no need to check * addrbook: remove ListOfKnownAddresses GetSelection is used instead in seed mode. * addrbook: panic if size is less than 0 * rewrite addrbook#saveToFile to not use a counter * test AttemptDisconnects func * move IsDialingOrExistingAddress check into DialPeerWithAddress * save and cleanup crawl peer data * get rid of DefaultSeedDisconnectWaitPeriod * make linter happy * fix TestPEXReactorSeedMode * fix comment * add a changelog entry * Apply suggestions from code review Co-Authored-By: melekes <anton.kalyaev@gmail.com> * rename ErrDialingOrExistingAddress to ErrCurrentlyDialingOrExistingAddress * lowercase errors * do not persist seed data pros: - no extra files - less IO cons: - if the node crashes, seed might crawl a peer too soon * fixes after Ethan's review * add a changelog entry * we should only consult Switch about peers checking addrbook size does not make sense since only PEX reactor uses it for dialing peers! https://github.com/tendermint/tendermint/pull/3011#discussion_r270948875
6 years ago
7 years ago
p2p: seed mode refactoring (#3011) ListOfKnownAddresses is removed panic if addrbook size is less than zero CrawlPeers does not attempt to connect to existing or peers we're currently dialing various perf. fixes improved tests (though not complete) move IsDialingOrExistingAddress check into DialPeerWithAddress (Fixes #2716) * addrbook: preallocate memory when saving addrbook to file * addrbook: remove oldestFirst struct and check for ID * oldestFirst replaced with sort.Slice * ID is now mandatory, so no need to check * addrbook: remove ListOfKnownAddresses GetSelection is used instead in seed mode. * addrbook: panic if size is less than 0 * rewrite addrbook#saveToFile to not use a counter * test AttemptDisconnects func * move IsDialingOrExistingAddress check into DialPeerWithAddress * save and cleanup crawl peer data * get rid of DefaultSeedDisconnectWaitPeriod * make linter happy * fix TestPEXReactorSeedMode * fix comment * add a changelog entry * Apply suggestions from code review Co-Authored-By: melekes <anton.kalyaev@gmail.com> * rename ErrDialingOrExistingAddress to ErrCurrentlyDialingOrExistingAddress * lowercase errors * do not persist seed data pros: - no extra files - less IO cons: - if the node crashes, seed might crawl a peer too soon * fixes after Ethan's review * add a changelog entry * we should only consult Switch about peers checking addrbook size does not make sense since only PEX reactor uses it for dialing peers! https://github.com/tendermint/tendermint/pull/3011#discussion_r270948875
6 years ago
7 years ago
p2p: seed mode refactoring (#3011) ListOfKnownAddresses is removed panic if addrbook size is less than zero CrawlPeers does not attempt to connect to existing or peers we're currently dialing various perf. fixes improved tests (though not complete) move IsDialingOrExistingAddress check into DialPeerWithAddress (Fixes #2716) * addrbook: preallocate memory when saving addrbook to file * addrbook: remove oldestFirst struct and check for ID * oldestFirst replaced with sort.Slice * ID is now mandatory, so no need to check * addrbook: remove ListOfKnownAddresses GetSelection is used instead in seed mode. * addrbook: panic if size is less than 0 * rewrite addrbook#saveToFile to not use a counter * test AttemptDisconnects func * move IsDialingOrExistingAddress check into DialPeerWithAddress * save and cleanup crawl peer data * get rid of DefaultSeedDisconnectWaitPeriod * make linter happy * fix TestPEXReactorSeedMode * fix comment * add a changelog entry * Apply suggestions from code review Co-Authored-By: melekes <anton.kalyaev@gmail.com> * rename ErrDialingOrExistingAddress to ErrCurrentlyDialingOrExistingAddress * lowercase errors * do not persist seed data pros: - no extra files - less IO cons: - if the node crashes, seed might crawl a peer too soon * fixes after Ethan's review * add a changelog entry * we should only consult Switch about peers checking addrbook size does not make sense since only PEX reactor uses it for dialing peers! https://github.com/tendermint/tendermint/pull/3011#discussion_r270948875
6 years ago
7 years ago
p2p: seed mode refactoring (#3011) ListOfKnownAddresses is removed panic if addrbook size is less than zero CrawlPeers does not attempt to connect to existing or peers we're currently dialing various perf. fixes improved tests (though not complete) move IsDialingOrExistingAddress check into DialPeerWithAddress (Fixes #2716) * addrbook: preallocate memory when saving addrbook to file * addrbook: remove oldestFirst struct and check for ID * oldestFirst replaced with sort.Slice * ID is now mandatory, so no need to check * addrbook: remove ListOfKnownAddresses GetSelection is used instead in seed mode. * addrbook: panic if size is less than 0 * rewrite addrbook#saveToFile to not use a counter * test AttemptDisconnects func * move IsDialingOrExistingAddress check into DialPeerWithAddress * save and cleanup crawl peer data * get rid of DefaultSeedDisconnectWaitPeriod * make linter happy * fix TestPEXReactorSeedMode * fix comment * add a changelog entry * Apply suggestions from code review Co-Authored-By: melekes <anton.kalyaev@gmail.com> * rename ErrDialingOrExistingAddress to ErrCurrentlyDialingOrExistingAddress * lowercase errors * do not persist seed data pros: - no extra files - less IO cons: - if the node crashes, seed might crawl a peer too soon * fixes after Ethan's review * add a changelog entry * we should only consult Switch about peers checking addrbook size does not make sense since only PEX reactor uses it for dialing peers! https://github.com/tendermint/tendermint/pull/3011#discussion_r270948875
6 years ago
p2p: seed mode refactoring (#3011) ListOfKnownAddresses is removed panic if addrbook size is less than zero CrawlPeers does not attempt to connect to existing or peers we're currently dialing various perf. fixes improved tests (though not complete) move IsDialingOrExistingAddress check into DialPeerWithAddress (Fixes #2716) * addrbook: preallocate memory when saving addrbook to file * addrbook: remove oldestFirst struct and check for ID * oldestFirst replaced with sort.Slice * ID is now mandatory, so no need to check * addrbook: remove ListOfKnownAddresses GetSelection is used instead in seed mode. * addrbook: panic if size is less than 0 * rewrite addrbook#saveToFile to not use a counter * test AttemptDisconnects func * move IsDialingOrExistingAddress check into DialPeerWithAddress * save and cleanup crawl peer data * get rid of DefaultSeedDisconnectWaitPeriod * make linter happy * fix TestPEXReactorSeedMode * fix comment * add a changelog entry * Apply suggestions from code review Co-Authored-By: melekes <anton.kalyaev@gmail.com> * rename ErrDialingOrExistingAddress to ErrCurrentlyDialingOrExistingAddress * lowercase errors * do not persist seed data pros: - no extra files - less IO cons: - if the node crashes, seed might crawl a peer too soon * fixes after Ethan's review * add a changelog entry * we should only consult Switch about peers checking addrbook size does not make sense since only PEX reactor uses it for dialing peers! https://github.com/tendermint/tendermint/pull/3011#discussion_r270948875
6 years ago
p2p: seed mode refactoring (#3011) ListOfKnownAddresses is removed panic if addrbook size is less than zero CrawlPeers does not attempt to connect to existing or peers we're currently dialing various perf. fixes improved tests (though not complete) move IsDialingOrExistingAddress check into DialPeerWithAddress (Fixes #2716) * addrbook: preallocate memory when saving addrbook to file * addrbook: remove oldestFirst struct and check for ID * oldestFirst replaced with sort.Slice * ID is now mandatory, so no need to check * addrbook: remove ListOfKnownAddresses GetSelection is used instead in seed mode. * addrbook: panic if size is less than 0 * rewrite addrbook#saveToFile to not use a counter * test AttemptDisconnects func * move IsDialingOrExistingAddress check into DialPeerWithAddress * save and cleanup crawl peer data * get rid of DefaultSeedDisconnectWaitPeriod * make linter happy * fix TestPEXReactorSeedMode * fix comment * add a changelog entry * Apply suggestions from code review Co-Authored-By: melekes <anton.kalyaev@gmail.com> * rename ErrDialingOrExistingAddress to ErrCurrentlyDialingOrExistingAddress * lowercase errors * do not persist seed data pros: - no extra files - less IO cons: - if the node crashes, seed might crawl a peer too soon * fixes after Ethan's review * add a changelog entry * we should only consult Switch about peers checking addrbook size does not make sense since only PEX reactor uses it for dialing peers! https://github.com/tendermint/tendermint/pull/3011#discussion_r270948875
6 years ago
  1. package p2p
  2. import (
  3. "fmt"
  4. "net"
  5. )
  6. // ErrFilterTimeout indicates that a filter operation timed out.
  7. type ErrFilterTimeout struct{}
  8. func (e ErrFilterTimeout) Error() string {
  9. return "filter timed out"
  10. }
  11. // ErrRejected indicates that a Peer was rejected carrying additional
  12. // information as to the reason.
  13. type ErrRejected struct {
  14. addr NetAddress
  15. conn net.Conn
  16. err error
  17. id NodeID
  18. isAuthFailure bool
  19. isDuplicate bool
  20. isFiltered bool
  21. isIncompatible bool
  22. isNodeInfoInvalid bool
  23. isSelf bool
  24. }
  25. // Addr returns the NetAddress for the rejected Peer.
  26. func (e ErrRejected) Addr() NetAddress {
  27. return e.addr
  28. }
  29. func (e ErrRejected) Error() string {
  30. if e.isAuthFailure {
  31. return fmt.Sprintf("auth failure: %s", e.err)
  32. }
  33. if e.isDuplicate {
  34. if e.conn != nil {
  35. return fmt.Sprintf(
  36. "duplicate CONN<%s>",
  37. e.conn.RemoteAddr().String(),
  38. )
  39. }
  40. if e.id != "" {
  41. return fmt.Sprintf("duplicate ID<%v>", e.id)
  42. }
  43. }
  44. if e.isFiltered {
  45. if e.conn != nil {
  46. return fmt.Sprintf(
  47. "filtered CONN<%s>: %s",
  48. e.conn.RemoteAddr().String(),
  49. e.err,
  50. )
  51. }
  52. if e.id != "" {
  53. return fmt.Sprintf("filtered ID<%v>: %s", e.id, e.err)
  54. }
  55. }
  56. if e.isIncompatible {
  57. return fmt.Sprintf("incompatible: %s", e.err)
  58. }
  59. if e.isNodeInfoInvalid {
  60. return fmt.Sprintf("invalid NodeInfo: %s", e.err)
  61. }
  62. if e.isSelf {
  63. return fmt.Sprintf("self ID<%v>", e.id)
  64. }
  65. return fmt.Sprintf("%s", e.err)
  66. }
  67. // IsAuthFailure when Peer authentication was unsuccessful.
  68. func (e ErrRejected) IsAuthFailure() bool { return e.isAuthFailure }
  69. // IsDuplicate when Peer ID or IP are present already.
  70. func (e ErrRejected) IsDuplicate() bool { return e.isDuplicate }
  71. // IsFiltered when Peer ID or IP was filtered.
  72. func (e ErrRejected) IsFiltered() bool { return e.isFiltered }
  73. // IsIncompatible when Peer NodeInfo is not compatible with our own.
  74. func (e ErrRejected) IsIncompatible() bool { return e.isIncompatible }
  75. // IsNodeInfoInvalid when the sent NodeInfo is not valid.
  76. func (e ErrRejected) IsNodeInfoInvalid() bool { return e.isNodeInfoInvalid }
  77. // IsSelf when Peer is our own node.
  78. func (e ErrRejected) IsSelf() bool { return e.isSelf }
  79. // ErrSwitchDuplicatePeerID to be raised when a peer is connecting with a known
  80. // ID.
  81. type ErrSwitchDuplicatePeerID struct {
  82. ID NodeID
  83. }
  84. func (e ErrSwitchDuplicatePeerID) Error() string {
  85. return fmt.Sprintf("duplicate peer ID %v", e.ID)
  86. }
  87. // ErrSwitchDuplicatePeerIP to be raised whena a peer is connecting with a known
  88. // IP.
  89. type ErrSwitchDuplicatePeerIP struct {
  90. IP net.IP
  91. }
  92. func (e ErrSwitchDuplicatePeerIP) Error() string {
  93. return fmt.Sprintf("duplicate peer IP %v", e.IP.String())
  94. }
  95. // ErrSwitchConnectToSelf to be raised when trying to connect to itself.
  96. type ErrSwitchConnectToSelf struct {
  97. Addr *NetAddress
  98. }
  99. func (e ErrSwitchConnectToSelf) Error() string {
  100. return fmt.Sprintf("connect to self: %v", e.Addr)
  101. }
  102. type ErrSwitchAuthenticationFailure struct {
  103. Dialed *NetAddress
  104. Got NodeID
  105. }
  106. func (e ErrSwitchAuthenticationFailure) Error() string {
  107. return fmt.Sprintf(
  108. "failed to authenticate peer. Dialed %v, but got peer with ID %s",
  109. e.Dialed,
  110. e.Got,
  111. )
  112. }
  113. // ErrTransportClosed is raised when the Transport has been closed.
  114. type ErrTransportClosed struct{}
  115. func (e ErrTransportClosed) Error() string {
  116. return "transport has been closed"
  117. }
  118. //-------------------------------------------------------------------
  119. type ErrNetAddressNoID struct {
  120. Addr string
  121. }
  122. func (e ErrNetAddressNoID) Error() string {
  123. return fmt.Sprintf("address (%s) does not contain ID", e.Addr)
  124. }
  125. type ErrNetAddressInvalid struct {
  126. Addr string
  127. Err error
  128. }
  129. func (e ErrNetAddressInvalid) Error() string {
  130. return fmt.Sprintf("invalid address (%s): %v", e.Addr, e.Err)
  131. }
  132. type ErrNetAddressLookup struct {
  133. Addr string
  134. Err error
  135. }
  136. func (e ErrNetAddressLookup) Error() string {
  137. return fmt.Sprintf("error looking up host (%s): %v", e.Addr, e.Err)
  138. }
  139. // ErrCurrentlyDialingOrExistingAddress indicates that we're currently
  140. // dialing this address or it belongs to an existing peer.
  141. type ErrCurrentlyDialingOrExistingAddress struct {
  142. Addr string
  143. }
  144. func (e ErrCurrentlyDialingOrExistingAddress) Error() string {
  145. return fmt.Sprintf("connection with %s has been established or dialed", e.Addr)
  146. }