#!/usr/bin/env bash if [ "$1" != "socat" ];then exec socat "tcp:${VEILID_SERVER:-127.0.0.1:5959}" exec:"$0 socat $*" 2>&1 else shift fi key="${1:-1eimAUnFTwpATw-uyWjkPqGh3o20StlvejgCQ2KQEEo}" subkey="${2:-0}" printf '{"op":"NewRoutingContext"}\n' state=0 stdbuf -oL jq -nc 'inputs | select(.type != "Update")' | while read -r line;do #type="$(jq -r .type <<< "$line")" #if [ "$type" == "Update" ];then # continue #fi #printf 'line: %s\n' "$line" >&2 case "$state" in 0) rc_id=1 printf '{"op":"RoutingContext","rc_id":%d,"rc_op":"CloseDhtRecord","key":"%s"}\n' "${rc_id}" "${key}" ;; 1) printf '\nQUIT :what? this isnt woodshop?\r\n' ;; *) echo 'state: ' "$state" >&2 ;; esac state=$[$state+1] done # | tee /dev/stderr #{ # "type": "Response", # "id": 0, # "op": "RoutingContext", # "rc_id": 1, # "rc_op": "GetDhtValue", # "value": { # "seq": 1, # "data": "ZXBvY2ggd2FzIGhlcmUgOik", # "writer": "8XrAbqEuCywkjcuc8I2C9Wfweb2NbG9ZuCq2vjM_oZY" # } #}