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)
|
||||
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",
|
||||
|
@ -43,7 +43,6 @@ export function collect_timestamps_from_neighborhood(...args: any) {
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("op" "string_to_b58") [-relay-] k)
|
||||
@ -89,12 +88,21 @@ export function collect_timestamps_from_neighborhood(...args: any) {
|
||||
)
|
||||
(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 %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
(call %init_peer_id% ("op" "identity") [$dead_peers] dead_peers-fix)
|
||||
)
|
||||
)
|
||||
@ -105,11 +113,11 @@ 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% 5])
|
||||
)
|
||||
`
|
||||
return callFunction(
|
||||
args,
|
||||
|
Loading…
Reference in New Issue
Block a user