diff --git a/aqua/app.aqua b/aqua/app.aqua index 6840842..9d15b43 100644 --- a/aqua/app.aqua +++ b/aqua/app.aqua @@ -2,18 +2,18 @@ import "@fluencelabs/aqua-lib/builtin.aqua" alias FakeTuple: u64 alias PeerInfoCb: PeerId, Info, []Service, []Blueprint, []Module -> () -alias ServiceInterfaceCb: PeerId, []FakeTuple -> () +alias ServiceInterfaceCb: PeerId, *FakeTuple -> () alias Log: string -> () service MyOp("op"): - array(i: Interface, s: string) -> FakeTuple + array(s: string, i: Interface) -> FakeTuple func collectServiceInterfaces(peer: PeerId, services: []Service, collectServiceInterface: ServiceInterfaceCb, log: Log): ifaces: *FakeTuple on peer: for srv <- services: iface <- Srv.get_interface(srv.id) - ifaces <- MyOp.array(iface, srv.id) + ifaces <- MyOp.array(srv.id, iface) collectServiceInterface(peer, ifaces) func askAllAndSend(peer: PeerId, collectPeerInfo: PeerInfoCb, collectServiceInterface: ServiceInterfaceCb, log: Log): @@ -22,12 +22,8 @@ func askAllAndSend(peer: PeerId, collectPeerInfo: PeerInfoCb, collectServiceInte blueprints <- Dist.list_blueprints() modules <- Dist.list_modules() services <- Srv.list() - co log("b4 collectPeerInfo") co collectPeerInfo(peer, ident, services, blueprints, modules) - co log("b4 collectServiceInterfaces") collectServiceInterfaces(peer, services, collectServiceInterface, log) - co log("after collectServiceInterfaces") - func findAndAskNeighboursSchema(relayPeerId: PeerId, clientId: PeerId, collectPeerInfo: PeerInfoCb, collectServiceInterface: ServiceInterfaceCb, log: Log): on relayPeerId: @@ -39,7 +35,6 @@ func findAndAskNeighboursSchema(relayPeerId: PeerId, clientId: PeerId, collectPe askAllAndSend(n2, collectPeerInfo, collectServiceInterface, log) func getAll(knownPeers: []PeerId, collectPeerInfo: PeerInfoCb, collectServiceInterface: ServiceInterfaceCb, log: Log): - co log("starting") on HOST_PEER_ID: -- co askAllAndSend(relayPeerId, collectPeerInfo, collectServiceInterface) diff --git a/src/_aqua/app.d.ts b/src/_aqua/app.d.ts index 7cfdff0..469e47b 100644 --- a/src/_aqua/app.d.ts +++ b/src/_aqua/app.d.ts @@ -16,7 +16,7 @@ import { // Services export interface MyOpDef { - array: (i: { function_signatures: { arguments: string[][]; name: string; output_types: string[]; }[]; record_types: { fields: string[][]; id: number; name: string; }[]; }, s: string, callParams: CallParams<'i' | 's'>) => number | Promise; + array: (s: string, i: { function_signatures: { arguments: string[][]; name: string; output_types: string[]; }[]; record_types: { fields: string[][]; id: number; name: string; }[]; }, callParams: CallParams<'s' | 'i'>) => number | Promise; } export function registerMyOp(service: MyOpDef): void; export function registerMyOp(serviceId: string, service: MyOpDef): void; diff --git a/src/_aqua/app.js b/src/_aqua/app.js index e7dd7ac..33bfefd 100644 --- a/src/_aqua/app.js +++ b/src/_aqua/app.js @@ -28,13 +28,13 @@ export function registerMyOp(...args) { "functionName" : "array", "argDefs" : [ { - "name" : "i", + "name" : "s", "argType" : { "tag" : "primitive" } }, { - "name" : "s", + "name" : "i", "argType" : { "tag" : "primitive" } @@ -73,7 +73,7 @@ export function collectServiceInterfaces(...args) { (seq (seq (call peer ("srv" "get_interface") [srv.$.id!] iface) - (call peer ("op" "array") [iface srv.$.id!] $ifaces) + (call peer ("op" "array") [srv.$.id! iface] $ifaces) ) (next srv) ) @@ -87,7 +87,7 @@ export function collectServiceInterfaces(...args) { (call -relay- ("op" "noop") []) ) (xor - (call %init_peer_id% ("callbackSrv" "collectServiceInterface") [peer ifaces]) + (call %init_peer_id% ("callbackSrv" "collectServiceInterface") [peer $ifaces]) (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2]) ) ) @@ -194,87 +194,51 @@ export function askAllAndSend(...args) { (seq (seq (seq - (seq - (seq - (seq - (seq - (call peer ("peer" "identify") [] ident) - (call peer ("dist" "list_blueprints") [] blueprints) - ) - (call peer ("dist" "list_modules") [] modules) - ) - (call peer ("srv" "list") [] services) - ) - (par - (seq - (call -relay- ("op" "noop") []) - (xor - (call %init_peer_id% ("callbackSrv" "log") ["b4 collectPeerInfo"]) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1]) - ) - ) - (null) - ) - ) - (par - (seq - (call -relay- ("op" "noop") []) - (xor - (call %init_peer_id% ("callbackSrv" "collectPeerInfo") [peer ident services blueprints modules]) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2]) - ) - ) - (null) - ) - ) - (par - (seq - (call -relay- ("op" "noop") []) - (xor - (call %init_peer_id% ("callbackSrv" "log") ["b4 collectServiceInterfaces"]) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3]) - ) - ) - (null) - ) - ) - (xor - (fold services srv - (seq - (seq - (call peer ("srv" "get_interface") [srv.$.id!] iface) - (call peer ("op" "array") [iface srv.$.id!] $ifaces) - ) - (next srv) - ) - ) - (seq - (call -relay- ("op" "noop") []) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4]) + (call peer ("peer" "identify") [] ident) + (call peer ("dist" "list_blueprints") [] blueprints) ) + (call peer ("dist" "list_modules") [] modules) ) + (call peer ("srv" "list") [] services) + ) + (par + (seq + (call -relay- ("op" "noop") []) + (xor + (call %init_peer_id% ("callbackSrv" "collectPeerInfo") [peer ident services blueprints modules]) + (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1]) + ) + ) + (null) ) - (call -relay- ("op" "noop") []) ) (xor - (call %init_peer_id% ("callbackSrv" "collectServiceInterface") [peer ifaces]) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5]) + (fold services srv + (seq + (seq + (call peer ("srv" "get_interface") [srv.$.id!] iface) + (call peer ("op" "array") [srv.$.id! iface] $ifaces) + ) + (next srv) + ) + ) + (seq + (call -relay- ("op" "noop") []) + (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2]) + ) ) ) (call -relay- ("op" "noop") []) ) - (par - (xor - (call %init_peer_id% ("callbackSrv" "log") ["after collectServiceInterfaces"]) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 6]) - ) - (null) + (xor + (call %init_peer_id% ("callbackSrv" "collectServiceInterface") [peer $ifaces]) + (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3]) ) ) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 7]) + (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4]) ) ) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 8]) + (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5]) ) ` return callFunction( @@ -447,84 +411,48 @@ export function findAndAskNeighboursSchema(...args) { (seq (seq (seq - (seq - (seq - (seq - (seq - (call n2 ("peer" "identify") [] ident) - (call n2 ("dist" "list_blueprints") [] blueprints) - ) - (call n2 ("dist" "list_modules") [] modules) - ) - (call n2 ("srv" "list") [] services) - ) - (par - (seq - (call -relay- ("op" "noop") []) - (xor - (call %init_peer_id% ("callbackSrv" "log") ["b4 collectPeerInfo"]) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1]) - ) - ) - (null) - ) - ) - (par - (seq - (call -relay- ("op" "noop") []) - (xor - (call %init_peer_id% ("callbackSrv" "collectPeerInfo") [n2 ident services blueprints modules]) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2]) - ) - ) - (null) - ) - ) - (par - (seq - (call -relay- ("op" "noop") []) - (xor - (call %init_peer_id% ("callbackSrv" "log") ["b4 collectServiceInterfaces"]) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3]) - ) - ) - (null) - ) - ) - (xor - (fold services srv - (seq - (seq - (call n2 ("srv" "get_interface") [srv.$.id!] iface) - (call n2 ("op" "array") [iface srv.$.id!] $ifaces) - ) - (next srv) - ) - ) - (seq - (call -relay- ("op" "noop") []) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4]) + (call n2 ("peer" "identify") [] ident) + (call n2 ("dist" "list_blueprints") [] blueprints) ) + (call n2 ("dist" "list_modules") [] modules) ) + (call n2 ("srv" "list") [] services) + ) + (par + (seq + (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]) + ) + ) + (null) ) - (call -relay- ("op" "noop") []) ) (xor - (call %init_peer_id% ("callbackSrv" "collectServiceInterface") [n2 ifaces]) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5]) + (fold services srv + (seq + (seq + (call n2 ("srv" "get_interface") [srv.$.id!] iface) + (call n2 ("op" "array") [srv.$.id! iface] $ifaces) + ) + (next srv) + ) + ) + (seq + (call -relay- ("op" "noop") []) + (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2]) + ) ) ) (call -relay- ("op" "noop") []) ) - (par - (xor - (call %init_peer_id% ("callbackSrv" "log") ["after collectServiceInterfaces"]) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 6]) - ) - (null) + (xor + (call %init_peer_id% ("callbackSrv" "collectServiceInterface") [n2 $ifaces]) + (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3]) ) ) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 7]) + (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4]) ) ) (seq @@ -535,7 +463,7 @@ export function findAndAskNeighboursSchema(...args) { ) ) ) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 8]) + (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5]) ) ) (seq @@ -546,10 +474,10 @@ export function findAndAskNeighboursSchema(...args) { ) ) ) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 9]) + (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 6]) ) ) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 10]) + (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 7]) ) ` return callFunction( @@ -681,17 +609,8 @@ export function getAll(...args) { (xor (seq (seq - (seq - (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-) - (call %init_peer_id% ("getDataSrv" "knownPeers") [] knownPeers) - ) - (par - (xor - (call %init_peer_id% ("callbackSrv" "log") ["starting"]) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1]) - ) - (null) - ) + (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-) + (call %init_peer_id% ("getDataSrv" "knownPeers") [] knownPeers) ) (xor (par @@ -707,84 +626,48 @@ export function getAll(...args) { (seq (seq (seq - (seq - (seq - (seq - (seq - (call peer ("peer" "identify") [] ident) - (call peer ("dist" "list_blueprints") [] blueprints) - ) - (call peer ("dist" "list_modules") [] modules) - ) - (call peer ("srv" "list") [] services) - ) - (par - (seq - (call -relay- ("op" "noop") []) - (xor - (call %init_peer_id% ("callbackSrv" "log") ["b4 collectPeerInfo"]) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2]) - ) - ) - (null) - ) - ) - (par - (seq - (call -relay- ("op" "noop") []) - (xor - (call %init_peer_id% ("callbackSrv" "collectPeerInfo") [peer ident services blueprints modules]) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3]) - ) - ) - (null) - ) - ) - (par - (seq - (call -relay- ("op" "noop") []) - (xor - (call %init_peer_id% ("callbackSrv" "log") ["b4 collectServiceInterfaces"]) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4]) - ) - ) - (null) - ) - ) - (xor - (fold services srv - (seq - (seq - (call peer ("srv" "get_interface") [srv.$.id!] iface) - (call peer ("op" "array") [iface srv.$.id!] $ifaces) - ) - (next srv) - ) - ) - (seq - (call -relay- ("op" "noop") []) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5]) + (call peer ("peer" "identify") [] ident) + (call peer ("dist" "list_blueprints") [] blueprints) ) + (call peer ("dist" "list_modules") [] modules) ) + (call peer ("srv" "list") [] services) + ) + (par + (seq + (call -relay- ("op" "noop") []) + (xor + (call %init_peer_id% ("callbackSrv" "collectPeerInfo") [peer ident services blueprints modules]) + (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1]) + ) + ) + (null) ) - (call -relay- ("op" "noop") []) ) (xor - (call %init_peer_id% ("callbackSrv" "collectServiceInterface") [peer ifaces]) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 6]) + (fold services srv + (seq + (seq + (call peer ("srv" "get_interface") [srv.$.id!] iface) + (call peer ("op" "array") [srv.$.id! iface] $ifaces) + ) + (next srv) + ) + ) + (seq + (call -relay- ("op" "noop") []) + (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2]) + ) ) ) (call -relay- ("op" "noop") []) ) - (par - (xor - (call %init_peer_id% ("callbackSrv" "log") ["after collectServiceInterfaces"]) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 7]) - ) - (null) + (xor + (call %init_peer_id% ("callbackSrv" "collectServiceInterface") [peer $ifaces]) + (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3]) ) ) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 8]) + (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4]) ) ) (next peer) @@ -792,10 +675,10 @@ export function getAll(...args) { ) (null) ) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 9]) + (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5]) ) ) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 10]) + (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 6]) ) ` return callFunction( diff --git a/src/index.js b/src/index.js index 0af7bd8..3a59e3b 100644 --- a/src/index.js +++ b/src/index.js @@ -31,8 +31,8 @@ const defaultNetworkName = 'testNet + krasnodar'; const defaultEnv = { //relays: [...testNet, ...krasnodar, ...stage], - relays: [stage[0]], - relayIdx: 0, + relays: [...krasnodar], + relayIdx: 2, logLevel: 'trace', }; @@ -114,7 +114,7 @@ function genFlags(peerId, relays, relayIdx) { (async () => { const { relays, relayIdx, logLevel } = await initEnvironment(); - setLogLevel('trace'); + setLogLevel(logLevel); const keyPair = await KeyPair.randomEd25519(); await Fluence.start({ connectTo: relays[relayIdx].multiaddr, defaultTtlMs: 200000 }); // await Fluence.start({ connectTo: relays[relayIdx].multiaddr }); @@ -133,13 +133,12 @@ function genFlags(peerId, relays, relayIdx) { function collectServiceInterface(peer_id, ifaces) { // console.count(`service interface from ${peer_id}`); try { - for (var iface of ifaces) { + for (let srvIdAndInterfaceTuple of ifaces) { const eventRaw = { peer_id, - service_id: iface[1], - interface: iface[0], + service_id: srvIdAndInterfaceTuple[0], + interface: srvIdAndInterfaceTuple[1], }; - console.log(iface); app.ports.collectServiceInterface.send(eventRaw); } } catch (err) { @@ -149,7 +148,7 @@ function genFlags(peerId, relays, relayIdx) { // alias PeerInfoCb: PeerId, Info, []Service, []Blueprint, []Module -> () function collectPeerInfo(peerId, identify, services, blueprints, modules, interfaces) { - console.log('peer info from %s, %s services', peerId, services.length); + // console.log('peer info from %s, %s services', peerId, services.length); try { const eventRaw = { peerId,