-- Leo's gemini proxy

-- Connecting to git.thebackupbox.net:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

repo: veilid-hacks
action: commit
revision:
path_from:
revision_from: 99de4d976d7c729d324eeef84b09faa8ec0ca420:
path_to:
revision_to:

git.thebackupbox.net

veilid-hacks

git://git.thebackupbox.net/veilid-hacks

commit 99de4d976d7c729d324eeef84b09faa8ec0ca420
Author: epoch <epoch@thebackupbox.net>
Date:   Thu Sep 7 03:18:12 2023 -0500

    netchat updates making it easier to add peers you know the route blob for. netchat-send uses local list instead of asking DHT all the time.

diff --git a/netchat-add-route-blob b/netchat-add-route-blob
new file mode 100644
index 0000000000000000000000000000000000000000..7a47a118367077aa1edf5e25175f65d58e744e38
--- /dev/null
+++ b/netchat-add-route-blob
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+
+if [ ! "$1" ];then
+  printf "usage: netchat-add-route-blob <route-blob>\n" >&2
+  exit 1
+fi
+
+route_blob="$1"
+
+route_id="$(veilid-import-remote-private-route "${route_blob}")"
+printf '%s\n' "${route_blob}" > ~/projects/veilid-hacks/netsend_routes/"${route_id}"
diff --git a/netchat-discover b/netchat-discover
new file mode 100755
index 0000000000000000000000000000000000000000..f80e3461e19fd3a52f3d33c0df0ff6b520b33562
--- /dev/null
+++ b/netchat-discover
@@ -0,0 +1,49 @@
+#!/usr/bin/env bash
+
+## todo, probably make this use netchat-add-route-blob
+
+if [ "$1" = "-h" -o "$1" = "--help" ];then
+  printf "usage: netchat-send [-h|--help|-g|--global] <message>\n"
+  exit 1
+fi
+
+if [ "$1" = "-g" -o "$1" = "--global" ];then
+  check_remote=1
+  shift
+else
+  check_remote=0
+fi
+
+printf 'finding routes in local DHT keys...\n' >&2
+
+### import all of the local DHT keys first and only bother to do it once.
+for i in $(veilid-dht-list-local);do \
+  route_blob="$(veilid-dht-get "$i" | grep '^netchat ' | cut '-d ' -f2)"
+  [ "${route_blob}" ] || continue
+  route_id="$(veilid-import-remote-private-route "${route_blob}")"
+  [ "${route_id}" ] || continue
+  route_file=~/projects/veilid-hacks/netchat_routes/"${route_id}"
+  [ -e "${route_file}" ] && continue
+  printf "adding ${route_id} to netchat's known routes\n" >&2
+  printf '%s\n' "${route_blob}" > "${route_file}"
+done
+
+### only new keys will end up needing to be watched and looped over
+
+if [ "$check_remote" = "0" ];then
+  printf 'not finding routes in remote DHT keys. use -g for that.\n' >&2
+  exit 0
+fi
+
+printf 'finding routes in remote DHT keys...\n' >&2
+
+for i in $(veilid-dht-list-remote);do
+  route_blob="$(veilid-dht-get "$i" | grep '^netchat ' | cut '-d ' -f2)"
+  [ "${route_blob}" ] || continue
+  route_id="$(veilid-import-remote-private-route "${route_blob}")"
+  [ "${route_id}" ] || continue
+  route_file=~/projects/veilid-hacks/netchat_routes/"${route_id}"
+  [ -e "${route_file}" ] && continue
+  printf "adding ${route_id} to netchat's known routes\n" >&2
+  printf '%s\n' "${route_blob}" > "${route_file}"
+done
diff --git a/netchat-send b/netchat-send

index cc8a3ff57a38a66d2d7a95b9876c4454383552f4..

index ..8e7bdb078a4c8d9cee722e4f3cbefe930e853e11 100755

--- a/netchat-send
+++ b/netchat-send
@@ -1,41 +1,8 @@
 #!/usr/bin/env bash

