Skip to content

Commit

Permalink
Merge pull request #4767 from LiskHQ/4638-peerserver-implementation
Browse files Browse the repository at this point in the history
P2P add PeerServer class - Closes  #4638 & #4789
  • Loading branch information
shuse2 committed Feb 7, 2020
2 parents 7d1d8bb + 822328b commit 5997714
Show file tree
Hide file tree
Showing 27 changed files with 952 additions and 372 deletions.
1 change: 1 addition & 0 deletions elements/lisk-p2p/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const DEFAULT_POPULATOR_INTERVAL = 10000;
export const DEFAULT_FALLBACK_SEED_PEER_DISCOVERY_INTERVAL = 30000;
export const DEFAULT_SEND_PEER_LIMIT = 16;
// Max rate of WebSocket messages per second per peer.
export const DEFAULT_CONTROL_MESSAGE_LIMIT = 10;
export const DEFAULT_WS_MAX_MESSAGE_RATE = 100;
export const DEFAULT_WS_MAX_MESSAGE_RATE_PENALTY = 10;
export const DEFAULT_RATE_CALCULATION_INTERVAL = 1000;
Expand Down
28 changes: 27 additions & 1 deletion elements/lisk-p2p/src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { P2PPeerInfo } from './p2p_types';
import { P2PPeerInfo } from './types';

/*
* Copyright © 2019 Lisk Foundation
Expand Down Expand Up @@ -34,6 +34,16 @@ export class PeerInboundHandshakeError extends Error {
}
}

export class PeerInboundDuplicateConnectionError extends Error {
public peerId: string;

public constructor(message: string, peerId: string) {
super(message);
this.name = 'PeerInboundDuplicateConnectionError';
this.peerId = peerId;
}
}

export class RPCResponseError extends Error {
public peerId: string;

Expand Down Expand Up @@ -131,3 +141,19 @@ export class InvalidProtocolMessageError extends Error {
this.name = 'InvalidProtocolMessageError';
}
}

export class InvalidPayloadError extends Error {
public parsedMessage: object;
public constructor(message: string, parsedMessage: object) {
super(message);
this.name = 'InvalidPayloadError';
this.parsedMessage = parsedMessage;
}
}

export class InvalidDisconnectEventError extends Error {
public constructor(message: string) {
super(message);
this.name = 'InvalidDisconnectEventError';
}
}
1 change: 1 addition & 0 deletions elements/lisk-p2p/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
// P2P general
export const EVENT_NEW_INBOUND_PEER = 'newInboundPeer';
export const EVENT_NEW_INBOUND_PEER_CONNECTION = 'newInboundPeerConnection';
export const EVENT_FAILED_TO_ADD_INBOUND_PEER = 'failedToAddInboundPeer';
export const EVENT_NETWORK_READY = 'networkReady';

Expand Down
2 changes: 1 addition & 1 deletion elements/lisk-p2p/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ import * as errors from './errors';
import * as events from './events';
import { P2P } from './p2p';
import * as p2p_request from './p2p_request';
import * as p2p_types from './p2p_types';
import * as p2p_types from './types';

export { constants, errors, events, p2p_request, p2p_types, P2P };

0 comments on commit 5997714

Please sign in to comment.