Use callbacks instead of service

This commit is contained in:
folex 2021-07-07 17:27:46 +03:00
parent 0d676ed46a
commit b9a1d148f1
4 changed files with 519 additions and 280 deletions

View File

@ -1,39 +1,38 @@
import "@fluencelabs/aqua-lib/builtin.aqua"
service DashboardEvent("event"):
collectPeerInfo(peer: PeerId, ident: Info, services: []Service, blueprints: []Blueprint, modules: []Module)
collectServiceInterface(peer: PeerId, serviceId: string, iface: Interface)
alias PeerInfoCb: PeerId, Info, []Service, []Blueprint, []Module -> ()
alias ServiceInterfaceCb: PeerId, string, Interface -> ()
func collectServiceInterfaces(peer: PeerId, services: []Service):
func collectServiceInterfaces(peer: PeerId, services: []Service, collectServiceInterface: ServiceInterfaceCb):
for srv <- services par:
on peer:
iface <- Srv.get_interface(srv.id)
DashboardEvent.collectServiceInterface(peer, srv.id, iface)
collectServiceInterface(peer, srv.id, iface)
func askAllAndSend(peer: PeerId):
func askAllAndSend(peer: PeerId, collectPeerInfo: PeerInfoCb, collectServiceInterface: ServiceInterfaceCb):
on peer:
ident <- Peer.identify()
blueprints <- Dist.list_blueprints()
modules <- Dist.list_modules()
services <- Srv.list()
DashboardEvent.collectPeerInfo(peer, ident, services, blueprints, modules)
collectServiceInterfaces(peer, services)
collectPeerInfo(peer, ident, services, blueprints, modules)
Peer.timestamp_ms()
collectServiceInterfaces(peer, services, collectServiceInterface)
func findAndAskNeighboursSchema(relayPeerId: PeerId, clientId: PeerId):
on relayPeerId:
neighbors <- Kademlia.neighborhood(clientId, false)
for n <- neighbors par:
on n:
neighbors2 <- Kademlia.neighborhood(clientId, false)
for n2 <- neighbors2 par:
askAllAndSend(n2)
-- func findAndAskNeighboursSchema(relayPeerId: PeerId, clientId: PeerId):
-- on relayPeerId:
-- neighbors <- Kademlia.neighborhood(clientId, false)
-- for n <- neighbors par:
-- on n:
-- neighbors2 <- Kademlia.neighborhood(clientId, false)
-- for n2 <- neighbors2 par:
-- askAllAndSend(n2)
func getAll(relayPeerId: PeerId, knownPeers: []PeerId):
askAllAndSend(relayPeerId)
func getAll(relayPeerId: PeerId, knownPeers: []PeerId, collectPeerInfo: PeerInfoCb, collectServiceInterface: ServiceInterfaceCb):
-- co askAllAndSend(relayPeerId, collectPeerInfo, collectServiceInterface)
for peer <- knownPeers par:
askAllAndSend(peer)
-- par findAndAskNeighboursSchema(relayPeerId, %init_peer_id%)
askAllAndSend(peer, collectPeerInfo, collectServiceInterface)
-- co findAndAskNeighboursSchema(relayPeerId, %init_peer_id%)

321
package-lock.json generated
View File

