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.

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