|
| 1 | +#!/bin/bash |
| 2 | +printf "\nAssuming you already have a docker network called waku\n" |
| 3 | +# if not something like this should create it: docker network create --driver bridge --subnet 172.18.0.0/16 --gateway 172.18.0.1 waku |
| 4 | + |
| 5 | +cluster_id=4 |
| 6 | +pubsub_topic="/waku/2/rs/$cluster_id/0" |
| 7 | +encoded_pubsub_topic=$(echo "$pubsub_topic" | sed 's:/:%2F:g') |
| 8 | +node_1=wakuorg/go-waku:latest |
| 9 | +node_2=wakuorg/go-waku:latest |
| 10 | +node_1_ip=172.18.45.95 |
| 11 | + |
| 12 | +printf "\nStarting Bootstrap Node\n" |
| 13 | +container_id1=$(docker run -d -i -t -p 12297:12297 -p 12298:12298 -p 12299:12299 -p 12300:12300 -p 12301:12301 $node_1 --listen-address=0.0.0.0 --rest=true --rest-admin=true --websocket-support=true --log-level=DEBUG --rest-relay-cache-capacity=100 --websocket-port=12299 --rest-port=12297 --tcp-port=12298 --discv5-udp-port=12300 --rest-address=0.0.0.0 --nat=extip:$node_1_ip --peer-exchange=true --discv5-discovery=true --cluster-id=$cluster_id --relay=true --store=true --nodekey=30348dd51465150e04a5d9d932c72864c8967f806cce60b5d26afeca1e77eb68) |
| 14 | +docker network connect --ip $node_1_ip waku $container_id1 |
| 15 | +sleep 1 |
| 16 | + |
| 17 | +info1=$(curl -X GET "http://127.0.0.1:12297/debug/v1/info" -H "accept: application/json") |
| 18 | +enrUri=$(echo $info1 | jq -r '.enrUri') |
| 19 | + |
| 20 | +printf "\nStarting Second Node\n" |
| 21 | +container_id2=$(docker run -d -i -t -p 8158:8158 -p 8159:8159 -p 8160:8160 -p 8161:8161 -p 8162:8162 $node_2 --listen-address=0.0.0.0 --rest=true --rest-admin=true --websocket-support=true --log-level=DEBUG --rest-relay-cache-capacity=100 --websocket-port=8160 --rest-port=8158 --tcp-port=8159 --discv5-udp-port=8161 --rest-address=0.0.0.0 --nat=extip:172.18.207.159 --peer-exchange=true --discv5-discovery=true --cluster-id=$cluster_id --relay=true --discv5-bootstrap-node=$enrUri) |
| 22 | +docker network connect --ip 172.18.207.159 waku $container_id2 |
| 23 | +sleep 1 |
| 24 | + |
| 25 | +printf "\nSubscribe\n" |
| 26 | +curl -X POST "http://127.0.0.1:12297/relay/v1/subscriptions" -H "Content-Type: application/json" -d "[\"$pubsub_topic\"]" |
| 27 | +curl -X POST "http://127.0.0.1:8158/relay/v1/subscriptions" -H "Content-Type: application/json" -d "[\"$pubsub_topic\"]" |
| 28 | +sleep 0.1 |
| 29 | + |
| 30 | +printf "\nRelay from NODE1\n" |
| 31 | +curl -X POST "http://127.0.0.1:12297/relay/v1/messages/$encoded_pubsub_topic" -H "Content-Type: application/json" -d '{"payload": "UmVsYXkgd29ya3MhIQ==", "contentTopic": "/test/1/waku-relay/proto", "timestamp": '$(date +%s%N)'}' |
| 32 | +sleep 0.1 |
| 33 | + |
| 34 | +printf "\nCheck message in NODE2\n" |
| 35 | +response=$(curl -X GET "http://127.0.0.1:8158/relay/v1/messages/$encoded_pubsub_topic" -H "Content-Type: application/json") |
| 36 | + |
| 37 | +printf "\nResponse: $response\n\n" |
| 38 | + |
| 39 | +printf "NODE1 INFO: $info1\n\n" |
| 40 | + |
| 41 | +printf "NODE1 ENR: $enrUri\n\n" |
| 42 | + |
| 43 | +# Extract the first non-WebSocket address |
| 44 | +ws_address=$(echo $info1 | jq -r '.listenAddresses[] | select(contains("/ws") | not)') |
| 45 | + |
| 46 | +# Check if we got an address, and construct the new address with it |
| 47 | +if [[ $ws_address != "" ]]; then |
| 48 | + identifier=$(echo $ws_address | awk -F'/p2p/' '{print $2}') |
| 49 | + if [[ $identifier != "" ]]; then |
| 50 | + multiaddr_with_id="/ip4/${node_1_ip}/tcp/${node_1_tcp}/p2p/${identifier}" |
| 51 | + printf "NODE1 MULTIADDRESS: $multiaddr_with_id\n\n" |
| 52 | + enrUri=$(echo $info1 | jq -r '.enrUri') |
| 53 | + else |
| 54 | + echo "No identifier found in the address." |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | +else |
| 58 | + echo "No non-WebSocket address found." |
| 59 | + exit 1 |
| 60 | +fi |
| 61 | + |
0 commit comments