mirror of
https://github.com/fluencelabs/examples
synced 2024-12-04 19:20:17 +00:00
Do not join if neighborhood is empty
This commit is contained in:
parent
6763ea05d5
commit
90d428fd62
@ -31,42 +31,6 @@ func collect_timestamps_from_neighborhood() -> []u64, []PeerId:
|
||||
|
||||
-- wait for all nodes to respond or timeout
|
||||
length <- Op.array_length(nodes)
|
||||
join statuses[length - 1]
|
||||
if length != 0:
|
||||
join statuses[length - 1]
|
||||
<- timestamps, dead_peers
|
||||
|
||||
|
||||
|
||||
-- -- timestamp getter with error collector over neighborhood
|
||||
-- func ts_getter_with_timeout()-> []u64, []string:
|
||||
-- -- timeout in ms
|
||||
-- rtt = 1000
|
||||
|
||||
-- res: *u64
|
||||
|
||||
-- -- error value for no timestamp
|
||||
-- err_value = 0
|
||||
|
||||
-- -- neighborhood n = 20 decr by 1 for array
|
||||
-- n_neighborhood = 19
|
||||
|
||||
-- -- err message
|
||||
-- msg = "timeout"
|
||||
|
||||
-- -- collect non-responsive peer ids, if any
|
||||
-- dead_peers: *string
|
||||
-- on HOST_PEER_ID:
|
||||
-- k <- Op.string_to_b58(HOST_PEER_ID)
|
||||
-- nodes <- Kademlia.neighborhood(k, nil, nil)
|
||||
-- for n <- nodes par:
|
||||
-- status: *string
|
||||
-- on n:
|
||||
-- res <- Peer.timestamp_ms()
|
||||
-- status <<- "success"
|
||||
-- par status <- Peer.timeout(rtt, msg)
|
||||
-- if status! != "success":
|
||||
-- res <<- err_value
|
||||
-- dead_peers <<- n
|
||||
-- Op.noop()
|
||||
|
||||
-- join res[n_neighborhood]
|
||||
-- <- res, dead_peers
|
||||
|
@ -20,7 +20,8 @@
|
||||
"scripts": {
|
||||
"start": "node -r ts-node/register src/index.ts",
|
||||
"compile-aqua": "aqua -i aqua -o src/_aqua/",
|
||||
"watch-aqua": "chokidar \"**/*.aqua\" -c \"npm run compile-aqua\""
|
||||
"watch-aqua": "chokidar \"**/*.aqua\" -c \"npm run compile-aqua\"",
|
||||
"buildpush": "docker build -f docker/Dockerfile -t fluencelabs/anti-fuzz . && docker push fluencelabs/anti-fuzz"
|
||||
},
|
||||
"keywords": [
|
||||
"aqua",
|
||||
|
@ -45,55 +45,63 @@ export function collect_timestamps_from_neighborhood(...args: any) {
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("op" "string_to_b58") [-relay-] k)
|
||||
(call -relay- ("kad" "neighborhood") [k [] []] nodes)
|
||||
)
|
||||
(par
|
||||
(fold nodes n
|
||||
(par
|
||||
(new $status
|
||||
(call -relay- ("op" "string_to_b58") [-relay-] k)
|
||||
(call -relay- ("kad" "neighborhood") [k [] []] nodes)
|
||||
)
|
||||
(par
|
||||
(fold nodes n
|
||||
(par
|
||||
(new $status
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(par
|
||||
(xor
|
||||
(seq
|
||||
(call n ("peer" "timestamp_ms") [] $timestamps)
|
||||
(ap "ok" $status)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
(par
|
||||
(xor
|
||||
(seq
|
||||
(call n ("peer" "timestamp_ms") [] $timestamps)
|
||||
(ap "ok" $status)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
(call -relay- ("peer" "timeout") [2000 "timed out"] $status)
|
||||
)
|
||||
(call -relay- ("op" "identity") [$status.$.[0]!] push-to-stream-30)
|
||||
(call -relay- ("peer" "timeout") [2000 "timed out"] $status)
|
||||
)
|
||||
(ap push-to-stream-30 $statuses)
|
||||
(call -relay- ("op" "identity") [$status.$.[0]!] push-to-stream-30)
|
||||
)
|
||||
(xor
|
||||
(mismatch $status.$.[0]! "ok"
|
||||
(ap n $dead_peers)
|
||||
)
|
||||
(null)
|
||||
(ap push-to-stream-30 $statuses)
|
||||
)
|
||||
(xor
|
||||
(mismatch $status.$.[0]! "ok"
|
||||
(ap n $dead_peers)
|
||||
)
|
||||
(null)
|
||||
)
|
||||
)
|
||||
(next n)
|
||||
)
|
||||
(next n)
|
||||
)
|
||||
(null)
|
||||
)
|
||||
(null)
|
||||
)
|
||||
(call -relay- ("op" "array_length") [nodes] length)
|
||||
)
|
||||
(call -relay- ("math" "sub") [length 1] sub)
|
||||
(call -relay- ("op" "array_length") [nodes] length)
|
||||
)
|
||||
(xor
|
||||
(mismatch length 0
|
||||
(xor
|
||||
(seq
|
||||
(call -relay- ("math" "sub") [length 1] sub)
|
||||
(call -relay- ("op" "noop") [$statuses.$.[sub]!])
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(null)
|
||||
)
|
||||
(call -relay- ("op" "noop") [$statuses.$.[sub]!])
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
(call %init_peer_id% ("op" "identity") [$dead_peers] dead_peers-fix)
|
||||
)
|
||||
@ -105,10 +113,10 @@ export function collect_timestamps_from_neighborhood(...args: any) {
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [timestamps-fix dead_peers-fix])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5])
|
||||
)
|
||||
`
|
||||
return callFunction(
|
||||
|
Loading…
Reference in New Issue
Block a user