@ -2846,6 +2846,12 @@
}
}
},
"charenc": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/charenc/-/charenc-0.0.2.tgz",
"integrity": "sha1-wKHS86cJLgN3S/qD8UwPxXkKhmc=",
"dev": true
},
"check-error": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz",
@ -3772,6 +3778,12 @@
"sha.js": "^2.4.8"
}
},
"crocks": {
"version": "0.12.1",
"resolved": "https://registry.npmjs.org/crocks/-/crocks-0.12.1.tgz",
"integrity": "sha512-2qCRJwBmPlRQXzd50k9gt9PaItultOP8lj/cKSH2Eai9aeBuNqAnDuyolAm9TGn6Pw/4BgbxtPJLU1S+tQ4WMQ==",
"dev": true
},
"cross-spawn": {
"version": "7.0.3",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
@ -3782,6 +3794,12 @@
"which": "^2.0.1"
}
},
"crypt": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/crypt/-/crypt-0.0.2.tgz",
"integrity": "sha1-iNf/fsDfuG9xPch7u0LQRNPmxBs=",
"dev": true
},
"crypto-browserify": {
"version": "3.12.0",
"resolved": "https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-3.12.0.tgz",
@ -4925,6 +4943,258 @@
"elm-hot": "^1.1.5"
}
},
"elm-live": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/elm-live/-/elm-live-4.0.2.tgz",
"integrity": "sha512-4I3UvJxF6MubC14VsgtV11B0zBxaaKtdKKsWquoaa5a3UHBIGW83qgTnt/NxOj4omOLfupaftmDaE4yRMTgTcw==",
"dev": true,
"requires": {
"chalk": "^1.1.1",
"chokidar": "3.0.2",
"commander": "2.17.1",
"crocks": "0.12.1",
"cross-spawn": "5.0.1",
"elm-hot": "1.1.4",
"finalhandler": "1.1.2",
"http-proxy": "1.17.0",
"internal-ip": "4.3.0",
"mime": "2.4.3",
"open": "6.4.0",
"pem": "1.14.2",
"serve-static": "1.14.1",
"ws": "7.1.1"
},
"dependencies": {
"ansi-styles": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz",
"integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=",
"dev": true
},
"anymatch": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.2.tgz",
"integrity": "sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg==",
"dev": true,
"requires": {
"normalize-path": "^3.0.0",
"picomatch": "^2.0.4"
}
},
"binary-extensions": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz",
"integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==",
"dev": true
},
"braces": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
"integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
"dev": true,
"requires": {
"fill-range": "^7.0.1"
}
},
"chalk": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
"integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
"dev": true,
"requires": {
"ansi-styles": "^2.2.1",
"escape-string-regexp": "^1.0.2",
"has-ansi": "^2.0.0",
"strip-ansi": "^3.0.0",
"supports-color": "^2.0.0"
}
},
"chokidar": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.0.2.tgz",
"integrity": "sha512-c4PR2egjNjI1um6bamCQ6bUNPDiyofNQruHvKgHQ4gDUP/ITSVSzNsiI5OWtHOsX323i5ha/kk4YmOZ1Ktg7KA==",
"dev": true,
"requires": {
"anymatch": "^3.0.1",
"braces": "^3.0.2",
"fsevents": "^2.0.6",
"glob-parent": "^5.0.0",
"is-binary-path": "^2.1.0",
"is-glob": "^4.0.1",
"normalize-path": "^3.0.0",
"readdirp": "^3.1.1"
}
},
"commander": {
"version": "2.17.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.17.1.tgz",
"integrity": "sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg==",
"dev": true
},
"cross-spawn": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.0.1.tgz",
"integrity": "sha1-o7uzAtsil8vqPATt82lB9GE6o5k=",
"dev": true,
"requires": {
"lru-cache": "^4.0.1",
"shebang-command": "^1.2.0",
"which": "^1.2.9"
}
},
"elm-hot": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/elm-hot/-/elm-hot-1.1.4.tgz",
"integrity": "sha512-qPDP/o/Fkifriaxaf3E7hHFB5L6Ijihyg8is4A6xna6/h/zebUiNssbQrxywI2oxNUkr6W/leEu/WlIC1tmVnw==",
"dev": true
},
"eventemitter3": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-3.1.2.tgz",
"integrity": "sha512-tvtQIeLVHjDkJYnzf2dgVMxfuSGJeM/7UCG17TT4EumTfNtF+0nebF/4zWOIkCreAbtNqhGEboB6BWrwqNaw4Q==",
"dev": true
},
"fill-range": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
"integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==",
"dev": true,
"requires": {
"to-regex-range": "^5.0.1"
}
},
"fsevents": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
"dev": true,
"optional": true
},
"glob-parent": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz",
"integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==",
"dev": true,
"requires": {
"is-glob": "^4.0.1"
}
},
"http-proxy": {
"version": "1.17.0",
"resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.17.0.tgz",
"integrity": "sha512-Taqn+3nNvYRfJ3bGvKfBSRwy1v6eePlm3oc/aWVxZp57DQr5Eq3xhKJi7Z4hZpS8PC3H4qI+Yly5EmFacGuA/g==",
"dev": true,
"requires": {
"eventemitter3": "^3.0.0",
"follow-redirects": "^1.0.0",
"requires-port": "^1.0.0"
}
},
"is-binary-path": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz",
"integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==",
"dev": true,
"requires": {
"binary-extensions": "^2.0.0"
}
},
"is-number": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
"integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==",
"dev": true
},
"lru-cache": {
"version": "4.1.5",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz",
"integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==",
"dev": true,
"requires": {
"pseudomap": "^1.0.2",
"yallist": "^2.1.2"
}
},
"mime": {
"version": "2.4.3",
"resolved": "https://registry.npmjs.org/mime/-/mime-2.4.3.tgz",
"integrity": "sha512-QgrPRJfE+riq5TPZMcHZOtm8c6K/yYrMbKIoRfapfiGLxS8OTeIfRhUGW5LU7MlRa52KOAGCfUNruqLrIBvWZw==",
"dev": true
},
"readdirp": {
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz",
"integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==",
"dev": true,
"requires": {
"picomatch": "^2.2.1"
}
},
"shebang-command": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz",
"integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=",
"dev": true,
"requires": {
"shebang-regex": "^1.0.0"
}
},
"shebang-regex": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz",
"integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=",
"dev": true
},
"strip-ansi": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
"dev": true,
"requires": {
"ansi-regex": "^2.0.0"
}
},
"supports-color": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz",
"integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=",
"dev": true
},
"to-regex-range": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
"integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==",
"dev": true,
"requires": {
"is-number": "^7.0.0"
}
},
"which": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz",
"integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==",
"dev": true,
"requires": {
"isexe": "^2.0.0"
}
},
"ws": {
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.1.1.tgz",
"integrity": "sha512-o41D/WmDeca0BqYhsr3nJzQyg9NF5X8l/UdnFNux9cS3lwB+swm8qGWX5rn+aD6xfBU3rGmtHij7g7x6LxFU3A==",
"dev": true,
"requires": {
"async-limiter": "^1.0.0"
}
},
"yallist": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz",
"integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=",
"dev": true
}
}
},
"elm-test": {
"version": "0.19.1-revision4",
"resolved": "https://registry.npmjs.org/elm-test/-/elm-test-0.19.1-revision4.tgz",
@ -8797,6 +9067,25 @@
"object-visit": "^1.0.0"
}
},
"md5": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/md5/-/md5-2.3.0.tgz",
"integrity": "sha512-T1GITYmFaKuO91vxyoQMFETst+O71VUPEU3ze5GNzDm0OWdP8v1ziTaAEPUr/3kLsY3Sftgz242A1SetQiDL7g==",
"dev": true,
"requires": {
"charenc": "0.0.2",
"crypt": "0.0.2",
"is-buffer": "~1.1.6"
},
"dependencies": {
"is-buffer": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==",
"dev": true
}
}
},
"md5.js": {
"version": "1.3.5",
"resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz",
@ -10206,6 +10495,15 @@
"mimic-fn": "^2.1.0"
}
},
"open": {
"version": "6.4.0",
"resolved": "https://registry.npmjs.org/open/-/open-6.4.0.tgz",
"integrity": "sha512-IFenVPgF70fSm1keSd2iDBIDIBZkroLeuffXq+wKTzTJlBpesFWojV9lb8mzOfaAzM1sr7HQHuO0vtV0zYekGg==",
"dev": true,
"requires": {
"is-wsl": "^1.1.0"
}
},
"opn": {
"version": "5.4.0",
"resolved": "https://registry.npmjs.org/opn/-/opn-5.4.0.tgz",
@ -10657,6 +10955,29 @@
}
}
},
"pem": {
"version": "1.14.2",
"resolved": "https://registry.npmjs.org/pem/-/pem-1.14.2.tgz",
"integrity": "sha512-TOnPtq3ZFnCniOZ+rka4pk8UIze9xG1qI+wNE7EmkiR/cg+53uVvk5QbkWZ7M6RsuOxzz62FW1hlAobJr/lTOA==",
"dev": true,
"requires": {
"es6-promisify": "^6.0.0",
"md5": "^2.2.1",
"os-tmpdir": "^1.0.1",
"which": "^1.3.1"
},
"dependencies": {
"which": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz",
"integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==",
"dev": true,
"requires": {
"isexe": "^2.0.0"
}
}
}
},
"pem-jwk": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/pem-jwk/-/pem-jwk-2.0.0.tgz",

