Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4023 from LiskHQ/3976_netgroup_inbound_eviction
Browse files Browse the repository at this point in the history
Netgroup inbound peer eviction and secret generation - Closes #3976
  • Loading branch information
shuse2 committed Aug 6, 2019
2 parents 841dbf0 + 3c47ec9 commit 273388e
Show file tree
Hide file tree
Showing 26 changed files with 189 additions and 176 deletions.
2 changes: 1 addition & 1 deletion commander/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"dependencies": {
"@liskhq/lisk-api-client": "2.0.2",
"@liskhq/lisk-constants": "1.2.2",
"@liskhq/lisk-cryptography": "2.2.0",
"@liskhq/lisk-cryptography": "2.3.0-alpha.0",
"@liskhq/lisk-passphrase": "2.0.2",
"@liskhq/lisk-transactions": "2.3.0",
"@oclif/command": "1.5.6",
Expand Down
2 changes: 1 addition & 1 deletion elements/lisk-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"dependencies": {
"@liskhq/lisk-api-client": "2.0.2",
"@liskhq/lisk-constants": "1.2.2",
"@liskhq/lisk-cryptography": "2.2.0",
"@liskhq/lisk-cryptography": "2.3.0-alpha.0",
"@liskhq/lisk-passphrase": "2.0.2",
"@liskhq/lisk-transactions": "2.3.0",
"@types/node": "10.12.21"
Expand Down
9 changes: 3 additions & 6 deletions elements/lisk-cryptography/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion elements/lisk-cryptography/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@liskhq/lisk-cryptography",
"version": "2.2.0",
"version": "2.3.0-alpha.0",
"description": "General cryptographic functions for use with Lisk-related software",
"author": "Lisk Foundation <admin@lisk.io>, lightcurve GmbH <admin@lightcurve.io>",
"license": "Apache-2.0",
Expand Down
1 change: 1 addition & 0 deletions elements/lisk-cryptography/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ export * from './encrypt';
export * from './hash';
export * from './keys';
export * from './sign';
export { getRandomBytes } from './nacl';

export { constants };
2 changes: 1 addition & 1 deletion elements/lisk-elements/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"dependencies": {
"@liskhq/lisk-api-client": "2.0.2",
"@liskhq/lisk-constants": "1.2.2",
"@liskhq/lisk-cryptography": "2.2.0",
"@liskhq/lisk-cryptography": "2.3.0-alpha.0",
"@liskhq/lisk-passphrase": "2.0.2",
"@liskhq/lisk-transactions": "2.3.0",
"@types/node": "10.12.21"
Expand Down
116 changes: 8 additions & 108 deletions elements/lisk-p2p/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion elements/lisk-p2p/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"enableLocalIPs": "sudo ./scripts/enableTestLocalIPs.sh 10 19"
},
"dependencies": {
"@liskhq/lisk-cryptography": "2.1.1",
"@liskhq/lisk-cryptography": "2.3.0-alpha.0",
"lodash.shuffle": "4.2.0",
"semver": "5.6.0",
"socketcluster-client": "14.3.0",
Expand Down
13 changes: 11 additions & 2 deletions elements/lisk-p2p/src/p2p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Removal or modification of this copyright notice is prohibited.
*
*/

import { getRandomBytes } from '@liskhq/lisk-cryptography';
import { EventEmitter } from 'events';
import * as http from 'http';
// tslint:disable-next-line no-require-imports
Expand Down Expand Up @@ -131,11 +131,16 @@ const BASE_10_RADIX = 10;
export const DEFAULT_MAX_OUTBOUND_CONNECTIONS = 20;
export const DEFAULT_MAX_INBOUND_CONNECTIONS = 100;
export const DEFAULT_OUTBOUND_SHUFFLE_INTERVAL = 300000;
export const DEFAULT_PEER_PROTECTION_FOR_NETGROUP = 0.034;
export const DEFAULT_PEER_PROTECTION_FOR_LATENCY = 0.068;
export const DEFAULT_PEER_PROTECTION_FOR_USEFULNESS = 0.068;
export const DEFAULT_PEER_PROTECTION_FOR_LONGEVITY = 0.5;
export const DEFAULT_MIN_PEER_DISCOVERY_THRESHOLD = 100;
export const DEFAULT_MAX_PEER_DISCOVERY_RESPONSE_SIZE = 1000;
const SECRET_BYTE_LENGTH = 4;
export const DEFAULT_RANDOM_SECRET = getRandomBytes(
SECRET_BYTE_LENGTH,
).readUInt32BE(0);

const selectRandomPeerSample = (
peerList: ReadonlyArray<P2PPeerInfo>,
Expand All @@ -152,7 +157,6 @@ export class P2P extends EventEmitter {
private readonly _bannedPeers: Set<string>;
private readonly _populatorInterval: number;
private _populatorIntervalId: NodeJS.Timer | undefined;

private _nodeInfo: P2PNodeInfo;
private readonly _peerPool: PeerPool;
private readonly _scServer: SCServerUpdated;
Expand Down Expand Up @@ -420,6 +424,10 @@ export class P2P extends EventEmitter {
outboundShuffleInterval: config.outboundShuffleInterval
? config.outboundShuffleInterval
: DEFAULT_OUTBOUND_SHUFFLE_INTERVAL,
netgroupProtectionRatio:
typeof config.netgroupProtectionRatio === 'number'
? config.netgroupProtectionRatio
: DEFAULT_PEER_PROTECTION_FOR_NETGROUP,
latencyProtectionRatio:
typeof config.latencyProtectionRatio === 'number'
? config.latencyProtectionRatio
Expand All @@ -444,6 +452,7 @@ export class P2P extends EventEmitter {
typeof config.rateCalculationInterval === 'number'
? config.rateCalculationInterval
: DEFAULT_RATE_CALCULATION_INTERVAL,
secret: config.secret ? config.secret : DEFAULT_RANDOM_SECRET,
});

this._bindHandlersToPeerPool(this._peerPool);
Expand Down
2 changes: 2 additions & 0 deletions elements/lisk-p2p/src/p2p_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,14 @@ export interface P2PConfig {
readonly latencyProtectionRatio?: number;
readonly productivityProtectionRatio?: number;
readonly longevityProtectionRatio?: number;
readonly netgroupProtectionRatio?: number;
readonly hostIp?: string;
readonly wsMaxMessageRate?: number;
readonly wsMaxMessageRatePenalty?: number;
readonly rateCalculationInterval?: number;
readonly minimumPeerDiscoveryThreshold?: number;
readonly maximumPeerDiscoveryResponseSize?: number;
readonly secret?: number;
}

// Network info exposed by the P2P library.
Expand Down
Loading

0 comments on commit 273388e

Please sign in to comment.