This commit is contained in:
Pavel Murygin 2021-10-29 12:23:13 +03:00
parent b5dfe4365f
commit 5a2dbc0bc9
6 changed files with 297 additions and 167 deletions

View File

@ -1,34 +1,44 @@
import "@fluencelabs/aqua-lib/builtin.aqua" import "@fluencelabs/aqua-lib/builtin.aqua"
alias FakeTuple: u64
alias PeerInfoCb: PeerId, Info, []Service, []Blueprint, []Module -> () alias PeerInfoCb: PeerId, Info, []Service, []Blueprint, []Module -> ()
alias ServiceInterfaceCb: PeerId, string, Interface -> () alias ServiceInterfaceCb: PeerId, []FakeTuple -> ()
alias Log: string -> ()
func collectServiceInterfaces(peer: PeerId, services: []Service, collectServiceInterface: ServiceInterfaceCb): service MyOp("op"):
for srv <- services par: array(i: Interface, s: string) -> FakeTuple
on peer:
func collectServiceInterfaces(peer: PeerId, services: []Service, collectServiceInterface: ServiceInterfaceCb, log: Log):
ifaces: *FakeTuple
on peer:
for srv <- services:
iface <- Srv.get_interface(srv.id) iface <- Srv.get_interface(srv.id)
collectServiceInterface(peer, srv.id, iface) ifaces <- MyOp.array(iface, srv.id)
collectServiceInterface(peer, ifaces)
func askAllAndSend(peer: PeerId, collectPeerInfo: PeerInfoCb, collectServiceInterface: ServiceInterfaceCb): func askAllAndSend(peer: PeerId, collectPeerInfo: PeerInfoCb, collectServiceInterface: ServiceInterfaceCb, log: Log):
on peer via HOST_PEER_ID: on peer via HOST_PEER_ID:
ident <- Peer.identify() ident <- Peer.identify()
blueprints <- Dist.list_blueprints() blueprints <- Dist.list_blueprints()
modules <- Dist.list_modules() modules <- Dist.list_modules()
services <- Srv.list() services <- Srv.list()
collectPeerInfo(peer, ident, services, blueprints, modules) co log("b4 collectPeerInfo")
collectServiceInterfaces(peer, services, collectServiceInterface) 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): func findAndAskNeighboursSchema(relayPeerId: PeerId, clientId: PeerId, collectPeerInfo: PeerInfoCb, collectServiceInterface: ServiceInterfaceCb, log: Log):
on relayPeerId: on relayPeerId:
neighbors <- Kademlia.neighborhood(clientId, nil, nil) neighbors <- Kademlia.neighborhood(clientId, nil, nil)
for n <- neighbors par: for n <- neighbors par:
on n: on n:
neighbors2 <- Kademlia.neighborhood(clientId, nil, nil) neighbors2 <- Kademlia.neighborhood(clientId, nil, nil)
for n2 <- neighbors2 par: for n2 <- neighbors2 par:
askAllAndSend(n2, collectPeerInfo, collectServiceInterface) askAllAndSend(n2, collectPeerInfo, collectServiceInterface, log)
func getAll(knownPeers: []PeerId, collectPeerInfo: PeerInfoCb, collectServiceInterface: ServiceInterfaceCb): func getAll(knownPeers: []PeerId, collectPeerInfo: PeerInfoCb, collectServiceInterface: ServiceInterfaceCb, log: Log):
on HOST_PEER_ID: on HOST_PEER_ID:
-- co askAllAndSend(relayPeerId, collectPeerInfo, collectServiceInterface) -- co askAllAndSend(relayPeerId, collectPeerInfo, collectServiceInterface)
@ -36,6 +46,6 @@ func getAll(knownPeers: []PeerId, collectPeerInfo: PeerInfoCb, collectServiceInt
-- we gather data from the known peers only. -- we gather data from the known peers only.
-- Known peers are explicitly represent the whole network atm -- Known peers are explicitly represent the whole network atm
for peer <- knownPeers par: for peer <- knownPeers par:
askAllAndSend(peer, collectPeerInfo, collectServiceInterface) askAllAndSend(peer, collectPeerInfo, collectServiceInterface, log)
-- co findAndAskNeighboursSchema(relayPeerId, %init_peer_id%, collectPeerInfo, collectServiceInterface) -- co findAndAskNeighboursSchema(relayPeerId, %init_peer_id%, collectPeerInfo, collectServiceInterface)

14
package-lock.json generated
View File

@ -18,7 +18,7 @@
"devDependencies": { "devDependencies": {
"@babel/core": "^7.11.6", "@babel/core": "^7.11.6",
"@babel/preset-env": "^7.11.5", "@babel/preset-env": "^7.11.5",
"@fluencelabs/aqua": "^0.4.0-235", "@fluencelabs/aqua": "^0.4.0-238",
"@fluencelabs/aqua-lib": "0.1.14", "@fluencelabs/aqua-lib": "0.1.14",
"@types/yup": "^0.29.11", "@types/yup": "^0.29.11",
"babel-loader": "^8.1.0", "babel-loader": "^8.1.0",
@ -1278,9 +1278,9 @@
} }
}, },
"node_modules/@fluencelabs/aqua": { "node_modules/@fluencelabs/aqua": {
"version": "0.4.0-235", "version": "0.4.0-238",
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua/-/aqua-0.4.0-235.tgz", "resolved": "https://registry.npmjs.org/@fluencelabs/aqua/-/aqua-0.4.0-238.tgz",
"integrity": "sha512-tbbHG3dhlwcSzlHMPoV4/MLW6JE00q3hiyznjLh+aW91ovBAXuWe5C1n9CKeRiJtYz3yIQCn2l3arI/PvzLx9Q==", "integrity": "sha512-vSie7LinYIF+WoCz16yVduGsjLL0JO6gNBi1q0WtHHXCZiLn7d7m+gNacVrIbPrI9bwUht0U6kJd6xFKqXBUhw==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@fluencelabs/fluence": "0.12.1" "@fluencelabs/fluence": "0.12.1"
@ -19450,9 +19450,9 @@
} }
}, },
"@fluencelabs/aqua": { "@fluencelabs/aqua": {
"version": "0.4.0-235", "version": "0.4.0-238",
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua/-/aqua-0.4.0-235.tgz", "resolved": "https://registry.npmjs.org/@fluencelabs/aqua/-/aqua-0.4.0-238.tgz",
"integrity": "sha512-tbbHG3dhlwcSzlHMPoV4/MLW6JE00q3hiyznjLh+aW91ovBAXuWe5C1n9CKeRiJtYz3yIQCn2l3arI/PvzLx9Q==", "integrity": "sha512-vSie7LinYIF+WoCz16yVduGsjLL0JO6gNBi1q0WtHHXCZiLn7d7m+gNacVrIbPrI9bwUht0U6kJd6xFKqXBUhw==",
"dev": true, "dev": true,
"requires": { "requires": {
"@fluencelabs/fluence": "0.12.1" "@fluencelabs/fluence": "0.12.1"

View File

@ -40,7 +40,7 @@
"devDependencies": { "devDependencies": {
"@babel/core": "^7.11.6", "@babel/core": "^7.11.6",
"@babel/preset-env": "^7.11.5", "@babel/preset-env": "^7.11.5",
"@fluencelabs/aqua": "^0.4.0-235", "@fluencelabs/aqua": "^0.4.0-238",
"@fluencelabs/aqua-lib": "0.1.14", "@fluencelabs/aqua-lib": "0.1.14",
"@types/yup": "^0.29.11", "@types/yup": "^0.29.11",
"babel-loader": "^8.1.0", "babel-loader": "^8.1.0",

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

@ -3,7 +3,7 @@
* This file is auto-generated. Do not edit manually: changes may be erased. * 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 * If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.4.0-235 * Aqua version: 0.4.0-238
* *
*/ */
import { Fluence, FluencePeer } from '@fluencelabs/fluence'; import { Fluence, FluencePeer } from '@fluencelabs/fluence';
@ -15,25 +15,32 @@ import {
// Services // 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<number>;
}
export function registerMyOp(service: MyOpDef): void;
export function registerMyOp(serviceId: string, service: MyOpDef): void;
export function registerMyOp(peer: FluencePeer, service: MyOpDef): void;
export function registerMyOp(peer: FluencePeer, serviceId: string, service: MyOpDef): void;
// Functions // Functions
export function collectServiceInterfaces(peer_: string, services: { blueprint_id: string; id: string; owner_id: string; }[], collectServiceInterface: (arg0: string, arg1: string, arg2: { function_signatures: { arguments: string[][]; name: string; output_types: string[]; }[]; record_types: { fields: string[][]; id: number; name: string; }[]; }, callParams: CallParams<'arg0' | 'arg1' | 'arg2'>) => void | Promise<void>, config?: {ttl?: number}): Promise<void>; export function collectServiceInterfaces(peer_: string, services: { blueprint_id: string; id: string; owner_id: string; }[], collectServiceInterface: (arg0: string, arg1: number[], callParams: CallParams<'arg0' | 'arg1'>) => void | Promise<void>, log: (arg0: string, callParams: CallParams<'arg0'>) => void | Promise<void>, config?: {ttl?: number}): Promise<void>;
export function collectServiceInterfaces(peer: FluencePeer, peer_: string, services: { blueprint_id: string; id: string; owner_id: string; }[], collectServiceInterface: (arg0: string, arg1: string, arg2: { function_signatures: { arguments: string[][]; name: string; output_types: string[]; }[]; record_types: { fields: string[][]; id: number; name: string; }[]; }, callParams: CallParams<'arg0' | 'arg1' | 'arg2'>) => void | Promise<void>, config?: {ttl?: number}): Promise<void>; export function collectServiceInterfaces(peer: FluencePeer, peer_: string, services: { blueprint_id: string; id: string; owner_id: string; }[], collectServiceInterface: (arg0: string, arg1: number[], callParams: CallParams<'arg0' | 'arg1'>) => void | Promise<void>, log: (arg0: string, callParams: CallParams<'arg0'>) => void | Promise<void>, config?: {ttl?: number}): Promise<void>;
export function askAllAndSend(peer_: string, collectPeerInfo: (arg0: string, arg1: { external_addresses: string[]; }, arg2: { blueprint_id: string; id: string; owner_id: string; }[], arg3: { dependencies: string[]; id: string; name: string; }[], arg4: { config: { name: string; }; hash: string; name: string; }[], callParams: CallParams<'arg0' | 'arg1' | 'arg2' | 'arg3' | 'arg4'>) => void | Promise<void>, collectServiceInterface: (arg0: string, arg1: string, arg2: { function_signatures: { arguments: string[][]; name: string; output_types: string[]; }[]; record_types: { fields: string[][]; id: number; name: string; }[]; }, callParams: CallParams<'arg0' | 'arg1' | 'arg2'>) => void | Promise<void>, config?: {ttl?: number}): Promise<void>; export function askAllAndSend(peer_: string, collectPeerInfo: (arg0: string, arg1: { external_addresses: string[]; }, arg2: { blueprint_id: string; id: string; owner_id: string; }[], arg3: { dependencies: string[]; id: string; name: string; }[], arg4: { config: { name: string; }; hash: string; name: string; }[], callParams: CallParams<'arg0' | 'arg1' | 'arg2' | 'arg3' | 'arg4'>) => void | Promise<void>, collectServiceInterface: (arg0: string, arg1: number[], callParams: CallParams<'arg0' | 'arg1'>) => void | Promise<void>, log: (arg0: string, callParams: CallParams<'arg0'>) => void | Promise<void>, config?: {ttl?: number}): Promise<void>;
export function askAllAndSend(peer: FluencePeer, peer_: string, collectPeerInfo: (arg0: string, arg1: { external_addresses: string[]; }, arg2: { blueprint_id: string; id: string; owner_id: string; }[], arg3: { dependencies: string[]; id: string; name: string; }[], arg4: { config: { name: string; }; hash: string; name: string; }[], callParams: CallParams<'arg0' | 'arg1' | 'arg2' | 'arg3' | 'arg4'>) => void | Promise<void>, collectServiceInterface: (arg0: string, arg1: string, arg2: { function_signatures: { arguments: string[][]; name: string; output_types: string[]; }[]; record_types: { fields: string[][]; id: number; name: string; }[]; }, callParams: CallParams<'arg0' | 'arg1' | 'arg2'>) => void | Promise<void>, config?: {ttl?: number}): Promise<void>; export function askAllAndSend(peer: FluencePeer, peer_: string, collectPeerInfo: (arg0: string, arg1: { external_addresses: string[]; }, arg2: { blueprint_id: string; id: string; owner_id: string; }[], arg3: { dependencies: string[]; id: string; name: string; }[], arg4: { config: { name: string; }; hash: string; name: string; }[], callParams: CallParams<'arg0' | 'arg1' | 'arg2' | 'arg3' | 'arg4'>) => void | Promise<void>, collectServiceInterface: (arg0: string, arg1: number[], callParams: CallParams<'arg0' | 'arg1'>) => void | Promise<void>, log: (arg0: string, callParams: CallParams<'arg0'>) => void | Promise<void>, config?: {ttl?: number}): Promise<void>;
export function findAndAskNeighboursSchema(relayPeerId: string, clientId: string, collectPeerInfo: (arg0: string, arg1: { external_addresses: string[]; }, arg2: { blueprint_id: string; id: string; owner_id: string; }[], arg3: { dependencies: string[]; id: string; name: string; }[], arg4: { config: { name: string; }; hash: string; name: string; }[], callParams: CallParams<'arg0' | 'arg1' | 'arg2' | 'arg3' | 'arg4'>) => void | Promise<void>, collectServiceInterface: (arg0: string, arg1: string, arg2: { function_signatures: { arguments: string[][]; name: string; output_types: string[]; }[]; record_types: { fields: string[][]; id: number; name: string; }[]; }, callParams: CallParams<'arg0' | 'arg1' | 'arg2'>) => void | Promise<void>, config?: {ttl?: number}): Promise<void>; export function findAndAskNeighboursSchema(relayPeerId: string, clientId: string, collectPeerInfo: (arg0: string, arg1: { external_addresses: string[]; }, arg2: { blueprint_id: string; id: string; owner_id: string; }[], arg3: { dependencies: string[]; id: string; name: string; }[], arg4: { config: { name: string; }; hash: string; name: string; }[], callParams: CallParams<'arg0' | 'arg1' | 'arg2' | 'arg3' | 'arg4'>) => void | Promise<void>, collectServiceInterface: (arg0: string, arg1: number[], callParams: CallParams<'arg0' | 'arg1'>) => void | Promise<void>, log: (arg0: string, callParams: CallParams<'arg0'>) => void | Promise<void>, config?: {ttl?: number}): Promise<void>;
export function findAndAskNeighboursSchema(peer: FluencePeer, relayPeerId: string, clientId: string, collectPeerInfo: (arg0: string, arg1: { external_addresses: string[]; }, arg2: { blueprint_id: string; id: string; owner_id: string; }[], arg3: { dependencies: string[]; id: string; name: string; }[], arg4: { config: { name: string; }; hash: string; name: string; }[], callParams: CallParams<'arg0' | 'arg1' | 'arg2' | 'arg3' | 'arg4'>) => void | Promise<void>, collectServiceInterface: (arg0: string, arg1: string, arg2: { function_signatures: { arguments: string[][]; name: string; output_types: string[]; }[]; record_types: { fields: string[][]; id: number; name: string; }[]; }, callParams: CallParams<'arg0' | 'arg1' | 'arg2'>) => void | Promise<void>, config?: {ttl?: number}): Promise<void>; export function findAndAskNeighboursSchema(peer: FluencePeer, relayPeerId: string, clientId: string, collectPeerInfo: (arg0: string, arg1: { external_addresses: string[]; }, arg2: { blueprint_id: string; id: string; owner_id: string; }[], arg3: { dependencies: string[]; id: string; name: string; }[], arg4: { config: { name: string; }; hash: string; name: string; }[], callParams: CallParams<'arg0' | 'arg1' | 'arg2' | 'arg3' | 'arg4'>) => void | Promise<void>, collectServiceInterface: (arg0: string, arg1: number[], callParams: CallParams<'arg0' | 'arg1'>) => void | Promise<void>, log: (arg0: string, callParams: CallParams<'arg0'>) => void | Promise<void>, config?: {ttl?: number}): Promise<void>;
export function getAll(knownPeers: string[], collectPeerInfo: (arg0: string, arg1: { external_addresses: string[]; }, arg2: { blueprint_id: string; id: string; owner_id: string; }[], arg3: { dependencies: string[]; id: string; name: string; }[], arg4: { config: { name: string; }; hash: string; name: string; }[], callParams: CallParams<'arg0' | 'arg1' | 'arg2' | 'arg3' | 'arg4'>) => void | Promise<void>, collectServiceInterface: (arg0: string, arg1: string, arg2: { function_signatures: { arguments: string[][]; name: string; output_types: string[]; }[]; record_types: { fields: string[][]; id: number; name: string; }[]; }, callParams: CallParams<'arg0' | 'arg1' | 'arg2'>) => void | Promise<void>, config?: {ttl?: number}): Promise<void>; export function getAll(knownPeers: string[], collectPeerInfo: (arg0: string, arg1: { external_addresses: string[]; }, arg2: { blueprint_id: string; id: string; owner_id: string; }[], arg3: { dependencies: string[]; id: string; name: string; }[], arg4: { config: { name: string; }; hash: string; name: string; }[], callParams: CallParams<'arg0' | 'arg1' | 'arg2' | 'arg3' | 'arg4'>) => void | Promise<void>, collectServiceInterface: (arg0: string, arg1: number[], callParams: CallParams<'arg0' | 'arg1'>) => void | Promise<void>, log: (arg0: string, callParams: CallParams<'arg0'>) => void | Promise<void>, config?: {ttl?: number}): Promise<void>;
export function getAll(peer: FluencePeer, knownPeers: string[], collectPeerInfo: (arg0: string, arg1: { external_addresses: string[]; }, arg2: { blueprint_id: string; id: string; owner_id: string; }[], arg3: { dependencies: string[]; id: string; name: string; }[], arg4: { config: { name: string; }; hash: string; name: string; }[], callParams: CallParams<'arg0' | 'arg1' | 'arg2' | 'arg3' | 'arg4'>) => void | Promise<void>, collectServiceInterface: (arg0: string, arg1: string, arg2: { function_signatures: { arguments: string[][]; name: string; output_types: string[]; }[]; record_types: { fields: string[][]; id: number; name: string; }[]; }, callParams: CallParams<'arg0' | 'arg1' | 'arg2'>) => void | Promise<void>, config?: {ttl?: number}): Promise<void>; export function getAll(peer: FluencePeer, knownPeers: string[], collectPeerInfo: (arg0: string, arg1: { external_addresses: string[]; }, arg2: { blueprint_id: string; id: string; owner_id: string; }[], arg3: { dependencies: string[]; id: string; name: string; }[], arg4: { config: { name: string; }; hash: string; name: string; }[], callParams: CallParams<'arg0' | 'arg1' | 'arg2' | 'arg3' | 'arg4'>) => void | Promise<void>, collectServiceInterface: (arg0: string, arg1: number[], callParams: CallParams<'arg0' | 'arg1'>) => void | Promise<void>, log: (arg0: string, callParams: CallParams<'arg0'>) => void | Promise<void>, config?: {ttl?: number}): Promise<void>;

View File

@ -3,7 +3,7 @@
* This file is auto-generated. Do not edit manually: changes may be erased. * 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 * If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.4.0-235 * Aqua version: 0.4.0-238
* *
*/ */
import { Fluence, FluencePeer } from '@fluencelabs/fluence'; import { Fluence, FluencePeer } from '@fluencelabs/fluence';
@ -16,6 +16,39 @@ import {
// Services // Services
export function registerMyOp(...args) {
registerService(
args,
{
"defaultServiceId" : "op",
"functions" : [
{
"functionName" : "array",
"argDefs" : [
{
"name" : "i",
"argType" : {
"tag" : "primitive"
}
},
{
"name" : "s",
"argType" : {
"tag" : "primitive"
}
}
],
"returnType" : {
"tag" : "primitive"
}
}
]
}
);
}
// Functions // Functions
export function collectServiceInterfaces(...args) { export function collectServiceInterfaces(...args) {
@ -25,31 +58,37 @@ export function collectServiceInterfaces(...args) {
(seq (seq
(seq (seq
(seq (seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "peer") [] peer)
)
(call %init_peer_id% ("getDataSrv" "services") [] services)
)
(fold services srv
(par
(seq (seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "peer") [] peer)
)
(call %init_peer_id% ("getDataSrv" "services") [] services)
)
(call -relay- ("op" "noop") []) (call -relay- ("op" "noop") [])
(xor )
(xor
(fold services srv
(seq (seq
(seq (seq
(call peer ("srv" "get_interface") [srv.$.id!] iface) (call peer ("srv" "get_interface") [srv.$.id!] iface)
(call -relay- ("op" "noop") []) (call peer ("op" "array") [iface srv.$.id!] $ifaces)
)
(xor
(call %init_peer_id% ("callbackSrv" "collectServiceInterface") [peer srv.$.id! iface])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
) )
(next srv)
) )
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2]) )
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
) )
) )
(next srv)
) )
(call -relay- ("op" "noop") [])
)
(xor
(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% 3]) (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
@ -92,9 +131,22 @@ export function collectServiceInterfaces(...args) {
"argType" : { "argType" : {
"tag" : "primitive" "tag" : "primitive"
} }
}, }
],
"returnType" : {
"tag" : "void"
}
}
}
},
{
"name" : "log",
"argType" : {
"tag" : "callback",
"callback" : {
"argDefs" : [
{ {
"name" : "arg2", "name" : "arg0",
"argType" : { "argType" : {
"tag" : "primitive" "tag" : "primitive"
} }
@ -141,46 +193,44 @@ export function askAllAndSend(...args) {
(seq (seq
(seq (seq
(seq (seq
(seq (call peer ("peer" "identify") [] ident)
(call peer ("peer" "identify") [] ident) (call peer ("dist" "list_blueprints") [] blueprints)
(call peer ("dist" "list_blueprints") [] blueprints)
)
(call peer ("dist" "list_modules") [] modules)
) )
(call peer ("srv" "list") [] services) (call peer ("dist" "list_modules") [] modules)
) )
(call -relay- ("op" "noop") []) (call peer ("srv" "list") [] services)
) )
(xor (par
(call %init_peer_id% ("callbackSrv" "collectPeerInfo") [peer ident services blueprints modules]) (seq
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1]) (call -relay- ("op" "noop") [])
(xor
(call %init_peer_id% ("callbackSrv" "log") ["b4 collectPeerInfo"])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
(null)
) )
) )
(call -relay- ("op" "noop") [])
)
(fold services srv
(par (par
(seq (seq
(call -relay- ("op" "noop") []) (call -relay- ("op" "noop") [])
(xor (xor
(seq (call %init_peer_id% ("callbackSrv" "collectPeerInfo") [peer ident services blueprints modules])
(seq (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
(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])
) )
) )
(seq (null)
(call -relay- ("op" "noop") []) )
(next srv) )
(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)
) )
) )
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4]) (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
@ -263,9 +313,22 @@ export function askAllAndSend(...args) {
"argType" : { "argType" : {
"tag" : "primitive" "tag" : "primitive"
} }
}, }
],
"returnType" : {
"tag" : "void"
}
}
}
},
{
"name" : "log",
"argType" : {
"tag" : "callback",
"callback" : {
"argDefs" : [
{ {
"name" : "arg2", "name" : "arg0",
"argType" : { "argType" : {
"tag" : "primitive" "tag" : "primitive"
} }
@ -309,82 +372,101 @@ export function findAndAskNeighboursSchema(...args) {
(call -relay- ("op" "noop") []) (call -relay- ("op" "noop") [])
) )
(xor (xor
(seq (par
(call relayPeerId ("kad" "neighborhood") [clientId [] []] neighbors) (seq
(fold neighbors n (seq
(par (call -relay- ("op" "noop") [])
(xor (call relayPeerId ("kad" "neighborhood") [clientId [] []] neighbors)
)
(call %init_peer_id% ("op" "noop") [])
)
(seq
(call -relay- ("op" "noop") [])
(fold neighbors n
(par
(seq (seq
(call n ("kad" "neighborhood") [clientId [] []] neighbors2) (call -relay- ("op" "noop") [])
(fold neighbors2 n2 (xor
(par (par
(seq
(seq
(call -relay- ("op" "noop") [])
(call n ("kad" "neighborhood") [clientId [] []] neighbors2)
)
(call %init_peer_id% ("op" "noop") [])
)
(seq (seq
(call -relay- ("op" "noop") []) (call -relay- ("op" "noop") [])
(xor (fold neighbors2 n2
(seq (par
(seq (seq
(seq (call -relay- ("op" "noop") [])
(xor
(seq (seq
(seq (seq
(seq (seq
(seq (seq
(call n2 ("peer" "identify") [] ident) (seq
(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 ("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)
) )
(call n2 ("dist" "list_modules") [] modules)
) )
(call n2 ("srv" "list") [] services) (par
)
(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 (seq
(call n2 ("srv" "get_interface") [srv.$.id!] iface)
(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% 2])
)
) )
(null)
)
)
(par
(seq
(call -relay- ("op" "noop") [])
(xor (xor
(call %init_peer_id% ("callbackSrv" "collectServiceInterface") [n2 srv.$.id! iface]) (call %init_peer_id% ("callbackSrv" "log") ["b4 collectServiceInterfaces"])
(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]) (null)
) )
) )
(seq (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
(call -relay- ("op" "noop") [])
(next srv)
)
) )
) )
) (seq
(seq (call -relay- ("op" "noop") [])
(call -relay- ("op" "noop") []) (next n2)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4]) )
) )
) )
) )
(next n2)
) )
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5])
) )
) )
(seq (seq
(call -relay- ("op" "noop") []) (call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5]) (next n)
) )
) )
(next n)
) )
) )
) )
@ -474,9 +556,22 @@ export function findAndAskNeighboursSchema(...args) {
"argType" : { "argType" : {
"tag" : "primitive" "tag" : "primitive"
} }
}, }
],
"returnType" : {
"tag" : "void"
}
}
}
},
{
"name" : "log",
"argType" : {
"tag" : "callback",
"callback" : {
"argDefs" : [
{ {
"name" : "arg2", "name" : "arg0",
"argType" : { "argType" : {
"tag" : "primitive" "tag" : "primitive"
} }
@ -514,12 +609,12 @@ export function getAll(...args) {
(call %init_peer_id% ("getDataSrv" "knownPeers") [] knownPeers) (call %init_peer_id% ("getDataSrv" "knownPeers") [] knownPeers)
) )
(xor (xor
(fold knownPeers peer (par
(par (fold knownPeers peer
(seq (par
(call -relay- ("op" "noop") []) (seq
(xor (call -relay- ("op" "noop") [])
(seq (xor
(seq (seq
(seq (seq
(seq (seq
@ -533,45 +628,46 @@ export function getAll(...args) {
) )
(call peer ("srv" "list") [] services) (call peer ("srv" "list") [] services)
) )
(call -relay- ("op" "noop") []) (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)
)
) )
(xor (par
(call %init_peer_id% ("callbackSrv" "collectPeerInfo") [peer ident services blueprints modules]) (seq
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1]) (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)
) )
) )
(call -relay- ("op" "noop") [])
)
(fold services srv
(par (par
(seq (seq
(call -relay- ("op" "noop") []) (call -relay- ("op" "noop") [])
(xor (xor
(seq (call %init_peer_id% ("callbackSrv" "log") ["b4 collectServiceInterfaces"])
(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 (null)
(call -relay- ("op" "noop") [])
(next srv)
)
) )
) )
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
) )
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
) )
(next peer)
) )
(next peer)
) )
(null)
) )
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5]) (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5])
) )
@ -653,9 +749,22 @@ export function getAll(...args) {
"argType" : { "argType" : {
"tag" : "primitive" "tag" : "primitive"
} }
}, }
],
"returnType" : {
"tag" : "void"
}
}
}
},
{
"name" : "log",
"argType" : {
"tag" : "callback",
"callback" : {
"argDefs" : [
{ {
"name" : "arg2", "name" : "arg0",
"argType" : { "argType" : {
"tag" : "primitive" "tag" : "primitive"
} }

View File

@ -30,8 +30,9 @@ import { askAllAndSend, getAll } from './_aqua/app';
const defaultNetworkName = 'testNet + krasnodar'; const defaultNetworkName = 'testNet + krasnodar';
const defaultEnv = { const defaultEnv = {
relays: [...testNet, ...krasnodar, ...stage], //relays: [...testNet, ...krasnodar, ...stage],
relayIdx: 2, relays: [krasnodar[0]],
relayIdx: 0,
logLevel: 'error', logLevel: 'error',
}; };
@ -115,7 +116,8 @@ function genFlags(peerId, relays, relayIdx) {
const { relays, relayIdx, logLevel } = await initEnvironment(); const { relays, relayIdx, logLevel } = await initEnvironment();
setLogLevel(logLevel); setLogLevel(logLevel);
const keyPair = await KeyPair.randomEd25519(); const keyPair = await KeyPair.randomEd25519();
await Fluence.start({ connectTo: relays[relayIdx].multiaddr }); await Fluence.start({ connectTo: relays[relayIdx].multiaddr, defaultTtlMs: 200000 });
// await Fluence.start({ connectTo: relays[relayIdx].multiaddr });
const pid = Fluence.getStatus().peerId; const pid = Fluence.getStatus().peerId;
const flags = genFlags(pid, relays, relayIdx); const flags = genFlags(pid, relays, relayIdx);
console.log(`Own peer id: ${pid}`); console.log(`Own peer id: ${pid}`);
@ -128,16 +130,17 @@ function genFlags(peerId, relays, relayIdx) {
}); });
// alias ServiceInterfaceCb: PeerId, string, Interface -> () // alias ServiceInterfaceCb: PeerId, string, Interface -> ()
function collectServiceInterface(peer_id, service_id, iface) { function collectServiceInterface(peer_id, ifaces) {
// console.count(`service interface from ${peer_id}`); // console.count(`service interface from ${peer_id}`);
try { try {
const eventRaw = { for (var iface of ifaces) {
peer_id, const eventRaw = {
service_id, peer_id,
interface: iface, service_id: iface[1],
}; interface: iface[0],
};
app.ports.collectServiceInterface.send(eventRaw); app.ports.collectServiceInterface.send(eventRaw);
}
} catch (err) { } catch (err) {
log.error('Elm eventreceiver failed: ', err); log.error('Elm eventreceiver failed: ', err);
} }
@ -168,7 +171,8 @@ function genFlags(peerId, relays, relayIdx) {
// }); // });
// } // }
await getAll(data.knownPeers, collectPeerInfo, collectServiceInterface, { ttl: 120000 }); console.log('called getAll');
await getAll(Fluence.getPeer(), data.knownPeers, collectPeerInfo, collectServiceInterface, console.log);
}); });
})(); })();