-- Leo's gemini proxy
-- Connecting to git.thebackupbox.net:1965...
-- Connected
-- Sending request
-- Meta line: 20 text/gemini
repo: veilid-hacks action: blob revision: path_from: veilid-dht-set revision_from: refs/heads/trunk: path_to: revision_to:
/ veilid-dht-set
refs/heads/trunk:/veilid-dht-set #!/usr/bin/env bash export keys_dir=~/projects/veilid-hacks/keys if [ ! "$1" ];then printf 'usage: veilid-dht-set <key>[/subkey] <value>\n' >&2 exit 1 fi if [ "$1" != "socat" ];then export key="$(printf "%s" "$1" | cut -d/ -f1)" if grep '/' <<< "$1" 2>&1 >/dev/null;then export subkey="$(printf "%s" "$1" | cut -d/ -f2)" else export subkey=0 fi shift export input="$*" # echo "key: $key" # echo "subkey: $subkey" # echo "input: $input" exec socat "tcp:${VEILID_SERVER:-127.0.0.1:5959}" exec:"$0 socat" 2>&1 else shift fi data="$(printf '%s' "$input" | enb64url | tr -d '\n' | sed 's/=*$//' | tr -d '\n' )" ### the input data needs to be base64url'd and stripped writer="$(head -n1 "${keys_dir}/${key}")" 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 '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":"OpenDhtRecord","key":"%s","writer":"%s"}\n' "${rc_id}" "${key}" "${writer}" ;; 1) ## state: 1 line: {"type":"Response","id":0,"op":"RoutingContext","rc_id":1,"rc_op":"OpenDhtRecord","value":{"key":"VLD0:1eimAUnFTwpATw-uyWjkPqGh3o20StlvejgCQ2KQEEo","owner":"8XrAbqEuCywkjcuc8I2C9Wfweb2NbG9ZuCq2vjM_oZY","owner_secret":null,"schema":{"kind":"DFLT","o_cnt":1}}} printf '{"op":"RoutingContext","rc_id":%d,"rc_op":"SetDhtValue","data":"%s","key":"%s","subkey":%d}\n' "${rc_id}" "${data}" "${key}" "${subkey}" ;; 2) #jq -r '.value.data' <<< "$line" | ./pad 4 = | base64 -d >&2 #printf '\n' >&2 #just because it is weird not having a newline at the end of stuff. printf '{"op":"RoutingContext","rc_id":%d,"rc_op":"CloseDhtRecord","key":"%s"}\n' "${rc_id}" "${key}" ;; 3) 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" # } #}
-- Response ended
-- Page fetched on Sun Jun 2 12:15:55 2024