repo: veilid-hacks action: blob revision: path_from: netchat-watch-appmsgs revision_from: refs/heads/trunk: path_to: revision_to:
blob of:
/ netchat-watch-appmsgs
refs/heads/trunk:/netchat-watch-appmsgs
#!/usr/bin/env bash
export keys_dir=~/projects/veilid-hacks/keys
### make a new route with which to receive messages
route_blob="$(veilid-new-private-route | tail -n1)"
if [ ! "$route_blob" ];then
printf "failed to create a new private route.\n" >&2
exit 1
fi
printf 'created private route. blob:\n\n%s\n\n' "${route_blob}" >&2
### publish our route blob to the DHT for others to find.
### we want to reuse one for our netchat if it already exists.
if [ ! -e ${keys_dir}/netchat ];then
printf 'no netchat DHT key found. creating a new one.\n' >&2
veilid-dht-create | cut -d: -f2 > ${keys_dir}/netchat
else
printf 'using previously created netchat DHT key\n' >&2
fi
key="$(cat "${keys_dir}/netchat")"
if [ ! "$key" ];then
printf "failed to create dht key for your route blob\n" >&2
exit 2
fi
printf "DHT key: %s\n" "${key}" >&2
veilid-dht-set "${key}" "netchat ${route_blob}"
while [ "$(veilid-dht-get "${key}")" != "netchat ${route_blob}" ];do
printf "waiting for DHT to sync with the new route...\n" >&2
sleep 1
done
printf "stored route blob into DHT key.\n" "${key}" >&2
### import our own route... because.
route_id="$(netchat-add-route-blob "${route_blob}")"
printf "imported route to ourself.. for reasons: %s\n" "${route_id}"
if [ ! "$route_id" ];then
printf 'failed to import remote private route: %s\n' "${route_blob}" >&2
exit 4
fi
printf "now watching for appmsgs...\n" >&2
veilid-watch-appmsgs