mirror of
https://github.com/fluencelabs/dashboard
synced 2024-12-04 15:20:21 +00:00
Send a separate particle to each node (#25)
This commit is contained in:
parent
2552c842b1
commit
566f26363d
@ -4,13 +4,13 @@ alias PeerInfoCb: PeerId, Info, []Service, []Blueprint, []Module -> ()
|
||||
alias ServiceInterfaceCb: PeerId, string, Interface -> ()
|
||||
|
||||
func collectServiceInterfaces(peer: PeerId, services: []Service, collectServiceInterface: ServiceInterfaceCb):
|
||||
for srv <- services par:
|
||||
for srv <- services:
|
||||
on peer:
|
||||
iface <- Srv.get_interface(srv.id)
|
||||
collectServiceInterface(peer, srv.id, iface)
|
||||
|
||||
func askAllAndSend(peer: PeerId, collectPeerInfo: PeerInfoCb, collectServiceInterface: ServiceInterfaceCb):
|
||||
on peer:
|
||||
on peer via HOST_PEER_ID:
|
||||
ident <- Peer.identify()
|
||||
blueprints <- Dist.list_blueprints()
|
||||
modules <- Dist.list_modules()
|
||||
|
48455
package-lock.json
generated
48455
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -31,7 +31,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/fluencelabs/fluence-admin#readme",
|
||||
"dependencies": {
|
||||
"@fluencelabs/fluence": "0.11.0",
|
||||
"@fluencelabs/fluence": "0.13.0",
|
||||
"@fluencelabs/fluence-network-environment": "1.0.10",
|
||||
"css-spinners": "^1.0.1",
|
||||
"tachyons": "^4.12.0",
|
||||
@ -40,8 +40,8 @@
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.11.6",
|
||||
"@babel/preset-env": "^7.11.5",
|
||||
"@fluencelabs/aqua": "^0.3.0-222",
|
||||
"@fluencelabs/aqua-lib": "^0.1.14",
|
||||
"@fluencelabs/aqua": "0.3.1-231",
|
||||
"@fluencelabs/aqua-lib": "0.1.14",
|
||||
"@types/yup": "^0.29.11",
|
||||
"babel-loader": "^8.1.0",
|
||||
"chokidar-cli": "^2.1.0",
|
||||
|
705
src/_aqua/app.js
705
src/_aqua/app.js
@ -1,12 +1,12 @@
|
||||
/**
|
||||
*
|
||||
* This file is auto-generated. Do not edit manually: changes may be erased.
|
||||
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
|
||||
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
|
||||
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
|
||||
* Aqua version: 0.3.0-222
|
||||
* Aqua version: 0.3.1-231
|
||||
*
|
||||
*/
|
||||
import { FluencePeer } from '@fluencelabs/fluence';
|
||||
import { Fluence, FluencePeer } from '@fluencelabs/fluence';
|
||||
import {
|
||||
ResultCodes,
|
||||
RequestFlow,
|
||||
@ -14,36 +14,42 @@ import {
|
||||
CallParams,
|
||||
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v1.js';
|
||||
|
||||
|
||||
function missingFields(obj, fields) {
|
||||
return fields.filter(f => !(f in obj))
|
||||
}
|
||||
|
||||
// Services
|
||||
|
||||
|
||||
// Functions
|
||||
|
||||
export function collectServiceInterfaces(...args) {
|
||||
let peer;
|
||||
let peer_;
|
||||
let services;
|
||||
let collectServiceInterface;
|
||||
let config;
|
||||
if (args[0] instanceof FluencePeer) {
|
||||
peer = args[0];
|
||||
peer_ = args[1];
|
||||
services = args[2];
|
||||
collectServiceInterface = args[3];
|
||||
config = args[4];
|
||||
} else {
|
||||
peer = FluencePeer.default;
|
||||
peer_ = args[0];
|
||||
services = args[1];
|
||||
collectServiceInterface = args[2];
|
||||
config = args[3];
|
||||
}
|
||||
|
||||
let request;
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
const r = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript(
|
||||
`
|
||||
export function collectServiceInterfaces(...args) {
|
||||
let peer;
|
||||
let peer_;
|
||||
let services;
|
||||
let collectServiceInterface;
|
||||
let config;
|
||||
if (FluencePeer.isInstance(args[0])) {
|
||||
peer = args[0];
|
||||
peer_ = args[1];
|
||||
services = args[2];
|
||||
collectServiceInterface = args[3];
|
||||
config = args[4];
|
||||
} else {
|
||||
peer = Fluence.getPeer();
|
||||
peer_ = args[0];
|
||||
services = args[1];
|
||||
collectServiceInterface = args[2];
|
||||
config = args[3];
|
||||
}
|
||||
|
||||
let request;
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
const r = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
@ -54,7 +60,7 @@ export function collectServiceInterfaces(...args) {
|
||||
(call %init_peer_id% ("getDataSrv" "services") [] services)
|
||||
)
|
||||
(fold services srv
|
||||
(par
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(xor
|
||||
@ -79,36 +85,33 @@ export function collectServiceInterfaces(...args) {
|
||||
)
|
||||
|
||||
`,
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return peer.connectionInfo.connectedRelay;
|
||||
});
|
||||
h.on('getDataSrv', 'peer', () => {
|
||||
return peer_;
|
||||
});
|
||||
h.on('getDataSrv', 'services', () => {
|
||||
return services;
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return peer.getStatus().relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'peer', () => {return peer_;});
|
||||
h.on('getDataSrv', 'services', () => {return services;});
|
||||
|
||||
h.use((req, resp, next) => {
|
||||
if (req.serviceId === 'callbackSrv' && req.fnName === 'collectServiceInterface') {
|
||||
const callParams = {
|
||||
...req.particleContext,
|
||||
tetraplets: {
|
||||
arg0: req.tetraplets[0],
|
||||
arg1: req.tetraplets[1],
|
||||
arg2: req.tetraplets[2],
|
||||
},
|
||||
};
|
||||
resp.retCode = ResultCodes.success;
|
||||
collectServiceInterface(req.args[0], req.args[1], req.args[2], callParams);
|
||||
resp.result = {};
|
||||
}
|
||||
next();
|
||||
});
|
||||
h.use((req, resp, next) => {
|
||||
if(req.serviceId === 'callbackSrv' && req.fnName === 'collectServiceInterface') {
|
||||
|
||||
const callParams = {
|
||||
...req.particleContext,
|
||||
tetraplets: {
|
||||
arg0: req.tetraplets[0],arg1: req.tetraplets[1],arg2: req.tetraplets[2]
|
||||
},
|
||||
};
|
||||
resp.retCode = ResultCodes.success;
|
||||
collectServiceInterface(req.args[0], req.args[1], req.args[2], callParams); resp.result = {}
|
||||
|
||||
h.onEvent('callbackSrv', 'response', (args) => {});
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
h.onEvent('callbackSrv', 'response', (args) => {
|
||||
|
||||
});
|
||||
|
||||
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||
const [err] = args;
|
||||
@ -118,42 +121,44 @@ export function collectServiceInterfaces(...args) {
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(() => {
|
||||
reject('Request timed out for collectServiceInterfaces');
|
||||
});
|
||||
if (config && config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
})
|
||||
if(config && config.ttl) {
|
||||
r.withTTL(config.ttl)
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
peer.internals.initiateFlow(request);
|
||||
return Promise.race([promise, Promise.resolve()]);
|
||||
}
|
||||
|
||||
|
||||
export function askAllAndSend(...args) {
|
||||
let peer;
|
||||
let peer_;
|
||||
let collectPeerInfo;
|
||||
let collectServiceInterface;
|
||||
let config;
|
||||
if (args[0] instanceof FluencePeer) {
|
||||
peer = args[0];
|
||||
peer_ = args[1];
|
||||
collectPeerInfo = args[2];
|
||||
collectServiceInterface = args[3];
|
||||
config = args[4];
|
||||
} else {
|
||||
peer = FluencePeer.default;
|
||||
peer_ = args[0];
|
||||
collectPeerInfo = args[1];
|
||||
collectServiceInterface = args[2];
|
||||
config = args[3];
|
||||
}
|
||||
|
||||
let request;
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
const r = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript(
|
||||
`
|
||||
export function askAllAndSend(...args) {
|
||||
let peer;
|
||||
let peer_;
|
||||
let collectPeerInfo;
|
||||
let collectServiceInterface;
|
||||
let config;
|
||||
if (FluencePeer.isInstance(args[0])) {
|
||||
peer = args[0];
|
||||
peer_ = args[1];
|
||||
collectPeerInfo = args[2];
|
||||
collectServiceInterface = args[3];
|
||||
config = args[4];
|
||||
} else {
|
||||
peer = Fluence.getPeer();
|
||||
peer_ = args[0];
|
||||
collectPeerInfo = args[1];
|
||||
collectServiceInterface = args[2];
|
||||
config = args[3];
|
||||
}
|
||||
|
||||
let request;
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
const r = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
@ -188,83 +193,86 @@ export function askAllAndSend(...args) {
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(fold services srv
|
||||
(par
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(xor
|
||||
(seq
|
||||
(call peer ("srv" "get_interface") [srv.$.id!] iface)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "collectServiceInterface") [peer srv.$.id! iface])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
(seq
|
||||
(call peer ("srv" "get_interface") [srv.$.id!] iface)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "collectServiceInterface") [peer srv.$.id! iface])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(next srv)
|
||||
)
|
||||
(next srv)
|
||||
)
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5])
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5])
|
||||
)
|
||||
)
|
||||
|
||||
`,
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return peer.connectionInfo.connectedRelay;
|
||||
});
|
||||
h.on('getDataSrv', 'peer', () => {
|
||||
return peer_;
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return peer.getStatus().relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'peer', () => {return peer_;});
|
||||
|
||||
h.use((req, resp, next) => {
|
||||
if (req.serviceId === 'callbackSrv' && req.fnName === 'collectPeerInfo') {
|
||||
const callParams = {
|
||||
...req.particleContext,
|
||||
tetraplets: {
|
||||
arg0: req.tetraplets[0],
|
||||
arg1: req.tetraplets[1],
|
||||
arg2: req.tetraplets[2],
|
||||
arg3: req.tetraplets[3],
|
||||
arg4: req.tetraplets[4],
|
||||
},
|
||||
};
|
||||
resp.retCode = ResultCodes.success;
|
||||
collectPeerInfo(req.args[0], req.args[1], req.args[2], req.args[3], req.args[4], callParams);
|
||||
resp.result = {};
|
||||
}
|
||||
next();
|
||||
});
|
||||
h.use((req, resp, next) => {
|
||||
if(req.serviceId === 'callbackSrv' && req.fnName === 'collectPeerInfo') {
|
||||
|
||||
const callParams = {
|
||||
...req.particleContext,
|
||||
tetraplets: {
|
||||
arg0: req.tetraplets[0],arg1: req.tetraplets[1],arg2: req.tetraplets[2],arg3: req.tetraplets[3],arg4: req.tetraplets[4]
|
||||
},
|
||||
};
|
||||
resp.retCode = ResultCodes.success;
|
||||
collectPeerInfo(req.args[0], req.args[1], req.args[2], req.args[3], req.args[4], callParams); resp.result = {}
|
||||
|
||||
h.use((req, resp, next) => {
|
||||
if (req.serviceId === 'callbackSrv' && req.fnName === 'collectServiceInterface') {
|
||||
const callParams = {
|
||||
...req.particleContext,
|
||||
tetraplets: {
|
||||
arg0: req.tetraplets[0],
|
||||
arg1: req.tetraplets[1],
|
||||
arg2: req.tetraplets[2],
|
||||
},
|
||||
};
|
||||
resp.retCode = ResultCodes.success;
|
||||
collectServiceInterface(req.args[0], req.args[1], req.args[2], callParams);
|
||||
resp.result = {};
|
||||
}
|
||||
next();
|
||||
});
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
|
||||
h.onEvent('callbackSrv', 'response', (args) => {});
|
||||
h.use((req, resp, next) => {
|
||||
if(req.serviceId === 'callbackSrv' && req.fnName === 'collectServiceInterface') {
|
||||
|
||||
const callParams = {
|
||||
...req.particleContext,
|
||||
tetraplets: {
|
||||
arg0: req.tetraplets[0],arg1: req.tetraplets[1],arg2: req.tetraplets[2]
|
||||
},
|
||||
};
|
||||
resp.retCode = ResultCodes.success;
|
||||
collectServiceInterface(req.args[0], req.args[1], req.args[2], callParams); resp.result = {}
|
||||
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
h.onEvent('callbackSrv', 'response', (args) => {
|
||||
|
||||
});
|
||||
|
||||
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||
const [err] = args;
|
||||
@ -274,45 +282,47 @@ export function askAllAndSend(...args) {
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(() => {
|
||||
reject('Request timed out for askAllAndSend');
|
||||
});
|
||||
if (config && config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
})
|
||||
if(config && config.ttl) {
|
||||
r.withTTL(config.ttl)
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
peer.internals.initiateFlow(request);
|
||||
return Promise.race([promise, Promise.resolve()]);
|
||||
}
|
||||
|
||||
|
||||
export function findAndAskNeighboursSchema(...args) {
|
||||
let peer;
|
||||
let relayPeerId;
|
||||
let clientId;
|
||||
let collectPeerInfo;
|
||||
let collectServiceInterface;
|
||||
let config;
|
||||
if (args[0] instanceof FluencePeer) {
|
||||
peer = args[0];
|
||||
relayPeerId = args[1];
|
||||
clientId = args[2];
|
||||
collectPeerInfo = args[3];
|
||||
collectServiceInterface = args[4];
|
||||
config = args[5];
|
||||
} else {
|
||||
peer = FluencePeer.default;
|
||||
relayPeerId = args[0];
|
||||
clientId = args[1];
|
||||
collectPeerInfo = args[2];
|
||||
collectServiceInterface = args[3];
|
||||
config = args[4];
|
||||
}
|
||||
|
||||
let request;
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
const r = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript(
|
||||
`
|
||||
export function findAndAskNeighboursSchema(...args) {
|
||||
let peer;
|
||||
let relayPeerId;
|
||||
let clientId;
|
||||
let collectPeerInfo;
|
||||
let collectServiceInterface;
|
||||
let config;
|
||||
if (FluencePeer.isInstance(args[0])) {
|
||||
peer = args[0];
|
||||
relayPeerId = args[1];
|
||||
clientId = args[2];
|
||||
collectPeerInfo = args[3];
|
||||
collectServiceInterface = args[4];
|
||||
config = args[5];
|
||||
} else {
|
||||
peer = Fluence.getPeer();
|
||||
relayPeerId = args[0];
|
||||
clientId = args[1];
|
||||
collectPeerInfo = args[2];
|
||||
collectServiceInterface = args[3];
|
||||
config = args[4];
|
||||
}
|
||||
|
||||
let request;
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
const r = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
@ -335,58 +345,61 @@ export function findAndAskNeighboursSchema(...args) {
|
||||
(call n ("kad" "neighborhood") [clientId [] []] neighbors2)
|
||||
(fold neighbors2 n2
|
||||
(par
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call n2 ("peer" "identify") [] ident)
|
||||
(call n2 ("dist" "list_blueprints") [] blueprints)
|
||||
(seq
|
||||
(call n2 ("peer" "identify") [] ident)
|
||||
(call n2 ("dist" "list_blueprints") [] blueprints)
|
||||
)
|
||||
(call n2 ("dist" "list_modules") [] modules)
|
||||
)
|
||||
(call n2 ("dist" "list_modules") [] modules)
|
||||
(call n2 ("srv" "list") [] services)
|
||||
)
|
||||
(call n2 ("srv" "list") [] services)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "collectPeerInfo") [n2 ident services blueprints modules])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(fold services srv
|
||||
(par
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(call n2 ("srv" "get_interface") [srv.$.id!] iface)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "collectServiceInterface") [n2 srv.$.id! iface])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
(call %init_peer_id% ("callbackSrv" "collectPeerInfo") [n2 ident services blueprints modules])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(fold services srv
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(call n2 ("srv" "get_interface") [srv.$.id!] iface)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "collectServiceInterface") [n2 srv.$.id! iface])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(next srv)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||
)
|
||||
)
|
||||
)
|
||||
(next n2)
|
||||
@ -409,55 +422,50 @@ export function findAndAskNeighboursSchema(...args) {
|
||||
)
|
||||
|
||||
`,
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return peer.connectionInfo.connectedRelay;
|
||||
});
|
||||
h.on('getDataSrv', 'relayPeerId', () => {
|
||||
return relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'clientId', () => {
|
||||
return clientId;
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return peer.getStatus().relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'relayPeerId', () => {return relayPeerId;});
|
||||
h.on('getDataSrv', 'clientId', () => {return clientId;});
|
||||
|
||||
h.use((req, resp, next) => {
|
||||
if (req.serviceId === 'callbackSrv' && req.fnName === 'collectPeerInfo') {
|
||||
const callParams = {
|
||||
...req.particleContext,
|
||||
tetraplets: {
|
||||
arg0: req.tetraplets[0],
|
||||
arg1: req.tetraplets[1],
|
||||
arg2: req.tetraplets[2],
|
||||
arg3: req.tetraplets[3],
|
||||
arg4: req.tetraplets[4],
|
||||
},
|
||||
};
|
||||
resp.retCode = ResultCodes.success;
|
||||
collectPeerInfo(req.args[0], req.args[1], req.args[2], req.args[3], req.args[4], callParams);
|
||||
resp.result = {};
|
||||
}
|
||||
next();
|
||||
});
|
||||
h.use((req, resp, next) => {
|
||||
if(req.serviceId === 'callbackSrv' && req.fnName === 'collectPeerInfo') {
|
||||
|
||||
const callParams = {
|
||||
...req.particleContext,
|
||||
tetraplets: {
|
||||
arg0: req.tetraplets[0],arg1: req.tetraplets[1],arg2: req.tetraplets[2],arg3: req.tetraplets[3],arg4: req.tetraplets[4]
|
||||
},
|
||||
};
|
||||
resp.retCode = ResultCodes.success;
|
||||
collectPeerInfo(req.args[0], req.args[1], req.args[2], req.args[3], req.args[4], callParams); resp.result = {}
|
||||
|
||||
h.use((req, resp, next) => {
|
||||
if (req.serviceId === 'callbackSrv' && req.fnName === 'collectServiceInterface') {
|
||||
const callParams = {
|
||||
...req.particleContext,
|
||||
tetraplets: {
|
||||
arg0: req.tetraplets[0],
|
||||
arg1: req.tetraplets[1],
|
||||
arg2: req.tetraplets[2],
|
||||
},
|
||||
};
|
||||
resp.retCode = ResultCodes.success;
|
||||
collectServiceInterface(req.args[0], req.args[1], req.args[2], callParams);
|
||||
resp.result = {};
|
||||
}
|
||||
next();
|
||||
});
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
|
||||
h.onEvent('callbackSrv', 'response', (args) => {});
|
||||
h.use((req, resp, next) => {
|
||||
if(req.serviceId === 'callbackSrv' && req.fnName === 'collectServiceInterface') {
|
||||
|
||||
const callParams = {
|
||||
...req.particleContext,
|
||||
tetraplets: {
|
||||
arg0: req.tetraplets[0],arg1: req.tetraplets[1],arg2: req.tetraplets[2]
|
||||
},
|
||||
};
|
||||
resp.retCode = ResultCodes.success;
|
||||
collectServiceInterface(req.args[0], req.args[1], req.args[2], callParams); resp.result = {}
|
||||
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
h.onEvent('callbackSrv', 'response', (args) => {
|
||||
|
||||
});
|
||||
|
||||
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||
const [err] = args;
|
||||
@ -467,45 +475,47 @@ export function findAndAskNeighboursSchema(...args) {
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(() => {
|
||||
reject('Request timed out for findAndAskNeighboursSchema');
|
||||
});
|
||||
if (config && config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
})
|
||||
if(config && config.ttl) {
|
||||
r.withTTL(config.ttl)
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
peer.internals.initiateFlow(request);
|
||||
return Promise.race([promise, Promise.resolve()]);
|
||||
}
|
||||
|
||||
|
||||
export function getAll(...args) {
|
||||
let peer;
|
||||
let relayPeerId;
|
||||
let knownPeers;
|
||||
let collectPeerInfo;
|
||||
let collectServiceInterface;
|
||||
let config;
|
||||
if (args[0] instanceof FluencePeer) {
|
||||
peer = args[0];
|
||||
relayPeerId = args[1];
|
||||
knownPeers = args[2];
|
||||
collectPeerInfo = args[3];
|
||||
collectServiceInterface = args[4];
|
||||
config = args[5];
|
||||
} else {
|
||||
peer = FluencePeer.default;
|
||||
relayPeerId = args[0];
|
||||
knownPeers = args[1];
|
||||
collectPeerInfo = args[2];
|
||||
collectServiceInterface = args[3];
|
||||
config = args[4];
|
||||
}
|
||||
|
||||
let request;
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
const r = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript(
|
||||
`
|
||||
export function getAll(...args) {
|
||||
let peer;
|
||||
let relayPeerId;
|
||||
let knownPeers;
|
||||
let collectPeerInfo;
|
||||
let collectServiceInterface;
|
||||
let config;
|
||||
if (FluencePeer.isInstance(args[0])) {
|
||||
peer = args[0];
|
||||
relayPeerId = args[1];
|
||||
knownPeers = args[2];
|
||||
collectPeerInfo = args[3];
|
||||
collectServiceInterface = args[4];
|
||||
config = args[5];
|
||||
} else {
|
||||
peer = Fluence.getPeer();
|
||||
relayPeerId = args[0];
|
||||
knownPeers = args[1];
|
||||
collectPeerInfo = args[2];
|
||||
collectServiceInterface = args[3];
|
||||
config = args[4];
|
||||
}
|
||||
|
||||
let request;
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
const r = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
@ -544,31 +554,34 @@ export function getAll(...args) {
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(fold services srv
|
||||
(par
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(xor
|
||||
(seq
|
||||
(call peer ("srv" "get_interface") [srv.$.id!] iface)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "collectServiceInterface") [peer srv.$.id! iface])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
(seq
|
||||
(call peer ("srv" "get_interface") [srv.$.id!] iface)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "collectServiceInterface") [peer srv.$.id! iface])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(next srv)
|
||||
)
|
||||
(next srv)
|
||||
)
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||
)
|
||||
)
|
||||
)
|
||||
(next peer)
|
||||
@ -579,55 +592,50 @@ export function getAll(...args) {
|
||||
)
|
||||
|
||||
`,
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return peer.connectionInfo.connectedRelay;
|
||||
});
|
||||
h.on('getDataSrv', 'relayPeerId', () => {
|
||||
return relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'knownPeers', () => {
|
||||
return knownPeers;
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return peer.getStatus().relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'relayPeerId', () => {return relayPeerId;});
|
||||
h.on('getDataSrv', 'knownPeers', () => {return knownPeers;});
|
||||
|
||||
h.use((req, resp, next) => {
|
||||
if (req.serviceId === 'callbackSrv' && req.fnName === 'collectPeerInfo') {
|
||||
const callParams = {
|
||||
...req.particleContext,
|
||||
tetraplets: {
|
||||
arg0: req.tetraplets[0],
|
||||
arg1: req.tetraplets[1],
|
||||
arg2: req.tetraplets[2],
|
||||
arg3: req.tetraplets[3],
|
||||
arg4: req.tetraplets[4],
|
||||
},
|
||||
};
|
||||
resp.retCode = ResultCodes.success;
|
||||
collectPeerInfo(req.args[0], req.args[1], req.args[2], req.args[3], req.args[4], callParams);
|
||||
resp.result = {};
|
||||
}
|
||||
next();
|
||||
});
|
||||
h.use((req, resp, next) => {
|
||||
if(req.serviceId === 'callbackSrv' && req.fnName === 'collectPeerInfo') {
|
||||
|
||||
const callParams = {
|
||||
...req.particleContext,
|
||||
tetraplets: {
|
||||
arg0: req.tetraplets[0],arg1: req.tetraplets[1],arg2: req.tetraplets[2],arg3: req.tetraplets[3],arg4: req.tetraplets[4]
|
||||
},
|
||||
};
|
||||
resp.retCode = ResultCodes.success;
|
||||
collectPeerInfo(req.args[0], req.args[1], req.args[2], req.args[3], req.args[4], callParams); resp.result = {}
|
||||
|
||||
h.use((req, resp, next) => {
|
||||
if (req.serviceId === 'callbackSrv' && req.fnName === 'collectServiceInterface') {
|
||||
const callParams = {
|
||||
...req.particleContext,
|
||||
tetraplets: {
|
||||
arg0: req.tetraplets[0],
|
||||
arg1: req.tetraplets[1],
|
||||
arg2: req.tetraplets[2],
|
||||
},
|
||||
};
|
||||
resp.retCode = ResultCodes.success;
|
||||
collectServiceInterface(req.args[0], req.args[1], req.args[2], callParams);
|
||||
resp.result = {};
|
||||
}
|
||||
next();
|
||||
});
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
|
||||
h.onEvent('callbackSrv', 'response', (args) => {});
|
||||
h.use((req, resp, next) => {
|
||||
if(req.serviceId === 'callbackSrv' && req.fnName === 'collectServiceInterface') {
|
||||
|
||||
const callParams = {
|
||||
...req.particleContext,
|
||||
tetraplets: {
|
||||
arg0: req.tetraplets[0],arg1: req.tetraplets[1],arg2: req.tetraplets[2]
|
||||
},
|
||||
};
|
||||
resp.retCode = ResultCodes.success;
|
||||
collectServiceInterface(req.args[0], req.args[1], req.args[2], callParams); resp.result = {}
|
||||
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
h.onEvent('callbackSrv', 'response', (args) => {
|
||||
|
||||
});
|
||||
|
||||
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||
const [err] = args;
|
||||
@ -637,12 +645,13 @@ export function getAll(...args) {
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(() => {
|
||||
reject('Request timed out for getAll');
|
||||
});
|
||||
if (config && config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
})
|
||||
if(config && config.ttl) {
|
||||
r.withTTL(config.ttl)
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
peer.internals.initiateFlow(request);
|
||||
return Promise.race([promise, Promise.resolve()]);
|
||||
}
|
||||
|
||||
|
22
src/index.js
22
src/index.js
@ -20,18 +20,18 @@ import './main.css';
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
import log from 'loglevel';
|
||||
import Multiaddr from 'multiaddr';
|
||||
import { stage, krasnodar } from '@fluencelabs/fluence-network-environment';
|
||||
import { FluencePeer, KeyPair, setLogLevel } from '@fluencelabs/fluence';
|
||||
import { stage, krasnodar, testNet } from '@fluencelabs/fluence-network-environment';
|
||||
import { Fluence, KeyPair, setLogLevel } from '@fluencelabs/fluence';
|
||||
import { Elm } from './Main.elm';
|
||||
import * as serviceWorker from './serviceWorker';
|
||||
import { interfaceInfo, peerInfo } from './types';
|
||||
import { getAll } from './_aqua/app';
|
||||
import { askAllAndSend } from './_aqua/app';
|
||||
|
||||
const defaultNetworkName = 'krasnodar';
|
||||
|
||||
const defaultEnv = {
|
||||
relays: krasnodar,
|
||||
relayIdx: 3,
|
||||
relays: [...krasnodar, ...testNet, ...stage],
|
||||
relayIdx: 2,
|
||||
logLevel: 'error',
|
||||
};
|
||||
|
||||
@ -115,8 +115,8 @@ function genFlags(peerId, relays, relayIdx) {
|
||||
const { relays, relayIdx, logLevel } = await initEnvironment();
|
||||
setLogLevel(logLevel);
|
||||
const keyPair = await KeyPair.randomEd25519();
|
||||
await FluencePeer.default.init({ connectTo: relays[relayIdx].multiaddr });
|
||||
const pid = FluencePeer.default.connectionInfo.selfPeerId;
|
||||
await Fluence.start({ connectTo: relays[relayIdx].multiaddr });
|
||||
const pid = Fluence.getStatus().peerId;
|
||||
const flags = genFlags(pid, relays, relayIdx);
|
||||
console.log(`Own peer id: ${pid}`);
|
||||
|
||||
@ -162,9 +162,11 @@ function genFlags(peerId, relays, relayIdx) {
|
||||
}
|
||||
|
||||
app.ports.getAll.subscribe(async (data) => {
|
||||
await getAll(data.relayPeerId, data.knownPeers, collectPeerInfo, collectServiceInterface, {
|
||||
ttl: 1000000,
|
||||
});
|
||||
for (let peer of data.knownPeers) {
|
||||
await askAllAndSend(peer, collectPeerInfo, collectServiceInterface, {
|
||||
ttl: 120000,
|
||||
});
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user