This commit is contained in:
Pavel Murygin 2021-10-29 17:47:16 +03:00
parent d809f35fcd
commit 6c20bbd407
4 changed files with 116 additions and 239 deletions

View File

@ -2,18 +2,18 @@ import "@fluencelabs/aqua-lib/builtin.aqua"
alias FakeTuple: u64 alias FakeTuple: u64
alias PeerInfoCb: PeerId, Info, []Service, []Blueprint, []Module -> () alias PeerInfoCb: PeerId, Info, []Service, []Blueprint, []Module -> ()
alias ServiceInterfaceCb: PeerId, []FakeTuple -> () alias ServiceInterfaceCb: PeerId, *FakeTuple -> ()
alias Log: string -> () alias Log: string -> ()
service MyOp("op"): 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): func collectServiceInterfaces(peer: PeerId, services: []Service, collectServiceInterface: ServiceInterfaceCb, log: Log):
ifaces: *FakeTuple ifaces: *FakeTuple
on peer: on peer:
for srv <- services: for srv <- services:
iface <- Srv.get_interface(srv.id) iface <- Srv.get_interface(srv.id)
ifaces <- MyOp.array(iface, srv.id) ifaces <- MyOp.array(srv.id, iface)
collectServiceInterface(peer, ifaces) collectServiceInterface(peer, ifaces)
func askAllAndSend(peer: PeerId, collectPeerInfo: PeerInfoCb, collectServiceInterface: ServiceInterfaceCb, log: Log): 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() blueprints <- Dist.list_blueprints()
modules <- Dist.list_modules() modules <- Dist.list_modules()
services <- Srv.list() services <- Srv.list()
co log("b4 collectPeerInfo")
co collectPeerInfo(peer, ident, services, blueprints, modules) co collectPeerInfo(peer, ident, services, blueprints, modules)
co log("b4 collectServiceInterfaces")
collectServiceInterfaces(peer, services, collectServiceInterface, log) collectServiceInterfaces(peer, services, collectServiceInterface, log)
co log("after collectServiceInterfaces")
func findAndAskNeighboursSchema(relayPeerId: PeerId, clientId: PeerId, collectPeerInfo: PeerInfoCb, collectServiceInterface: ServiceInterfaceCb, log: Log): func findAndAskNeighboursSchema(relayPeerId: PeerId, clientId: PeerId, collectPeerInfo: PeerInfoCb, collectServiceInterface: ServiceInterfaceCb, log: Log):
on relayPeerId: on relayPeerId:
@ -39,7 +35,6 @@ func findAndAskNeighboursSchema(relayPeerId: PeerId, clientId: PeerId, collectPe
askAllAndSend(n2, collectPeerInfo, collectServiceInterface, log) askAllAndSend(n2, collectPeerInfo, collectServiceInterface, log)
func getAll(knownPeers: []PeerId, collectPeerInfo: PeerInfoCb, collectServiceInterface: ServiceInterfaceCb, log: Log): func getAll(knownPeers: []PeerId, collectPeerInfo: PeerInfoCb, collectServiceInterface: ServiceInterfaceCb, log: Log):
co log("starting")
on HOST_PEER_ID: on HOST_PEER_ID:
-- co askAllAndSend(relayPeerId, collectPeerInfo, collectServiceInterface) -- co askAllAndSend(relayPeerId, collectPeerInfo, collectServiceInterface)

2
src/_aqua/app.d.ts vendored
View File

@ -16,7 +16,7 @@ import {
// Services // Services
export interface MyOpDef { 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<number>; 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<number>;
} }
export function registerMyOp(service: MyOpDef): void; export function registerMyOp(service: MyOpDef): void;
export function registerMyOp(serviceId: string, service: MyOpDef): void; export function registerMyOp(serviceId: string, service: MyOpDef): void;

View File

@ -28,13 +28,13 @@ export function registerMyOp(...args) {
"functionName" : "array", "functionName" : "array",
"argDefs" : [ "argDefs" : [
{ {
"name" : "i", "name" : "s",
"argType" : { "argType" : {
"tag" : "primitive" "tag" : "primitive"
} }
}, },
{ {
"name" : "s", "name" : "i",
"argType" : { "argType" : {
"tag" : "primitive" "tag" : "primitive"
} }
@ -73,7 +73,7 @@ export function collectServiceInterfaces(...args) {
(seq (seq
(seq (seq
(call peer ("srv" "get_interface") [srv.$.id!] iface) (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) (next srv)
) )
@ -87,7 +87,7 @@ export function collectServiceInterfaces(...args) {
(call -relay- ("op" "noop") []) (call -relay- ("op" "noop") [])
) )
(xor (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]) (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)
(seq (call peer ("dist" "list_blueprints") [] blueprints)
(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 ("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 (xor
(call %init_peer_id% ("callbackSrv" "collectServiceInterface") [peer ifaces]) (fold services srv
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5]) (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") []) (call -relay- ("op" "noop") [])
) )
(par (xor
(xor (call %init_peer_id% ("callbackSrv" "collectServiceInterface") [peer $ifaces])
(call %init_peer_id% ("callbackSrv" "log") ["after collectServiceInterfaces"]) (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 6])
)
(null)
) )
) )
(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( return callFunction(
@ -447,84 +411,48 @@ export function findAndAskNeighboursSchema(...args) {
(seq (seq
(seq (seq
(seq (seq
(seq (call n2 ("peer" "identify") [] ident)
(seq (call n2 ("dist" "list_blueprints") [] blueprints)
(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 ("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 (xor
(call %init_peer_id% ("callbackSrv" "collectServiceInterface") [n2 ifaces]) (fold services srv
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5]) (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") []) (call -relay- ("op" "noop") [])
) )
(par (xor
(xor (call %init_peer_id% ("callbackSrv" "collectServiceInterface") [n2 $ifaces])
(call %init_peer_id% ("callbackSrv" "log") ["after collectServiceInterfaces"]) (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 6])
)
(null)
) )
) )
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 7]) (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
) )
) )
(seq (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 (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( return callFunction(
@ -681,17 +609,8 @@ export function getAll(...args) {
(xor (xor
(seq (seq
(seq (seq
(seq (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-) (call %init_peer_id% ("getDataSrv" "knownPeers") [] knownPeers)
(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)
)
) )
(xor (xor
(par (par
@ -707,84 +626,48 @@ export function getAll(...args) {
(seq (seq
(seq (seq
(seq (seq
(seq (call peer ("peer" "identify") [] ident)
(seq (call peer ("dist" "list_blueprints") [] blueprints)
(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 ("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 (xor
(call %init_peer_id% ("callbackSrv" "collectServiceInterface") [peer ifaces]) (fold services srv
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 6]) (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") []) (call -relay- ("op" "noop") [])
) )
(par (xor
(xor (call %init_peer_id% ("callbackSrv" "collectServiceInterface") [peer $ifaces])
(call %init_peer_id% ("callbackSrv" "log") ["after collectServiceInterfaces"]) (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 7])
)
(null)
) )
) )
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 8]) (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
) )
) )
(next peer) (next peer)
@ -792,10 +675,10 @@ export function getAll(...args) {
) )
(null) (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( return callFunction(

View File

@ -31,8 +31,8 @@ const defaultNetworkName = 'testNet + krasnodar';
const defaultEnv = { const defaultEnv = {
//relays: [...testNet, ...krasnodar, ...stage], //relays: [...testNet, ...krasnodar, ...stage],
relays: [stage[0]], relays: [...krasnodar],
relayIdx: 0, relayIdx: 2,
logLevel: 'trace', logLevel: 'trace',
}; };
@ -114,7 +114,7 @@ function genFlags(peerId, relays, relayIdx) {
(async () => { (async () => {
const { relays, relayIdx, logLevel } = await initEnvironment(); const { relays, relayIdx, logLevel } = await initEnvironment();
setLogLevel('trace'); setLogLevel(logLevel);
const keyPair = await KeyPair.randomEd25519(); const keyPair = await KeyPair.randomEd25519();
await Fluence.start({ connectTo: relays[relayIdx].multiaddr, defaultTtlMs: 200000 }); await Fluence.start({ connectTo: relays[relayIdx].multiaddr, defaultTtlMs: 200000 });
// await Fluence.start({ connectTo: relays[relayIdx].multiaddr }); // await Fluence.start({ connectTo: relays[relayIdx].multiaddr });
@ -133,13 +133,12 @@ function genFlags(peerId, relays, relayIdx) {
function collectServiceInterface(peer_id, ifaces) { function collectServiceInterface(peer_id, ifaces) {
// console.count(`service interface from ${peer_id}`); // console.count(`service interface from ${peer_id}`);
try { try {
for (var iface of ifaces) { for (let srvIdAndInterfaceTuple of ifaces) {
const eventRaw = { const eventRaw = {
peer_id, peer_id,
service_id: iface[1], service_id: srvIdAndInterfaceTuple[0],
interface: iface[0], interface: srvIdAndInterfaceTuple[1],
}; };
console.log(iface);
app.ports.collectServiceInterface.send(eventRaw); app.ports.collectServiceInterface.send(eventRaw);
} }
} catch (err) { } catch (err) {
@ -149,7 +148,7 @@ function genFlags(peerId, relays, relayIdx) {
// alias PeerInfoCb: PeerId, Info, []Service, []Blueprint, []Module -> () // alias PeerInfoCb: PeerId, Info, []Service, []Blueprint, []Module -> ()
function collectPeerInfo(peerId, identify, services, blueprints, modules, interfaces) { 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 { try {
const eventRaw = { const eventRaw = {
peerId, peerId,