Update JS SDK version (#24)

This commit is contained in:
Pavel 2021-09-24 18:52:59 +03:00 committed by GitHub
parent 5335cd1547
commit 2552c842b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 345 additions and 160 deletions

View File

@ -21,10 +21,10 @@ func askAllAndSend(peer: PeerId, collectPeerInfo: PeerInfoCb, collectServiceInte
func findAndAskNeighboursSchema(relayPeerId: PeerId, clientId: PeerId, collectPeerInfo: PeerInfoCb, collectServiceInterface: ServiceInterfaceCb):
on relayPeerId:
neighbors <- Kademlia.neighborhood(clientId, false)
neighbors <- Kademlia.neighborhood(clientId, nil, nil)
for n <- neighbors par:
on n:
neighbors2 <- Kademlia.neighborhood(clientId, false)
neighbors2 <- Kademlia.neighborhood(clientId, nil, nil)
for n2 <- neighbors2 par:
askAllAndSend(n2, collectPeerInfo, collectServiceInterface)

80
package-lock.json generated
View File

@ -1030,10 +1030,10 @@
}
}
},
"@fluencelabs/aqua-cli": {
"version": "0.2.0-208",
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua-cli/-/aqua-cli-0.2.0-208.tgz",
"integrity": "sha512-IQ2loGZo/kGi1KmCeoNZWXTrzZFd7AdD4b8hvZdvFkRBCAmOz2Hx/6/b7SnTDjR7qcHvxWlSR1h9QcAgsjOLUg==",
"@fluencelabs/aqua": {
"version": "0.3.0-222",
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua/-/aqua-0.3.0-222.tgz",
"integrity": "sha512-dwBPNoE490LX9CRssNyz3nHKgpxwYvkRIhmTbjbFYXknzZWN18vx6WseD9tuzIFnlXdsJ/MoUhNZAxmT+VPhiw==",
"dev": true
},
"@fluencelabs/aqua-lib": {
@ -1043,9 +1043,9 @@
"dev": true
},
"@fluencelabs/avm": {
"version": "0.14.1",
"resolved": "https://registry.npmjs.org/@fluencelabs/avm/-/avm-0.14.1.tgz",
"integrity": "sha512-8up8exmCpEBhv0nlXlJiFN76yk3xK36AZPjah1KEYLqbIqdPtU78S2Brp4qctLLw9Pnl766U9bW7md+1SQYdWw==",
"version": "0.14.4",
"resolved": "https://registry.npmjs.org/@fluencelabs/avm/-/avm-0.14.4.tgz",
"integrity": "sha512-XyR+1H5k0CAc+mDHOkl81viX8XeW1Yqbw793xbsfUfju5bUb/hqk+gHv3q8lAFdbrCG5P45gdOT08a5RNODZaQ==",
"requires": {
"base64-js": "1.5.1"
},
@ -1058,14 +1058,14 @@
}
},
"@fluencelabs/fluence": {
"version": "0.10.0",
"resolved": "https://registry.npmjs.org/@fluencelabs/fluence/-/fluence-0.10.0.tgz",
"integrity": "sha512-7kRM2axlLUtRtS3GczVTChq3zo0iJ7TRKC7acY9lt7Y1G5HWy5yzfHt6sC422dcRgSLehrG6EQ+/sYZ/7Qq2sQ==",
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/@fluencelabs/fluence/-/fluence-0.11.0.tgz",
"integrity": "sha512-HfUS8eLwfviiJhqsrHnOnRxO20TbdahPreP6AkBXQaEpWeRew6vxAd0Dn+xdzy6KCJ4W9GOKLcgtPfqquIO2Pg==",
"requires": {
"@chainsafe/libp2p-noise": "4.0.0",
"@fluencelabs/avm": "0.14.1",
"@fluencelabs/avm": "0.14.4",
"async": "3.2.0",
"base64-js": "1.3.1",
"base64-js": "1.5.1",
"bs58": "4.0.1",
"cids": "0.8.1",
"it-length-prefixed": "3.0.1",
@ -1076,8 +1076,16 @@
"libp2p-websockets": "0.16.1",
"loglevel": "1.7.0",
"multiaddr": "10.0.0",
"noble-ed25519": "^1.2.5",
"peer-id": "0.15.3",
"uuid": "8.3.0"
},
"dependencies": {
"base64-js": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA=="
}
}
},
"@fluencelabs/fluence-network-environment": {
@ -7330,12 +7338,12 @@
"dev": true
},
"interface-datastore": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/interface-datastore/-/interface-datastore-5.1.2.tgz",
"integrity": "sha512-nRFl19/IkilNzuPdCUJHejyJCZrVAk4lIRcRXJkekuTdaiagIEnCd9GfmTTQlo2afiVISk8Iy/PxSgnfmrdEIw==",
"version": "5.1.3",
"resolved": "https://registry.npmjs.org/interface-datastore/-/interface-datastore-5.1.3.tgz",
"integrity": "sha512-OVJ2wXg4wuR8kGI9r+09UponEQl/oEtiPaMKiS8QnAKSOf/NTOGnnpmtQPy00UOp3vvbFOvocF6G7HnV76Fmpw==",
"requires": {
"err-code": "^3.0.1",
"interface-store": "^0.1.1",
"interface-store": "^1.0.2",
"ipfs-utils": "^8.1.2",
"it-all": "^1.0.2",
"it-drain": "^1.0.1",
@ -7356,9 +7364,9 @@
}
},
"interface-store": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/interface-store/-/interface-store-0.1.1.tgz",
"integrity": "sha512-ynnjIOybDZc0Brep3HHSa2RVlo/M5g7kuL/leui7o21EusKcLJS170vCJ8rliisc3c4jyd9ao5PthkGlBaX29g=="
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/interface-store/-/interface-store-1.0.2.tgz",
"integrity": "sha512-rUBLYsgoWwxuUpnQoSUr+DR/3dH3reVeIu5aOHFZK31lAexmb++kR6ZECNRgrx6WvoaM3Akdo0A7TDrqgCzZaQ=="
},
"internal-ip": {
"version": "4.3.0",
@ -7409,9 +7417,9 @@
"dev": true
},
"ipfs-utils": {
"version": "8.1.5",
"resolved": "https://registry.npmjs.org/ipfs-utils/-/ipfs-utils-8.1.5.tgz",
"integrity": "sha512-qjERTUy0iXPw5LRPA1OQLzYPjdYb7JQenihYaE0L+yA4NMoC9qhGVrYUqU8yaV0Iu+zk7i6BxoNwg8beWsqjbg==",
"version": "8.1.6",
"resolved": "https://registry.npmjs.org/ipfs-utils/-/ipfs-utils-8.1.6.tgz",
"integrity": "sha512-V/cwb6113DrDhrjDTWImA6+zmJbpdbUkxdxmEQO7it8ykV76bBmzU1ZXSM0QR0qxGy9VW8dkUlPAC2K10VgSmw==",
"requires": {
"abort-controller": "^3.0.0",
"any-signal": "^2.1.0",
@ -7426,7 +7434,7 @@
"nanoid": "^3.1.20",
"native-abort-controller": "^1.0.3",
"native-fetch": "^3.0.0",
"node-fetch": "npm:@achingbrain/node-fetch@^2.6.4",
"node-fetch": "https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz",
"react-native-fetch-api": "^2.0.0",
"stream-to-it": "^0.2.2"
}
@ -7852,9 +7860,9 @@
"integrity": "sha512-wiI02c+G1BVuu0jz30Nsr1/et0cpSRulKUusN8HDZXxuX4MdUzfMp2P4JUk+a49Wr1kHitRLrnnh3+UzJ6neaQ=="
},
"it-glob": {
"version": "0.0.13",
"resolved": "https://registry.npmjs.org/it-glob/-/it-glob-0.0.13.tgz",
"integrity": "sha512-0Hcd5BraJUPzL28NWiFbdNrcdyNxNTKKdU3sjdFiYynNTQpwlG2UKW31X7bp+XhJwux/oPzIquo5ioztVmc2RQ==",
"version": "0.0.14",
"resolved": "https://registry.npmjs.org/it-glob/-/it-glob-0.0.14.tgz",
"integrity": "sha512-TKKzs9CglbsihSpcwJPXN5DBUssu4akRzPlp8QJRCoLrKoaOpyY2V1qDlxx+UMivn0i114YyTd4AawWl7eqIdw==",
"requires": {
"@types/minimatch": "^3.0.4",
"minimatch": "^3.0.4"
@ -8966,9 +8974,9 @@
}
},
"multiformats": {
"version": "9.4.6",
"resolved": "https://registry.npmjs.org/multiformats/-/multiformats-9.4.6.tgz",
"integrity": "sha512-ngZRO82P7mPvw/3gu5NQ2QiUJGYTS0LAxvQnEAlWCJakvn7YpK2VAd9JWM5oosYUeqoVbkylH/FsqRc4fc2+ag=="
"version": "9.4.7",
"resolved": "https://registry.npmjs.org/multiformats/-/multiformats-9.4.7.tgz",
"integrity": "sha512-fZbcdf7LnvokPAZYkv4TLXe7PAg9sQ5qLXcwrAmZOloEb2+5FtFiAY+l3/9wsu4oTJXTV3JSggFQQ2dJLS01vA=="
},
"multihashes": {
"version": "0.4.21",
@ -9133,6 +9141,11 @@
"tslib": "^1.10.0"
}
},
"noble-ed25519": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/noble-ed25519/-/noble-ed25519-1.2.5.tgz",
"integrity": "sha512-7vst+4UhM5QU3jJ3pUqPMKBCOePrxBojmoQa59qcSnYvjFF/T4jqb4WISlfslcWyBw7G5H9V/acpcAxMd8DzUQ=="
},
"node-addon-api": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz",
@ -9196,8 +9209,7 @@
}
},
"node-fetch": {
"version": "npm:@achingbrain/node-fetch@2.6.7",
"resolved": "https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz",
"version": "https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz",
"integrity": "sha512-iTASGs+HTFK5E4ZqcMsHmeJ4zodyq8L38lZV33jwqcBJYoUt3HjN4+ot+O9/0b+ke8ddE7UgOtVuZN/OkV19/g=="
},
"node-forge": {
@ -15020,9 +15032,9 @@
"dev": true
},
"ws": {
"version": "7.5.3",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.3.tgz",
"integrity": "sha512-kQ/dHIzuLrS6Je9+uv81ueZomEwH0qVYstcAQ4/Z93K8zeko9gtAbttJWzoC5ukqXY1PpoouV3+VSOqEAFt5wg=="
"version": "7.5.4",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.4.tgz",
"integrity": "sha512-zP9z6GXm6zC27YtspwH99T3qTG7bBFv2VIkeHstMLrLlDJuzA7tQ5ls3OJ1hOGGCzTQPniNJoHXIAOS0Jljohg=="
},
"xml2js": {
"version": "0.4.23",

View File

@ -10,7 +10,7 @@
"build": "webpack",
"prod": "webpack -p --mode production",
"analyse": "elm-analyse -s -p 3001 -o",
"compile-aqua": "aqua-cli --js -i ./aqua/ -o ./src/_aqua",
"compile-aqua": "aqua --js -i ./aqua/ -o ./src/_aqua",
"watch-aqua": "chokidar \"**/*.aqua\" -c \"npm run compile-aqua\"",
"uie": "elm-live src_storybook/Explorer.elm --open --dir=.storybook --start-page=index.html -- --output=.storybook/explorer.js --debug"
},
@ -31,7 +31,7 @@
},
"homepage": "https://github.com/fluencelabs/fluence-admin#readme",
"dependencies": {
"@fluencelabs/fluence": "0.10.0",
"@fluencelabs/fluence": "0.11.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-cli": "0.2.0-208",
"@fluencelabs/aqua-lib": "0.1.14",
"@fluencelabs/aqua": "^0.3.0-222",
"@fluencelabs/aqua-lib": "^0.1.14",
"@types/yup": "^0.29.11",
"babel-loader": "^8.1.0",
"chokidar-cli": "^2.1.0",

View File

@ -1,24 +1,50 @@
/**
*
* 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.1.14-SNAPSHOT
* Aqua version: 0.3.0-222
*
*/
import { RequestFlowBuilder } from '@fluencelabs/fluence/dist/api.unstable';
import { FluencePeer } from '@fluencelabs/fluence';
import {
ResultCodes,
RequestFlow,
RequestFlowBuilder,
CallParams,
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v1.js';
// 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];
}
export async function collectServiceInterfaces(client, peer, services, collectServiceInterface, config) {
let request;
config = config || {};
const promise = new Promise((resolve, reject) => {
var r = new RequestFlowBuilder()
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(xor
(seq
(seq
(seq
@ -52,18 +78,39 @@ export async function collectServiceInterfaces(client, peer, services, collectSe
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)
`,
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return client.relayPeerId;
return peer.connectionInfo.connectedRelay;
});
h.on('getDataSrv', 'peer', () => {return peer;});
h.on('getDataSrv', 'services', () => {return services;});
h.on('callbackSrv', 'collectServiceInterface', (args) => {collectServiceInterface(args[0], args[1], args[2]); return {};});
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.onEvent('callbackSrv', 'response', (args) => {});
h.onEvent('errorHandlingSrv', 'error', (args) => {
// assuming error is the single argument
const [err] = args;
reject(err);
});
@ -71,27 +118,43 @@ h.on('callbackSrv', 'collectServiceInterface', (args) => {collectServiceInterfac
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for collectServiceInterfaces');
})
if(config.ttl) {
r.withTTL(config.ttl)
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
await client.initiateFlow(request);
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];
}
export async function askAllAndSend(client, peer, collectPeerInfo, collectServiceInterface, config) {
let request;
config = config || {};
const promise = new Promise((resolve, reject) => {
var r = new RequestFlowBuilder()
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(xor
(seq
(seq
(seq
@ -155,18 +218,55 @@ export async function askAllAndSend(client, peer, collectPeerInfo, collectServic
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5])
)
`,
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return client.relayPeerId;
return peer.connectionInfo.connectedRelay;
});
h.on('getDataSrv', 'peer', () => {return peer;});
h.on('callbackSrv', 'collectPeerInfo', (args) => {collectPeerInfo(args[0], args[1], args[2], args[3], args[4]); return {};});
h.on('callbackSrv', 'collectServiceInterface', (args) => {collectServiceInterface(args[0], args[1], args[2]); return {};});
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 === '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) => {
// assuming error is the single argument
const [err] = args;
reject(err);
});
@ -174,27 +274,46 @@ h.on('callbackSrv', 'collectServiceInterface', (args) => {collectServiceInterfac
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for askAllAndSend');
})
if(config.ttl) {
r.withTTL(config.ttl)
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
await client.initiateFlow(request);
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];
}
export async function findAndAskNeighboursSchema(client, relayPeerId, clientId, collectPeerInfo, collectServiceInterface, config) {
let request;
config = config || {};
const promise = new Promise((resolve, reject) => {
var r = new RequestFlowBuilder()
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(xor
(seq
(seq
(seq
@ -208,12 +327,12 @@ export async function findAndAskNeighboursSchema(client, relayPeerId, clientId,
)
(xor
(seq
(call relayPeerId ("kad" "neighborhood") [clientId false] neighbors)
(call relayPeerId ("kad" "neighborhood") [clientId [] []] neighbors)
(fold neighbors n
(par
(xor
(seq
(call n ("kad" "neighborhood") [clientId false] neighbors2)
(call n ("kad" "neighborhood") [clientId [] []] neighbors2)
(fold neighbors2 n2
(par
(xor
@ -289,19 +408,58 @@ export async function findAndAskNeighboursSchema(client, relayPeerId, clientId,
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 7])
)
`,
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return client.relayPeerId;
return peer.connectionInfo.connectedRelay;
});
h.on('getDataSrv', 'relayPeerId', () => {return relayPeerId;});
h.on('getDataSrv', 'clientId', () => {return clientId;});
h.on('callbackSrv', 'collectPeerInfo', (args) => {collectPeerInfo(args[0], args[1], args[2], args[3], args[4]); return {};});
h.on('callbackSrv', 'collectServiceInterface', (args) => {collectServiceInterface(args[0], args[1], args[2]); return {};});
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 === '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) => {
// assuming error is the single argument
const [err] = args;
reject(err);
});
@ -309,27 +467,46 @@ h.on('callbackSrv', 'collectServiceInterface', (args) => {collectServiceInterfac
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for findAndAskNeighboursSchema');
})
if(config.ttl) {
r.withTTL(config.ttl)
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
await client.initiateFlow(request);
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];
}
export async function getAll(client, relayPeerId, knownPeers, collectPeerInfo, collectServiceInterface, config) {
let request;
config = config || {};
const promise = new Promise((resolve, reject) => {
var r = new RequestFlowBuilder()
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(xor
(seq
(seq
(seq
@ -401,19 +578,58 @@ export async function getAll(client, relayPeerId, knownPeers, collectPeerInfo, c
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5])
)
`,
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return client.relayPeerId;
return peer.connectionInfo.connectedRelay;
});
h.on('getDataSrv', 'relayPeerId', () => {return relayPeerId;});
h.on('getDataSrv', 'knownPeers', () => {return knownPeers;});
h.on('callbackSrv', 'collectPeerInfo', (args) => {collectPeerInfo(args[0], args[1], args[2], args[3], args[4]); return {};});
h.on('callbackSrv', 'collectServiceInterface', (args) => {collectServiceInterface(args[0], args[1], args[2]); return {};});
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 === '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) => {
// assuming error is the single argument
const [err] = args;
reject(err);
});
@ -421,13 +637,12 @@ h.on('callbackSrv', 'collectServiceInterface', (args) => {collectServiceInterfac
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for getAll');
})
if(config.ttl) {
r.withTTL(config.ttl)
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
await client.initiateFlow(request);
peer.internals.initiateFlow(request);
return Promise.race([promise, Promise.resolve()]);
}

View File

@ -21,14 +21,7 @@ import './main.css';
import log from 'loglevel';
import Multiaddr from 'multiaddr';
import { stage, krasnodar } from '@fluencelabs/fluence-network-environment';
import {
createClient,
generatePeerId,
Particle,
sendParticle,
subscribeToEvent,
setLogLevel,
} from '@fluencelabs/fluence';
import { FluencePeer, KeyPair, setLogLevel } from '@fluencelabs/fluence';
import { Elm } from './Main.elm';
import * as serviceWorker from './serviceWorker';
import { interfaceInfo, peerInfo } from './types';
@ -121,54 +114,19 @@ function genFlags(peerId, relays, relayIdx) {
(async () => {
const { relays, relayIdx, logLevel } = await initEnvironment();
setLogLevel(logLevel);
const pid = await generatePeerId();
const flags = genFlags(pid.toB58String(), relays, relayIdx);
console.log(`connect with client: ${pid.toB58String()}`);
const keyPair = await KeyPair.randomEd25519();
await FluencePeer.default.init({ connectTo: relays[relayIdx].multiaddr });
const pid = FluencePeer.default.connectionInfo.selfPeerId;
const flags = genFlags(pid, relays, relayIdx);
console.log(`Own peer id: ${pid}`);
// If the relay is ever changed, an event shall be sent to elm
const client = await createClient(relays[relayIdx].multiaddr, pid);
const app = Elm.Main.init({
node: document.getElementById('root'),
flags: flags,
});
subscribeToEvent(client, 'event', 'collectPeerInfo', (args, _tetraplets) => {
try {
const peerId = args[0];
const identify = args[1];
const services = args[2];
const blueprints = args[3];
const modules = args[4];
const interfaces = args[5];
const eventRaw = {
peerId,
identify,
services,
blueprints,
modules,
};
app.ports.collectPeerInfo.send(eventRaw);
} catch (err) {
log.error('Elm eventreceiver failed: ', err);
}
});
subscribeToEvent(client, 'event', 'collectServiceInterface', (args, _tetraplets) => {
try {
const eventRaw = {
peer_id: args[0],
service_id: args[1],
interface: args[2],
};
app.ports.collectServiceInterface.send(eventRaw);
} catch (err) {
log.error('Elm eventreceiver failed: ', err);
}
});
// alias ServiceInterfaceCb: PeerId, string, Interface -> ()
function collectServiceInterface(peer_id, service_id, iface) {
// console.count(`service interface from ${peer_id}`);
@ -204,7 +162,7 @@ function genFlags(peerId, relays, relayIdx) {
}
app.ports.getAll.subscribe(async (data) => {
await getAll(client, data.relayPeerId, data.knownPeers, collectPeerInfo, collectServiceInterface, {
await getAll(data.relayPeerId, data.knownPeers, collectPeerInfo, collectServiceInterface, {
ttl: 1000000,
});
});