View File

@ -10,7 +10,7 @@ import { RequestFlowBuilder } from '@fluencelabs/fluence/dist/api.unstable';
export async function collectServiceInterfaces(client, peer, services, config) {
export async function collectServiceInterfaces(client, peer, services, collectServiceInterface, config) {
let request;
config = config || {};
const promise = new Promise((resolve, reject) => {
@ -30,26 +30,26 @@ export async function collectServiceInterfaces(client, peer, services, config) {
(fold services srv
(par
(seq
(seq
(call -relay- ("op" "noop") [])
(xor
(seq
(call -relay- ("op" "noop") [])
(xor
(seq
(call peer ("srv" "get_interface") [srv.$.id!] iface)
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
(call -relay- ("op" "noop") [])
)
(xor
(call %init_peer_id% ("callbackSrv" "collectServiceInterface") [peer srv.$.id! iface])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
(call %init_peer_id% ("event" "collectServiceInterface") [peer srv.$.id! iface])
)
(next srv)
)
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)
`,
@ -60,6 +60,7 @@ export async function collectServiceInterfaces(client, peer, services, config) {
});
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.onEvent('errorHandlingSrv', 'error', (args) => {
// assuming error is the single argument
@ -82,7 +83,7 @@ h.on('getDataSrv', 'services', () => {return services;});
export async function askAllAndSend(client, peer, config) {
export async function askAllAndSend(client, peer, collectPeerInfo, collectServiceInterface, config) {
let request;
config = config || {};
const promise = new Promise((resolve, reject) => {
@ -93,59 +94,62 @@ export async function askAllAndSend(client, peer, config) {
(xor
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "peer") [] peer)
)
(call -relay- ("op" "noop") [])
)
(xor
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "peer") [] peer)
)
(call -relay- ("op" "noop") [])
)
(xor
(seq
(seq
(seq
(call peer ("peer" "identify") [] ident)
(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)
)
(call peer ("dist" "list_modules") [] modules)
(call -relay- ("op" "noop") [])
)
(call peer ("srv" "list") [] services)
)
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
)
(call -relay- ("op" "noop") [])
)
(call %init_peer_id% ("event" "collectPeerInfo") [peer ident services blueprints modules])
)
(fold services srv
(par
(seq
(seq
(seq
(call -relay- ("op" "noop") [])
(xor
(call peer ("srv" "get_interface") [srv.$.id!] iface)
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
(call %init_peer_id% ("callbackSrv" "collectPeerInfo") [peer ident services blueprints modules])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
(call -relay- ("op" "noop") [])
)
(call %init_peer_id% ("event" "collectServiceInterface") [peer srv.$.id! iface])
(call peer ("peer" "timestamp_ms") [])
)
(fold services srv
(par
(xor
(seq
(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])
)
(next srv)
)
)
(next srv)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5])
)
`,
@ -155,6 +159,8 @@ export async function askAllAndSend(client, peer, config) {
return client.relayPeerId;
});
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.onEvent('errorHandlingSrv', 'error', (args) => {
// assuming error is the single argument
@ -177,7 +183,7 @@ export async function askAllAndSend(client, peer, config) {
export async function findAndAskNeighboursSchema(client, relayPeerId, clientId, config) {
export async function getAll(client, relayPeerId, knownPeers, collectPeerInfo, collectServiceInterface, config) {
let request;
config = config || {};
const promise = new Promise((resolve, reject) => {
@ -189,230 +195,62 @@ export async function findAndAskNeighboursSchema(client, relayPeerId, clientId,
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "relayPeerId") [] relayPeerId)
)
(call %init_peer_id% ("getDataSrv" "clientId") [] clientId)
)
(call -relay- ("op" "noop") [])
)
(xor
(seq
(call relayPeerId ("kad" "neighborhood") [clientId false] neighbors)
(fold neighbors n
(par
(xor
(seq
(call n ("kad" "neighborhood") [clientId false] neighbors2)
(fold neighbors2 n2
(par
(seq
(seq
(xor
(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)
)
(seq
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
(call -relay- ("op" "noop") [])
)
)
(call n ("event" "collectPeerInfo") [n2 ident services blueprints modules])
)
(fold services srv
(par
(seq
(xor
(call n2 ("srv" "get_interface") [srv.$.id!] iface)
(seq
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
(call -relay- ("op" "noop") [])
)
)
(call n ("event" "collectServiceInterface") [n2 srv.$.id! iface])
)
(next srv)
)
)
)
(next n2)
)
)
)
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)
)
(next n)
)
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5])
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return client.relayPeerId;
});
h.on('getDataSrv', 'relayPeerId', () => {return relayPeerId;});
h.on('getDataSrv', 'clientId', () => {return clientId;});
h.onEvent('errorHandlingSrv', 'error', (args) => {
// assuming error is the single argument
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for findAndAskNeighboursSchema');
})
if(config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
await client.initiateFlow(request);
return Promise.race([promise, Promise.resolve()]);
}
export async function getAll(client, relayPeerId, knownPeers, config) {
let request;
config = config || {};
const promise = new Promise((resolve, reject) => {
var r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "relayPeerId") [] relayPeerId)
)
(call %init_peer_id% ("getDataSrv" "knownPeers") [] knownPeers)
)
(call -relay- ("op" "noop") [])
)
(xor
(seq
(seq
(seq
(call relayPeerId ("peer" "identify") [] ident)
(call relayPeerId ("dist" "list_blueprints") [] blueprints)
)
(call relayPeerId ("dist" "list_modules") [] modules)
)
(call relayPeerId ("srv" "list") [] services)
)
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
)
(call -relay- ("op" "noop") [])
)
(call %init_peer_id% ("event" "collectPeerInfo") [relayPeerId ident services blueprints modules])
)
(fold services srv
(par
(seq
(seq
(seq
(call -relay- ("op" "noop") [])
(xor
(call relayPeerId ("srv" "get_interface") [srv.$.id!] iface)
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
)
)
(call -relay- ("op" "noop") [])
)
(call %init_peer_id% ("event" "collectServiceInterface") [relayPeerId srv.$.id! iface])
)
(next srv)
)
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "relayPeerId") [] relayPeerId)
)
(call %init_peer_id% ("getDataSrv" "knownPeers") [] knownPeers)
)
(fold knownPeers peer
(par
(seq
(seq
(call -relay- ("op" "noop") [])
(xor
(seq
(seq
(call -relay- ("op" "noop") [])
(xor
(seq
(seq
(seq
(call peer ("peer" "identify") [] ident0)
(call peer ("dist" "list_blueprints") [] blueprints0)
)
(call peer ("dist" "list_modules") [] modules0)
)
(call peer ("srv" "list") [] services0)
)
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)
)
)
(call -relay- ("op" "noop") [])
)
(call %init_peer_id% ("event" "collectPeerInfo") [peer ident0 services0 blueprints0 modules0])
)
(fold services0 srv0
(par
(seq
(seq
(seq
(call -relay- ("op" "noop") [])
(xor
(call peer ("srv" "get_interface") [srv0.$.id!] iface0)
(seq
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
(seq
(seq
(call peer ("peer" "identify") [] ident)
(call peer ("dist" "list_blueprints") [] blueprints)
)
(call peer ("dist" "list_modules") [] modules)
)
(call peer ("srv" "list") [] services)
)
(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])
)
)
(call -relay- ("op" "noop") [])
)
(call %init_peer_id% ("event" "collectServiceInterface") [peer srv0.$.id! iface0])
(call peer ("peer" "timestamp_ms") [])
)
(fold services srv
(par
(xor
(seq
(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])
)
(next srv)
)
)
(next srv0)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
)
)
(next peer)
@ -430,6 +268,8 @@ export async function getAll(client, relayPeerId, knownPeers, config) {
});
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.onEvent('errorHandlingSrv', 'error', (args) => {
// assuming error is the single argument

View File

@ -20,7 +20,7 @@ import './main.css';
// eslint-disable-next-line import/no-extraneous-dependencies
import log from 'loglevel';
import Multiaddr from 'multiaddr';
import { dev, krasnodar } from '@fluencelabs/fluence-network-environment';
import { krasnodar, Node } from '@fluencelabs/fluence-network-environment';
import {
createClient,
generatePeerId,
@ -36,9 +36,24 @@ import { getAll } from './_aqua/app';
const defaultNetworkName = 'krasnodar';
const localEnv = [
{
peerId: '12D3KooWHBG9oaVx4i3vi6c1rSBUm7MLBmyGmmbHoZ23pmjDCnvK',
multiaddr: '/ip4/127.0.0.1/tcp/9990/ws/p2p/12D3KooWHBG9oaVx4i3vi6c1rSBUm7MLBmyGmmbHoZ23pmjDCnvK',
},
{
peerId: '12D3KooWRABanQHUn28dxavN9ZS1zZghqoZVAYtFpoN7FdtoGTFv',
multiaddr: '/ip4/127.0.0.1/tcp/9991/ws/p2p/12D3KooWRABanQHUn28dxavN9ZS1zZghqoZVAYtFpoN7FdtoGTFv',
},
{
peerId: '12D3KooWFpQ7LHxcC9FEBUh3k4nSCC12jBhijJv3gJbi7wsNYzJ5',
multiaddr: '/ip4/127.0.0.1/tcp/9992/ws/p2p/12D3KooWFpQ7LHxcC9FEBUh3k4nSCC12jBhijJv3gJbi7wsNYzJ5',
},
];
const defaultEnv = {
relays: krasnodar,
relayIdx: 3,
relayIdx: 0,
logLevel: 'error',
};
@ -169,8 +184,45 @@ function genFlags(peerId, relays, relayIdx) {
}
});
// alias PeerInfoCb: PeerId, Info, []Service, []Blueprint, []Module -> ()
// alias ServiceInterfaceCb: PeerId, string, Interface -> ()
function collectServiceInterface(peer_id, service_id, iface) {
console.count(`service interface from ${peer_id}`);
return;
try {
const eventRaw = {
peer_id,
service_id,
interface: iface,
};
app.ports.collectServiceInterface.send(eventRaw);
} catch (err) {
log.error('Elm eventreceiver failed: ', err);
}
}
function collectPeerInfo(peerId, identify, services, blueprints, modules, interfaces) {
console.log('peer info from %s, %s services', peerId, services.length);
try {
const eventRaw = {
peerId,
identify,
services,
blueprints,
modules,
};
app.ports.collectPeerInfo.send(eventRaw);
} catch (err) {
log.error('Elm eventreceiver failed: ', err);
}
}
app.ports.getAll.subscribe(async (data) => {
await getAll(client, data.relayPeerId, data.knownPeers, { ttl: 1000000 });
await getAll(client, data.relayPeerId, data.knownPeers, collectPeerInfo, collectServiceInterface, {
ttl: 1000000,
});
});
})();
@ -178,3 +230,30 @@ function genFlags(peerId, relays, relayIdx) {
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();
/*
peer info from 12D3KooWSD5PToNiLQwKDXsu8JSysCwUt8BVUJEqCHcDe7P5h45e, 34 services
peer info from 12D3KooWKnEqMfYo9zvfHmqTLpLdiHXPe4SVqUWcWHDJdFGrSmcA, 22 services
peer info from 12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt, 23 services
peer info from 12D3KooWR4cv1a8tv7pps4HH6wePNaK6gf1Hww5wcCMzeWxyNw51, 20 services
peer info from 12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE, 28 services
peer info from 12D3KooWCMr9mU894i8JXAFqpgoFtx6qnV1LFPSfVc3Y34N4h4LS, 18 services
peer info from 12D3KooWEFFCZnar1cUJQ3rMWjvPQg6yMV2aXWs2DkJNSRbduBWn, 25 services
peer info from 12D3KooWFEwNWcHqi9rtsmDhsYcDbRUCDXH84RC4FW6UfsFWaoHi, 24 services
peer info from 12D3KooWDUszU2NeWyUVjCXhGEt1MoZrhvdmaQQwtZUriuGN1jTr, 24 services
peer info from 12D3KooWHLxVhUQyAuZe6AHMB29P7wkvTNMn7eDMcsqimJYLKREf, 50 services
peer info from 12D3KooWD7CvsYcpF9HE9CCV9aY3SJ317tkXVykjtZnht2EbzDPm, 17 services
/dns4/kras-00.fluence.dev/tcp/19990/wss/p2p/12D3KooWSD5PToNiLQwKDXsu8JSysCwUt8BVUJEqCHcDe7P5h45e
/dns4/kras-02.fluence.dev/tcp/19001/wss/p2p/12D3KooWHLxVhUQyAuZe6AHMB29P7wkvTNMn7eDMcsqimJYLKREf
/dns4/kras-03.fluence.dev/tcp/19001/wss/p2p/12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE
/dns4/kras-00.fluence.dev/tcp/19001/wss/p2p/12D3KooWR4cv1a8tv7pps4HH6wePNaK6gf1Hww5wcCMzeWxyNw51
/dns4/kras-01.fluence.dev/tcp/19001/wss/p2p/12D3KooWKnEqMfYo9zvfHmqTLpLdiHXPe4SVqUWcWHDJdFGrSmcA
/dns4/kras-04.fluence.dev/tcp/19001/wss/p2p/12D3KooWFEwNWcHqi9rtsmDhsYcDbRUCDXH84RC4FW6UfsFWaoHi
/dns4/kras-05.fluence.dev/tcp/19001/wss/p2p/12D3KooWCMr9mU894i8JXAFqpgoFtx6qnV1LFPSfVc3Y34N4h4LS
/dns4/kras-06.fluence.dev/tcp/19001/wss/p2p/12D3KooWDUszU2NeWyUVjCXhGEt1MoZrhvdmaQQwtZUriuGN1jTr
/dns4/kras-07.fluence.dev/tcp/19001/wss/p2p/12D3KooWEFFCZnar1cUJQ3rMWjvPQg6yMV2aXWs2DkJNSRbduBWn
/dns4/kras-08.fluence.dev/tcp/19001/wss/p2p/12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt
/dns4/kras-09.fluence.dev/tcp/19001/wss/p2p/12D3KooWD7CvsYcpF9HE9CCV9aY3SJ317tkXVykjtZnht2EbzDPm
*/