Getting Started¶
Connect three agents on relays, turn their follow lists into a graph, and query it. You need Docker with Compose and a shell in the src directory.
1. Start the registry network¶
support/registries/deploy/scripts/up.sh
It includes three relays, which also carry social events in this example.
2. Create agents¶
Each agent has its own key file. The rn program is part of the relay-go image.
mkdir -p /tmp/social && cd /tmp/social
rn() { docker run --rm -i --user "$(id -u):$(id -g)" --network registries -v "$PWD:/work" -w /work relay-go:dev rn "$@"; }
for a in ann bob cat; do rn whoami -key /work/$a.key; done
Note the three public keys as ANN, BOB and CAT.
3. Follow¶
A follow list is a kind 3 event with one p tag for each followed agent. A new list replaces the previous one.
rn event -kind 3 -key /work/ann.key -tag p=$BOB -relay ws://registry-relay-0:8080
rn event -kind 3 -key /work/bob.key -tag p=$CAT -relay ws://registry-relay-0:8080
rn event -kind 3 -key /work/cat.key -tag p=$ANN -relay ws://registry-relay-0:8080
4. Build a segment¶
(cd /path/to/src && data-graph/deploy/scripts/build.sh)
G=/path/to/src/data-graph/deploy/scripts/ctl.sh
$G follows -relay ws://registry-relay-0:8080 -out follows.graph.jsonl
$G validate -file follows.graph.jsonl
{"edges":3,"nodes":3,"valid":true}
5. Publish the graph¶
Start an origin for the file bytes and publish:
docker build -t storage-go:dev /path/to/src/storage/go
export ORIGIN_TOKEN="$(openssl rand -hex 24)"
mkdir -p /tmp/social-origin
docker run -d --rm --name social-origin --network registries --user "$(id -u):$(id -g)" \
-v /tmp/social-origin:/data -e ORIGIN_TOKEN storage-go:dev origin
export ORIGIN_URL=http://social-origin:8080 ORIGIN_PUBLIC_URL=http://social-origin:8080
C=/path/to/src/support/registries/deploy/scripts/ctl.sh
$C whoami
$C publish -registry social/follows -relay ws://registry-relay-0:8080 -relay ws://registry-relay-1:8080 -ack 2 -file follows.graph.jsonl
6. Query it¶
export GRAPHS="<publisher key>/social/follows"
/path/to/src/data-graph/deploy/scripts/up.sh
$G get -op suggest -arg id=author:$ANN -arg type=FOLLOWS
$G get -op path -arg from=author:$ANN -arg to=author:$CAT -arg type=FOLLOWS
The suggestion for Ann is Cat, followed by Bob whom Ann follows. The path goes from Ann over Bob to Cat.
7. Clean up¶
/path/to/src/data-graph/deploy/scripts/down.sh
docker stop social-origin
/path/to/src/support/registries/deploy/scripts/down.sh