examples/fuzz-client
2022-04-07 17:30:12 +04:00
..
aqua Do not join if neighborhood is empty 2022-04-07 17:30:12 +04:00
dist/src init 2022-02-07 18:39:56 -06:00
docker add docker 2022-03-29 18:59:34 -05:00
src Do not join if neighborhood is empty 2022-04-07 17:30:12 +04:00
package-lock.json Refactor fuzzing: pass relay address, allow to enable debug logs 2022-04-04 18:02:44 +04:00
package.json Do not join if neighborhood is empty 2022-04-07 17:30:12 +04:00
README.md add readme 2022-02-07 23:19:48 -06:00
tsconfig.json init 2022-02-07 18:39:56 -06:00

Test Client

Overview

In aqua/timestamp_gatherer.aqua we provide a simple timestamp getter function, ts_getter. ts_getter illustrates how to use the builtin timstamp function with Aqua.

-- aqua/timestamp_gatherer.aqua
-- simple timestamp getter for kademlia neighborhood which is max size 20
func ts_getter() -> []u64:
  -- on this peer
  on HOST_PEER_ID:
    -- convert peer id to b58
    k <- Op.string_to_b58(HOST_PEER_ID)
    -- get all neighbors
    nodes <- Kademlia.neighborhood(k, nil, nil)
    res: *u64
    -- for each neighbor
    for n <- nodes par:
      -- on selected neighbor peer
      on n:
        -- get the timestamp from that node
        res <- Peer.timestamp_ms()
      -- hot fix to force switching to peer
      Op.noop()
    -- join the results, which is tricky right now since we can't use array len
    -- the testnet size n is 10 so n -1
    join res[9]
  <- res

This function works well under optimal conditions but is problematic in reality where peers drop-off or disappear. We can use timeouts and some creative array filling to accommodate response variability while still getting our join to complete:


-- 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

We can execute Aqua with the Fluence JS client:

npm i
npm run compile-aqua
npm start

or from the command line:

aqua run \
     --addr /dns4/kras-05.fluence.dev/tcp/19001/wss/p2p/12D3KooWCMr9mU894i8JXAFqpgoFtx6qnV1LFPSfVc3Y34N4h4LS \
     -i aqua \
     -f 'ts_getter()'

and:

aqua run \
     --addr /dns4/kras-05.fluence.dev/tcp/19001/wss/p2p/12D3KooWCMr9mU894i8JXAFqpgoFtx6qnV1LFPSfVc3Y34N4h4LS \
     -i aqua \
     -f 'ts_getter_with_timeout()'