Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core-p2p): ignore maxSameSubnetPeers in seed mode #2547

Merged
merged 3 commits into from May 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core-p2p/src/defaults.ts
Expand Up @@ -28,7 +28,7 @@ export const defaults = {
/**
* The maximum authorized number of peers sharing same ip /24 subnet
*/
maxSameSubnetPeers: 5,
maxSameSubnetPeers: process.env.CORE_P2P_MAX_PEERS_SAME_SUBNET || 5,
/**
* The list of IPs we allow to be added to the peer list.
*/
Expand Down
7 changes: 5 additions & 2 deletions packages/core-p2p/src/peer-processors.ts
Expand Up @@ -79,7 +79,10 @@ export class PeerProcessor implements P2P.IPeerProcessor {
return false;
}

if (this.storage.getSameSubnetPeers(peer.ip).length >= app.resolveOptions("p2p").maxSameSubnetPeers) {
if (
this.storage.getSameSubnetPeers(peer.ip).length >= app.resolveOptions("p2p").maxSameSubnetPeers &&
!options.seed
) {
this.logger.warn(
`Rejected ${peer.ip} because we are already at the ${
app.resolveOptions("p2p").maxSameSubnetPeers
Expand Down Expand Up @@ -135,7 +138,7 @@ export class PeerProcessor implements P2P.IPeerProcessor {
this.storage.forgetSuspendedPeer(suspension);

const connection: SCClientSocket = this.connector.connection(peer);
if (connection.getState() !== connection.OPEN) {
if (connection && connection.getState() !== connection.OPEN) {
// if after suspension peer socket is not open, we just "destroy" the socket connection
// and we don't try to "accept" the peer again, so it will be definitively removed as there will be no reference to it
connection.destroy();
Expand Down