repo: veilid-hacks action: blob revision: path_from: veilid-dht-create revision_from: refs/heads/trunk: path_to: revision_to:
blob of:
/ veilid-dht-create
refs/heads/trunk:/veilid-dht-create
#!/usr/bin/env bash export keys_dir=~/projects/veilid-hacks/keys mkdir -p "$keys_dir" if [ "$1" = "-h" ];then printf 'usage: veilid-dht-create [] [ ]\n' >&2 exit 1 fi if [ "$1" != "socat" ];then export schema="${1:-DFLT}" export subkeys="${2:-1}" export input="$*" exec socat "tcp:${VEILID_SERVER:-127.0.0.1:5959}" exec:"$0 socat" 2>&1 else shift fi printf '{"op":"NewRoutingContext"}\n' state=0 stdbuf -oL jq -nc 'inputs | select(.type != "Update")' | while read -r line;do #printf 'state: %d line: %s\n' "$state" "$line" >&2 case "$state" in 0) rc_id="$(jq -r .value <<< "${line}")" printf '{"op":"RoutingContext","rc_id":%d,"rc_op":"CreateDhtRecord","schema":{"kind":"%s","o_cnt":%d}}\n' "${rc_id}" "${schema}" "${subkeys}" ### response to this looks like this: # {"type":"Response","id":0,"op":"RoutingContext","rc_id":1,"rc_op":"CreateDhtRecord","value":{"key":"VLD0:-x87x-BrIh4XGFhjBfGH6hC27srwakESZwZtTrQbrIo","owner":"YT_hQeImsibNdtul_fvR2VYa5UYV2HQTc1yZYcisOPE","owner_secret":"HT4hC6j7tFJ2Bz3iPrQvtpFm6bdVgcAk0m-GK5NuzX4","schema":{"kind":"DFLT","o_cnt":1}}} ;; 1) ### now to store the response into the keys dir... key="$(jq -r .value.key <<< "$line" | cut -d: -f2)" owner="$(jq -r .value.owner <<< "$line")" owner_secret="$(jq -r .value.owner_secret <<< "$line")" key_file="${keys_dir}/${key}" printf "%s:%s\n" "${owner}" "${owner_secret}" > "${key_file}" printf 'VLD0:%s\n' "${key}" >&2 printf '\nQUIT :what? this isnt woodshop?\r\n' ;; *) echo 'state: ' "$state" >&2 ;; esac state=$[$state+1] done #| tee /dev/stderr