From 90d428fd62cff49d3cbd84515a6417f75a062e61 Mon Sep 17 00:00:00 2001 From: folex <0xdxdy@gmail.com> Date: Thu, 7 Apr 2022 17:30:12 +0400 Subject: [PATCH] Do not join if neighborhood is empty --- fuzz-client/aqua/timestamp_gatherer.aqua | 40 +---------- fuzz-client/package.json | 3 +- fuzz-client/src/_aqua/timestamp_gatherer.ts | 78 ++++++++++++--------- 3 files changed, 47 insertions(+), 74 deletions(-) diff --git a/fuzz-client/aqua/timestamp_gatherer.aqua b/fuzz-client/aqua/timestamp_gatherer.aqua index 5ff1549..50c2dc9 100644 --- a/fuzz-client/aqua/timestamp_gatherer.aqua +++ b/fuzz-client/aqua/timestamp_gatherer.aqua @@ -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 diff --git a/fuzz-client/package.json b/fuzz-client/package.json index c43757b..708f852 100644 --- a/fuzz-client/package.json +++ b/fuzz-client/package.json @@ -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", diff --git a/fuzz-client/src/_aqua/timestamp_gatherer.ts b/fuzz-client/src/_aqua/timestamp_gatherer.ts index 7855fe3..1943e5a 100644 --- a/fuzz-client/src/_aqua/timestamp_gatherer.ts +++ b/fuzz-client/src/_aqua/timestamp_gatherer.ts @@ -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(