lisk-interchain
Advanced tools
Comparing version 1.0.1 to 1.1.0
30
index.js
@@ -5,2 +5,3 @@ const shuffle = require('lodash.shuffle'); | ||
let defaultSelectForSendFunction; | ||
let defaultSelectForConnectionFunction; | ||
@@ -14,2 +15,21 @@ function getAffectedModule(remoteActionName) { | ||
function interchainSelectForConnection(input) { | ||
if (!defaultSelectForConnectionFunction) { | ||
return []; | ||
} | ||
let knownPeers = [...input.newPeers, ...input.triedPeers]; | ||
let {nodeInfo} = input; | ||
let nodeModules = Object.keys(nodeInfo.modules || {}).sort().join(','); | ||
let matchingPeer = knownPeers.find((peerInfo) => { | ||
let peerModules = Object.keys(peerInfo.modules || {}).sort().join(','); | ||
return peerModules === nodeModules; | ||
}); | ||
let selectedPeers = defaultSelectForConnectionFunction(input); | ||
if (selectedPeers.length > 1) { | ||
selectedPeers[0] = matchingPeer; | ||
} | ||
return selectedPeers; | ||
} | ||
function interchainSelectForRequest(input) { | ||
@@ -30,2 +50,6 @@ let {nodeInfo, peers, peerLimit, requestPacket} = input; | ||
if (!defaultSelectForRequestFunction) { | ||
return []; | ||
} | ||
return defaultSelectForRequestFunction(input); | ||
@@ -48,2 +72,6 @@ } | ||
if (!defaultSelectForSendFunction) { | ||
return []; | ||
} | ||
return defaultSelectForSendFunction(input); | ||
@@ -75,5 +103,7 @@ } | ||
defaultSelectForSendFunction = this.network.p2p._peerPool._peerSelectForSend; | ||
defaultSelectForConnectionFunction = this.network.p2p._peerPool._peerSelectForConnection; | ||
this.network.p2p._peerPool._peerSelectForRequest = interchainSelectForRequest; | ||
this.network.p2p._peerPool._peerSelectForSend = interchainSelectForSend; | ||
this.network.p2p._peerPool._peerSelectForConnection = interchainSelectForConnection; | ||
}; | ||
@@ -80,0 +110,0 @@ } |
{ | ||
"name": "lisk-interchain", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Custom peer selector plugin for Lisk interchain.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4118
89