-if [ "$1" = "-h" -o "$1" = "--help" ];then
-  printf "usage: netchat-send [-h|--help|-g|--global] <message>\n"
-  exit 1
-fi
-
-if [ "$1" = "-g" -o "$1" = "--global" ];then
-  check_remote=1
-  shift
-else
-  check_remote=0
-fi
-
-printf 'sending to local DHT keys...\n' >&2
-
-### import all of the local DHT keys first and only bother to do it once.
-for i in $(veilid-dht-list-local);do \
-  route_blob="$(veilid-dht-get "$i" | grep '^netchat ' | cut '-d ' -f2)"
-  [ "${route_blob}" ] || continue
-  route_id="$(veilid-import-remote-private-route "${route_blob}")"
-  [ "${route_id}" ] || continue
-  veilid-appmessage "${route_id}" "$*"
-done
-
-### only new keys will end up needing to be watched and looped over
-
-if [ "$check_remote" = "0" ];then
-  printf 'not sending to remote DHT keys. use -g for that.\n' >&2
-  exit 0
-fi
-
-printf 'sending to remote DHT keys...\n' >&2
-
-for i in $(veilid-dht-list-remote);do
-  route_blob="$(veilid-dht-get "$i" | grep '^netchat ' | cut '-d ' -f2)"
-  [ "${route_blob}" ] || continue
-  route_id="$(veilid-import-remote-private-route "${route_blob}")"
-  [ "${route_id}" ] || continue
+for i in ~/projects/veilid-hacks/netchat_routes/*;do
+  blob="$(cat "$i")"
+  route_id="$(veilid-import-remote-private-route "$blob")"
+  printf 'sending to: %s\n' "${route_id}" >&2
   veilid-appmessage "${route_id}" "$*"
 done
diff --git a/veilid-dht-get b/veilid-dht-get

index 70813273b3c3fc5fbd6fb03b0d676d397f3bbc1e..

index ..fa77a7f0baf3331c707fbae8a6caae543cda0769 100755

--- a/veilid-dht-get
+++ b/veilid-dht-get
@@ -34,20 +34,31 @@ stdbuf -oL jq -nc 'inputs | select(.type != "Update")' | while read -r line;do
       printf '{"op":"RoutingContext","rc_id":%d,"rc_op":"OpenDhtRecord","key":"%s"}\n' "${rc_id}" "${key}"
     ;;
     1)
-      printf '{"op":"RoutingContext","rc_id":%d,"rc_op":"GetDhtValue","key":"%s","subkey":%d,"force_refresh":false}\n' "${rc_id}" "${key}" "${subkey}"
+      error="$(jq -r '.error.kind//""' <<< "$line")"
+      if [ "$error" ];then
+        printf '\nQUIT :what? this isnt woodshop?\r\n'
+      else
+        printf '{"op":"RoutingContext","rc_id":%d,"rc_op":"GetDhtValue","key":"%s","subkey":%d,"force_refresh":true}\n' "${rc_id}" "${key}" "${subkey}"
+      fi
     ;;
     2)
       error="$(jq -r '.error.kind//""' <<< "$line")"
       if [ "$error" ];then
-        printf '\nQUIT :what? this isnt woodshop?\r\n'
-        #printf 'error: %s' "$error" >&2
+        printf '{"op":"RoutingContext","rc_id":%d,"rc_op":"GetDhtValue","key":"%s","subkey":%d,"force_refresh":false}\n' "${rc_id}" "${key}" "${subkey}"
       else
         jq -r '.value.data' <<< "$line" | deb64url >&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}"
       fi
-      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)
+      error="$(jq -r '.error.kind//""' <<< "$line")"
+      if [ "$error" ];then
+        printf '{"op":"RoutingContext","rc_id":%d,"rc_op":"GetDhtValue","key":"%s","subkey":%d,"force_refresh":false}\n' "${rc_id}" "${key}" "${subkey}"
+      else
+        jq -r '.value.data' <<< "$line" | deb64url >&2
+        printf '\n' >&2 #just because it is weird not having a newline at the end of stuff.
+      fi
       printf '\nQUIT :what? this isnt woodshop?\r\n'
     ;;
     *)
diff --git a/veilid-import-remote-private-route b/veilid-import-remote-private-route

index 1a67cdea9f590b5c56bc6b7708c32802f0284c91..

index ..6b2194aabaa4446af12c7cb1bcfe307164221ef1 100755

--- a/veilid-import-remote-private-route
+++ b/veilid-import-remote-private-route
@@ -23,7 +23,7 @@ stdbuf -oL jq -nc 'inputs | select(.type != "Update")' | while read -r line;do
 ### what is the response of this look like?
 # {"type":"Response","id":0,"op":"ImportRemotePrivateRoute","value":"6_Xd6hQO27s3p3FSXLkZF0xYeVcNYF4zTzJz8eR_f8M"}
       route_id="$(jq -r .value <<< "${line}")"
-      printf '%s' "${route_id}" >&2
+      printf '%s\n' "${route_id}" >&2
       printf '\nQUIT :what? this isnt woodshop?\r\n'
 #    ;;
 #    *)

-----END OF PAGE-----

-- Response ended

-- Page fetched on Sun Jun 2 18:16:39 2024