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.

664 lines
18 KiB

lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
p2p: 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
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
p2p: 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
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
p2p: 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
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
p2p: 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
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
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
  1. package pex
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "os"
  6. "path/filepath"
  7. "testing"
  8. "time"
  9. "github.com/stretchr/testify/assert"
  10. "github.com/stretchr/testify/require"
  11. "github.com/tendermint/tendermint/config"
  12. "github.com/tendermint/tendermint/libs/log"
  13. "github.com/tendermint/tendermint/p2p"
  14. "github.com/tendermint/tendermint/p2p/mock"
  15. )
  16. var (
  17. cfg *config.P2PConfig
  18. )
  19. func init() {
  20. cfg = config.DefaultP2PConfig()
  21. cfg.PexReactor = true
  22. cfg.AllowDuplicateIP = true
  23. }
  24. func TestPEXReactorBasic(t *testing.T) {
  25. r, book := createReactor(&ReactorConfig{})
  26. defer teardownReactor(book)
  27. assert.NotNil(t, r)
  28. assert.NotEmpty(t, r.GetChannels())
  29. }
  30. func TestPEXReactorAddRemovePeer(t *testing.T) {
  31. r, book := createReactor(&ReactorConfig{})
  32. defer teardownReactor(book)
  33. size := book.Size()
  34. peer := p2p.CreateRandomPeer(false)
  35. r.AddPeer(peer)
  36. assert.Equal(t, size+1, book.Size())
  37. r.RemovePeer(peer, "peer not available")
  38. outboundPeer := p2p.CreateRandomPeer(true)
  39. r.AddPeer(outboundPeer)
  40. assert.Equal(t, size+1, book.Size(), "outbound peers should not be added to the address book")
  41. r.RemovePeer(outboundPeer, "peer not available")
  42. }
  43. // --- FAIL: TestPEXReactorRunning (11.10s)
  44. // pex_reactor_test.go:411: expected all switches to be connected to at
  45. // least one peer (switches: 0 => {outbound: 1, inbound: 0}, 1 =>
  46. // {outbound: 0, inbound: 1}, 2 => {outbound: 0, inbound: 0}, )
  47. //
  48. // EXPLANATION: peers are getting rejected because in switch#addPeer we check
  49. // if any peer (who we already connected to) has the same IP. Even though local
  50. // peers have different IP addresses, they all have the same underlying remote
  51. // IP: 127.0.0.1.
  52. //
  53. func TestPEXReactorRunning(t *testing.T) {
  54. N := 3
  55. switches := make([]*p2p.Switch, N)
  56. // directory to store address books
  57. dir, err := ioutil.TempDir("", "pex_reactor")
  58. require.Nil(t, err)
  59. defer os.RemoveAll(dir) // nolint: errcheck
  60. books := make([]AddrBook, N)
  61. logger := log.TestingLogger()
  62. // create switches
  63. for i := 0; i < N; i++ {
  64. switches[i] = p2p.MakeSwitch(cfg, i, "testing", "123.123.123", func(i int, sw *p2p.Switch) *p2p.Switch {
  65. books[i] = NewAddrBook(filepath.Join(dir, fmt.Sprintf("addrbook%d.json", i)), false)
  66. books[i].SetLogger(logger.With("pex", i))
  67. sw.SetAddrBook(books[i])
  68. sw.SetLogger(logger.With("pex", i))
  69. r := NewReactor(books[i], &ReactorConfig{})
  70. r.SetLogger(logger.With("pex", i))
  71. r.SetEnsurePeersPeriod(250 * time.Millisecond)
  72. sw.AddReactor("pex", r)
  73. return sw
  74. })
  75. }
  76. addOtherNodeAddrToAddrBook := func(switchIndex, otherSwitchIndex int) {
  77. addr := switches[otherSwitchIndex].NetAddress()
  78. books[switchIndex].AddAddress(addr, addr)
  79. }
  80. addOtherNodeAddrToAddrBook(0, 1)
  81. addOtherNodeAddrToAddrBook(1, 0)
  82. addOtherNodeAddrToAddrBook(2, 1)
  83. for _, sw := range switches {
  84. err := sw.Start() // start switch and reactors
  85. require.Nil(t, err)
  86. }
  87. assertPeersWithTimeout(t, switches, 10*time.Millisecond, 10*time.Second, N-1)
  88. // stop them
  89. for _, s := range switches {
  90. s.Stop()
  91. }
  92. }
  93. func TestPEXReactorReceive(t *testing.T) {
  94. r, book := createReactor(&ReactorConfig{})
  95. defer teardownReactor(book)
  96. peer := p2p.CreateRandomPeer(false)
  97. // we have to send a request to receive responses
  98. r.RequestAddrs(peer)
  99. size := book.Size()
  100. addrs := []*p2p.NetAddress{peer.SocketAddr()}
  101. msg := cdc.MustMarshalBinaryBare(&pexAddrsMessage{Addrs: addrs})
  102. r.Receive(PexChannel, peer, msg)
  103. assert.Equal(t, size+1, book.Size())
  104. msg = cdc.MustMarshalBinaryBare(&pexRequestMessage{})
  105. r.Receive(PexChannel, peer, msg) // should not panic.
  106. }
  107. func TestPEXReactorRequestMessageAbuse(t *testing.T) {
  108. r, book := createReactor(&ReactorConfig{})
  109. defer teardownReactor(book)
  110. sw := createSwitchAndAddReactors(r)
  111. sw.SetAddrBook(book)
  112. peer := mock.NewPeer(nil)
  113. p2p.AddPeerToSwitchPeerSet(sw, peer)
  114. assert.True(t, sw.Peers().Has(peer.ID()))
  115. id := string(peer.ID())
  116. msg := cdc.MustMarshalBinaryBare(&pexRequestMessage{})
  117. // first time creates the entry
  118. r.Receive(PexChannel, peer, msg)
  119. assert.True(t, r.lastReceivedRequests.Has(id))
  120. assert.True(t, sw.Peers().Has(peer.ID()))
  121. // next time sets the last time value
  122. r.Receive(PexChannel, peer, msg)
  123. assert.True(t, r.lastReceivedRequests.Has(id))
  124. assert.True(t, sw.Peers().Has(peer.ID()))
  125. // third time is too many too soon - peer is removed
  126. r.Receive(PexChannel, peer, msg)
  127. assert.False(t, r.lastReceivedRequests.Has(id))
  128. assert.False(t, sw.Peers().Has(peer.ID()))
  129. }
  130. func TestPEXReactorAddrsMessageAbuse(t *testing.T) {
  131. r, book := createReactor(&ReactorConfig{})
  132. defer teardownReactor(book)
  133. sw := createSwitchAndAddReactors(r)
  134. sw.SetAddrBook(book)
  135. peer := mock.NewPeer(nil)
  136. p2p.AddPeerToSwitchPeerSet(sw, peer)
  137. assert.True(t, sw.Peers().Has(peer.ID()))
  138. id := string(peer.ID())
  139. // request addrs from the peer
  140. r.RequestAddrs(peer)
  141. assert.True(t, r.requestsSent.Has(id))
  142. assert.True(t, sw.Peers().Has(peer.ID()))
  143. addrs := []*p2p.NetAddress{peer.SocketAddr()}
  144. msg := cdc.MustMarshalBinaryBare(&pexAddrsMessage{Addrs: addrs})
  145. // receive some addrs. should clear the request
  146. r.Receive(PexChannel, peer, msg)
  147. assert.False(t, r.requestsSent.Has(id))
  148. assert.True(t, sw.Peers().Has(peer.ID()))
  149. // receiving more addrs causes a disconnect
  150. r.Receive(PexChannel, peer, msg)
  151. assert.False(t, sw.Peers().Has(peer.ID()))
  152. }
  153. func TestCheckSeeds(t *testing.T) {
  154. // directory to store address books
  155. dir, err := ioutil.TempDir("", "pex_reactor")
  156. require.Nil(t, err)
  157. defer os.RemoveAll(dir) // nolint: errcheck
  158. // 1. test creating peer with no seeds works
  159. peerSwitch := testCreateDefaultPeer(dir, 0)
  160. require.Nil(t, peerSwitch.Start())
  161. peerSwitch.Stop()
  162. // 2. create seed
  163. seed := testCreateSeed(dir, 1, []*p2p.NetAddress{}, []*p2p.NetAddress{})
  164. // 3. test create peer with online seed works
  165. peerSwitch = testCreatePeerWithSeed(dir, 2, seed)
  166. require.Nil(t, peerSwitch.Start())
  167. peerSwitch.Stop()
  168. // 4. test create peer with all seeds having unresolvable DNS fails
  169. badPeerConfig := &ReactorConfig{
  170. Seeds: []string{"ed3dfd27bfc4af18f67a49862f04cc100696e84d@bad.network.addr:26657",
  171. "d824b13cb5d40fa1d8a614e089357c7eff31b670@anotherbad.network.addr:26657"},
  172. }
  173. peerSwitch = testCreatePeerWithConfig(dir, 2, badPeerConfig)
  174. require.Error(t, peerSwitch.Start())
  175. peerSwitch.Stop()
  176. // 5. test create peer with one good seed address succeeds
  177. badPeerConfig = &ReactorConfig{
  178. Seeds: []string{"ed3dfd27bfc4af18f67a49862f04cc100696e84d@bad.network.addr:26657",
  179. "d824b13cb5d40fa1d8a614e089357c7eff31b670@anotherbad.network.addr:26657",
  180. seed.NetAddress().String()},
  181. }
  182. peerSwitch = testCreatePeerWithConfig(dir, 2, badPeerConfig)
  183. require.Nil(t, peerSwitch.Start())
  184. peerSwitch.Stop()
  185. }
  186. func TestPEXReactorUsesSeedsIfNeeded(t *testing.T) {
  187. // directory to store address books
  188. dir, err := ioutil.TempDir("", "pex_reactor")
  189. require.Nil(t, err)
  190. defer os.RemoveAll(dir) // nolint: errcheck
  191. // 1. create seed
  192. seed := testCreateSeed(dir, 0, []*p2p.NetAddress{}, []*p2p.NetAddress{})
  193. require.Nil(t, seed.Start())
  194. defer seed.Stop()
  195. // 2. create usual peer with only seed configured.
  196. peer := testCreatePeerWithSeed(dir, 1, seed)
  197. require.Nil(t, peer.Start())
  198. defer peer.Stop()
  199. // 3. check that the peer connects to seed immediately
  200. assertPeersWithTimeout(t, []*p2p.Switch{peer}, 10*time.Millisecond, 3*time.Second, 1)
  201. }
  202. func TestConnectionSpeedForPeerReceivedFromSeed(t *testing.T) {
  203. // directory to store address books
  204. dir, err := ioutil.TempDir("", "pex_reactor")
  205. require.Nil(t, err)
  206. defer os.RemoveAll(dir) // nolint: errcheck
  207. // 1. create peer
  208. peerSwitch := testCreateDefaultPeer(dir, 1)
  209. require.Nil(t, peerSwitch.Start())
  210. defer peerSwitch.Stop()
  211. // 2. Create seed which knows about the peer
  212. peerAddr := peerSwitch.NetAddress()
  213. seed := testCreateSeed(dir, 2, []*p2p.NetAddress{peerAddr}, []*p2p.NetAddress{peerAddr})
  214. require.Nil(t, seed.Start())
  215. defer seed.Stop()
  216. // 3. create another peer with only seed configured.
  217. secondPeer := testCreatePeerWithSeed(dir, 3, seed)
  218. require.Nil(t, secondPeer.Start())
  219. defer secondPeer.Stop()
  220. // 4. check that the second peer connects to seed immediately
  221. assertPeersWithTimeout(t, []*p2p.Switch{secondPeer}, 10*time.Millisecond, 3*time.Second, 1)
  222. // 5. check that the second peer connects to the first peer immediately
  223. assertPeersWithTimeout(t, []*p2p.Switch{secondPeer}, 10*time.Millisecond, 1*time.Second, 2)
  224. }
  225. func TestPEXReactorSeedMode(t *testing.T) {
  226. // directory to store address books
  227. dir, err := ioutil.TempDir("", "pex_reactor")
  228. require.Nil(t, err)
  229. defer os.RemoveAll(dir) // nolint: errcheck
  230. pexRConfig := &ReactorConfig{SeedMode: true, SeedDisconnectWaitPeriod: 10 * time.Millisecond}
  231. pexR, book := createReactor(pexRConfig)
  232. defer teardownReactor(book)
  233. sw := createSwitchAndAddReactors(pexR)
  234. sw.SetAddrBook(book)
  235. err = sw.Start()
  236. require.NoError(t, err)
  237. defer sw.Stop()
  238. assert.Zero(t, sw.Peers().Size())
  239. peerSwitch := testCreateDefaultPeer(dir, 1)
  240. require.NoError(t, peerSwitch.Start())
  241. defer peerSwitch.Stop()
  242. // 1. Test crawlPeers dials the peer
  243. pexR.crawlPeers([]*p2p.NetAddress{peerSwitch.NetAddress()})
  244. assert.Equal(t, 1, sw.Peers().Size())
  245. assert.True(t, sw.Peers().Has(peerSwitch.NodeInfo().ID()))
  246. // 2. attemptDisconnects should not disconnect because of wait period
  247. pexR.attemptDisconnects()
  248. assert.Equal(t, 1, sw.Peers().Size())
  249. // sleep for SeedDisconnectWaitPeriod
  250. time.Sleep(pexRConfig.SeedDisconnectWaitPeriod + 1*time.Millisecond)
  251. // 3. attemptDisconnects should disconnect after wait period
  252. pexR.attemptDisconnects()
  253. assert.Equal(t, 0, sw.Peers().Size())
  254. }
  255. func TestPEXReactorDoesNotDisconnectFromPersistentPeerInSeedMode(t *testing.T) {
  256. // directory to store address books
  257. dir, err := ioutil.TempDir("", "pex_reactor")
  258. require.Nil(t, err)
  259. defer os.RemoveAll(dir) // nolint: errcheck
  260. pexRConfig := &ReactorConfig{SeedMode: true, SeedDisconnectWaitPeriod: 1 * time.Millisecond}
  261. pexR, book := createReactor(pexRConfig)
  262. defer teardownReactor(book)
  263. sw := createSwitchAndAddReactors(pexR)
  264. sw.SetAddrBook(book)
  265. err = sw.Start()
  266. require.NoError(t, err)
  267. defer sw.Stop()
  268. assert.Zero(t, sw.Peers().Size())
  269. peerSwitch := testCreateDefaultPeer(dir, 1)
  270. require.NoError(t, peerSwitch.Start())
  271. defer peerSwitch.Stop()
  272. err = sw.AddPersistentPeers([]string{peerSwitch.NetAddress().String()})
  273. require.NoError(t, err)
  274. // 1. Test crawlPeers dials the peer
  275. pexR.crawlPeers([]*p2p.NetAddress{peerSwitch.NetAddress()})
  276. assert.Equal(t, 1, sw.Peers().Size())
  277. assert.True(t, sw.Peers().Has(peerSwitch.NodeInfo().ID()))
  278. // sleep for SeedDisconnectWaitPeriod
  279. time.Sleep(pexRConfig.SeedDisconnectWaitPeriod + 1*time.Millisecond)
  280. // 2. attemptDisconnects should not disconnect because the peer is persistent
  281. pexR.attemptDisconnects()
  282. assert.Equal(t, 1, sw.Peers().Size())
  283. }
  284. func TestPEXReactorDialsPeerUpToMaxAttemptsInSeedMode(t *testing.T) {
  285. // directory to store address books
  286. dir, err := ioutil.TempDir("", "pex_reactor")
  287. require.Nil(t, err)
  288. defer os.RemoveAll(dir) // nolint: errcheck
  289. pexR, book := createReactor(&ReactorConfig{SeedMode: true})
  290. defer teardownReactor(book)
  291. sw := createSwitchAndAddReactors(pexR)
  292. sw.SetAddrBook(book)
  293. err = sw.Start()
  294. require.NoError(t, err)
  295. defer sw.Stop()
  296. peer := mock.NewPeer(nil)
  297. addr := peer.SocketAddr()
  298. err = book.AddAddress(addr, addr)
  299. require.NoError(t, err)
  300. assert.True(t, book.HasAddress(addr))
  301. // imitate maxAttemptsToDial reached
  302. pexR.attemptsToDial.Store(addr.DialString(), _attemptsToDial{maxAttemptsToDial + 1, time.Now()})
  303. pexR.crawlPeers([]*p2p.NetAddress{addr})
  304. assert.False(t, book.HasAddress(addr))
  305. }
  306. // connect a peer to a seed, wait a bit, then stop it.
  307. // this should give it time to request addrs and for the seed
  308. // to call FlushStop, and allows us to test calling Stop concurrently
  309. // with FlushStop. Before a fix, this non-deterministically reproduced
  310. // https://github.com/tendermint/tendermint/issues/3231.
  311. func TestPEXReactorSeedModeFlushStop(t *testing.T) {
  312. N := 2
  313. switches := make([]*p2p.Switch, N)
  314. // directory to store address books
  315. dir, err := ioutil.TempDir("", "pex_reactor")
  316. require.Nil(t, err)
  317. defer os.RemoveAll(dir) // nolint: errcheck
  318. books := make([]AddrBook, N)
  319. logger := log.TestingLogger()
  320. // create switches
  321. for i := 0; i < N; i++ {
  322. switches[i] = p2p.MakeSwitch(cfg, i, "testing", "123.123.123", func(i int, sw *p2p.Switch) *p2p.Switch {
  323. books[i] = NewAddrBook(filepath.Join(dir, fmt.Sprintf("addrbook%d.json", i)), false)
  324. books[i].SetLogger(logger.With("pex", i))
  325. sw.SetAddrBook(books[i])
  326. sw.SetLogger(logger.With("pex", i))
  327. config := &ReactorConfig{}
  328. if i == 0 {
  329. // first one is a seed node
  330. config = &ReactorConfig{SeedMode: true}
  331. }
  332. r := NewReactor(books[i], config)
  333. r.SetLogger(logger.With("pex", i))
  334. r.SetEnsurePeersPeriod(250 * time.Millisecond)
  335. sw.AddReactor("pex", r)
  336. return sw
  337. })
  338. }
  339. for _, sw := range switches {
  340. err := sw.Start() // start switch and reactors
  341. require.Nil(t, err)
  342. }
  343. reactor := switches[0].Reactors()["pex"].(*Reactor)
  344. peerID := switches[1].NodeInfo().ID()
  345. err = switches[1].DialPeerWithAddress(switches[0].NetAddress())
  346. assert.NoError(t, err)
  347. // sleep up to a second while waiting for the peer to send us a message.
  348. // this isn't perfect since it's possible the peer sends us a msg and we FlushStop
  349. // before this loop catches it. but non-deterministically it works pretty well.
  350. for i := 0; i < 1000; i++ {
  351. v := reactor.lastReceivedRequests.Get(string(peerID))
  352. if v != nil {
  353. break
  354. }
  355. time.Sleep(time.Millisecond)
  356. }
  357. // by now the FlushStop should have happened. Try stopping the peer.
  358. // it should be safe to do this.
  359. peers := switches[0].Peers().List()
  360. for _, peer := range peers {
  361. peer.Stop()
  362. }
  363. // stop the switches
  364. for _, s := range switches {
  365. s.Stop()
  366. }
  367. }
  368. func TestPEXReactorDoesNotAddPrivatePeersToAddrBook(t *testing.T) {
  369. peer := p2p.CreateRandomPeer(false)
  370. pexR, book := createReactor(&ReactorConfig{})
  371. book.AddPrivateIDs([]string{string(peer.NodeInfo().ID())})
  372. defer teardownReactor(book)
  373. // we have to send a request to receive responses
  374. pexR.RequestAddrs(peer)
  375. size := book.Size()
  376. addrs := []*p2p.NetAddress{peer.SocketAddr()}
  377. msg := cdc.MustMarshalBinaryBare(&pexAddrsMessage{Addrs: addrs})
  378. pexR.Receive(PexChannel, peer, msg)
  379. assert.Equal(t, size, book.Size())
  380. pexR.AddPeer(peer)
  381. assert.Equal(t, size, book.Size())
  382. }
  383. func TestPEXReactorDialPeer(t *testing.T) {
  384. pexR, book := createReactor(&ReactorConfig{})
  385. defer teardownReactor(book)
  386. sw := createSwitchAndAddReactors(pexR)
  387. sw.SetAddrBook(book)
  388. peer := mock.NewPeer(nil)
  389. addr := peer.SocketAddr()
  390. assert.Equal(t, 0, pexR.AttemptsToDial(addr))
  391. // 1st unsuccessful attempt
  392. pexR.dialPeer(addr)
  393. assert.Equal(t, 1, pexR.AttemptsToDial(addr))
  394. // 2nd unsuccessful attempt
  395. pexR.dialPeer(addr)
  396. // must be skipped because it is too early
  397. assert.Equal(t, 1, pexR.AttemptsToDial(addr))
  398. if !testing.Short() {
  399. time.Sleep(3 * time.Second)
  400. // 3rd attempt
  401. pexR.dialPeer(addr)
  402. assert.Equal(t, 2, pexR.AttemptsToDial(addr))
  403. }
  404. }
  405. func assertPeersWithTimeout(
  406. t *testing.T,
  407. switches []*p2p.Switch,
  408. checkPeriod, timeout time.Duration,
  409. nPeers int,
  410. ) {
  411. var (
  412. ticker = time.NewTicker(checkPeriod)
  413. remaining = timeout
  414. )
  415. for {
  416. select {
  417. case <-ticker.C:
  418. // check peers are connected
  419. allGood := true
  420. for _, s := range switches {
  421. outbound, inbound, _ := s.NumPeers()
  422. if outbound+inbound < nPeers {
  423. allGood = false
  424. break
  425. }
  426. }
  427. remaining -= checkPeriod
  428. if remaining < 0 {
  429. remaining = 0
  430. }
  431. if allGood {
  432. return
  433. }
  434. case <-time.After(remaining):
  435. numPeersStr := ""
  436. for i, s := range switches {
  437. outbound, inbound, _ := s.NumPeers()
  438. numPeersStr += fmt.Sprintf("%d => {outbound: %d, inbound: %d}, ", i, outbound, inbound)
  439. }
  440. t.Errorf(
  441. "expected all switches to be connected to at least %d peer(s) (switches: %s)",
  442. nPeers, numPeersStr,
  443. )
  444. return
  445. }
  446. }
  447. }
  448. // Creates a peer with the provided config
  449. func testCreatePeerWithConfig(dir string, id int, config *ReactorConfig) *p2p.Switch {
  450. peer := p2p.MakeSwitch(
  451. cfg,
  452. id,
  453. "127.0.0.1",
  454. "123.123.123",
  455. func(i int, sw *p2p.Switch) *p2p.Switch {
  456. book := NewAddrBook(filepath.Join(dir, fmt.Sprintf("addrbook%d.json", id)), false)
  457. book.SetLogger(log.TestingLogger())
  458. sw.SetAddrBook(book)
  459. sw.SetLogger(log.TestingLogger())
  460. r := NewReactor(
  461. book,
  462. config,
  463. )
  464. r.SetLogger(log.TestingLogger())
  465. sw.AddReactor("pex", r)
  466. return sw
  467. },
  468. )
  469. return peer
  470. }
  471. // Creates a peer with the default config
  472. func testCreateDefaultPeer(dir string, id int) *p2p.Switch {
  473. return testCreatePeerWithConfig(dir, id, &ReactorConfig{})
  474. }
  475. // Creates a seed which knows about the provided addresses / source address pairs.
  476. // Starting and stopping the seed is left to the caller
  477. func testCreateSeed(dir string, id int, knownAddrs, srcAddrs []*p2p.NetAddress) *p2p.Switch {
  478. seed := p2p.MakeSwitch(
  479. cfg,
  480. id,
  481. "127.0.0.1",
  482. "123.123.123",
  483. func(i int, sw *p2p.Switch) *p2p.Switch {
  484. book := NewAddrBook(filepath.Join(dir, "addrbookSeed.json"), false)
  485. book.SetLogger(log.TestingLogger())
  486. for j := 0; j < len(knownAddrs); j++ {
  487. book.AddAddress(knownAddrs[j], srcAddrs[j])
  488. book.MarkGood(knownAddrs[j].ID)
  489. }
  490. sw.SetAddrBook(book)
  491. sw.SetLogger(log.TestingLogger())
  492. r := NewReactor(book, &ReactorConfig{})
  493. r.SetLogger(log.TestingLogger())
  494. sw.AddReactor("pex", r)
  495. return sw
  496. },
  497. )
  498. return seed
  499. }
  500. // Creates a peer which knows about the provided seed.
  501. // Starting and stopping the peer is left to the caller
  502. func testCreatePeerWithSeed(dir string, id int, seed *p2p.Switch) *p2p.Switch {
  503. conf := &ReactorConfig{
  504. Seeds: []string{seed.NetAddress().String()},
  505. }
  506. return testCreatePeerWithConfig(dir, id, conf)
  507. }
  508. func createReactor(conf *ReactorConfig) (r *Reactor, book AddrBook) {
  509. // directory to store address book
  510. dir, err := ioutil.TempDir("", "pex_reactor")
  511. if err != nil {
  512. panic(err)
  513. }
  514. book = NewAddrBook(filepath.Join(dir, "addrbook.json"), true)
  515. book.SetLogger(log.TestingLogger())
  516. r = NewReactor(book, conf)
  517. r.SetLogger(log.TestingLogger())
  518. return
  519. }
  520. func teardownReactor(book AddrBook) {
  521. // FIXME Shouldn't rely on .(*addrBook) assertion
  522. err := os.RemoveAll(filepath.Dir(book.(*addrBook).FilePath()))
  523. if err != nil {
  524. panic(err)
  525. }
  526. }
  527. func createSwitchAndAddReactors(reactors ...p2p.Reactor) *p2p.Switch {
  528. sw := p2p.MakeSwitch(cfg, 0, "127.0.0.1", "123.123.123", func(i int, sw *p2p.Switch) *p2p.Switch { return sw })
  529. sw.SetLogger(log.TestingLogger())
  530. for _, r := range reactors {
  531. sw.AddReactor(r.String(), r)
  532. r.SetSwitch(sw)
  533. }
  534. return sw
  535. }