lisk-interchain
Advanced tools
Comparing version 1.0.0 to 1.0.1
49
index.js
@@ -0,1 +1,3 @@ | ||
const shuffle = require('lodash.shuffle'); | ||
let defaultSelectForRequestFunction; | ||
@@ -11,7 +13,2 @@ let defaultSelectForSendFunction; | ||
function interchainSelectForConnection(input) { | ||
let {nodeInfo, peers} = input; | ||
return peers; | ||
} | ||
function interchainSelectForRequest(input) { | ||
@@ -23,5 +20,9 @@ let {nodeInfo, peers, peerLimit, requestPacket} = input; | ||
let matchingPeers = peers.filter((peerInfo) => { | ||
return peerInfo. | ||
return peerInfo.modules && peerInfo.modules[procedureTargetModule]; | ||
}); | ||
return; // TODO 2 | ||
if (!matchingPeers.length) { | ||
return []; | ||
} | ||
let chosenPeer = matchingPeers[Math.floor(Math.random() * matchingPeers.length)]; | ||
return [chosenPeer]; | ||
} | ||
@@ -35,4 +36,11 @@ | ||
if (messagePacket) { | ||
return; // TODO 2 | ||
let eventSourceModule = getAffectedModule(messagePacket.event); | ||
if (eventSourceModule) { | ||
let matchingPeers = peers.filter((peerInfo) => { | ||
return peerInfo.modules && peerInfo.modules[eventSourceModule]; | ||
}); | ||
if (!matchingPeers.length) { | ||
return []; | ||
} | ||
return shuffle(matchingPeers).slice(0, input.peerLimit); | ||
} | ||
@@ -43,14 +51,31 @@ | ||
module.exports = function (app) { | ||
function attachInterchain(app) { | ||
let realLoadFunction = app.getModule('network').prototype.load; | ||
app.getModule('network').prototype.load = async function (channel) { | ||
await realLoadFunction.call(this, channel); | ||
let availableModules = Object.keys(app.getModules() || {}).reduce((modulesMap, moduleName) => { | ||
return { | ||
...modulesMap, | ||
[moduleName]: {} | ||
}; | ||
}, {}); | ||
let realApplyNodeInfoFunction = this.network.p2p.applyNodeInfo; | ||
this.network.p2p.applyNodeInfo = function (nodeInfo) { | ||
let extendedNodeInfo = { | ||
...nodeInfo, | ||
modules: availableModules | ||
}; | ||
realApplyNodeInfoFunction.call(this, extendedNodeInfo); | ||
}; | ||
defaultSelectForRequestFunction = this.network.p2p._peerPool._peerSelectForRequest; | ||
defaultSelectForSendFunction = this.network.p2p._peerPool._peerSelectForSend; | ||
this.network.p2p._peerPool._peerSelectForConnection = interchainSelectForConnection; | ||
this.network.p2p._peerPool._peerSelectForRequest = interchainSelectForRequest; | ||
this.network.p2p._peerPool._peerSelectForSend = interchainSelectForSend; | ||
}; | ||
}; | ||
} | ||
module.exports = attachInterchain; |
{ | ||
"name": "lisk-interchain", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Custom peer selector plugin for Lisk interchain.", | ||
@@ -24,3 +24,6 @@ "main": "index.js", | ||
}, | ||
"homepage": "https://github.com/jondubois/lisk-interchain#readme" | ||
"homepage": "https://github.com/jondubois/lisk-interchain#readme", | ||
"dependencies": { | ||
"lodash.shuffle": "^4.2.0" | ||
} | ||
} |
# lisk-interchain | ||
Custom peer selector plugin for Lisk interchain. | ||
Custom peer matching plugin for Lisk interchain. |
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
3158
63
1
+ Addedlodash.shuffle@^4.2.0
+ Addedlodash.shuffle@4.2.0(transitive)