| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | test_description="Test circuit relay" |
| 4 | |
| 5 | . lib/test-lib.sh |
| 6 | |
| 7 | # start iptb + wait for peering |
| 8 | NUM_NODES=3 |
| 9 | test_expect_success 'init iptb' ' |
| 10 | iptb testbed create -type localipfs -count $NUM_NODES -init && |
| 11 | iptb run -- ipfs config --json "Routing.LoopbackAddressesOnLanDHT" true |
| 12 | ' |
| 13 | |
| 14 | # Network topology: A <-> Relay <-> B |
| 15 | test_expect_success 'start up nodes for configuration' ' |
| 16 | iptb start -wait -- --routing=none |
| 17 | ' |
| 18 | |
| 19 | test_expect_success 'peer ids' ' |
| 20 | PEERID_0=$(iptb attr get 0 id) && |
| 21 | PEERID_1=$(iptb attr get 1 id) && |
| 22 | PEERID_2=$(iptb attr get 2 id) |
| 23 | ' |
| 24 | |
| 25 | relayaddrs=$(ipfsi 1 swarm addrs local | jq --raw-input . | jq --slurp .) |
| 26 | staticrelay=$(ipfsi 1 swarm addrs local | sed -e "s|$|/p2p/$PEERID_1|g" | jq --raw-input . | jq --slurp .) |
| 27 | |
| 28 | test_expect_success 'configure the relay node as a static relay for node A' ' |
| 29 | ipfsi 0 config Internal.Libp2pForceReachability private && |
| 30 | ipfsi 0 config --json Swarm.RelayClient.Enabled true && |
| 31 | ipfsi 0 config --json Swarm.RelayClient.StaticRelays "$staticrelay" |
| 32 | ' |
| 33 | |
| 34 | test_expect_success 'configure the relay node' ' |
| 35 | ipfsi 1 config Internal.Libp2pForceReachability public && |
| 36 | ipfsi 1 config --json Swarm.RelayService.Enabled true && |
| 37 | ipfsi 1 config --json Addresses.Swarm "$relayaddrs" |
| 38 | ' |
| 39 | |
| 40 | test_expect_success 'configure the node B' ' |
| 41 | ipfsi 2 config Internal.Libp2pForceReachability private && |
| 42 | ipfsi 2 config --json Swarm.RelayClient.Enabled true |
| 43 | ' |
| 44 | |
| 45 | test_expect_success 'restart nodes' ' |
| 46 | iptb stop && |
| 47 | iptb_wait_stop && |
| 48 | iptb start -wait -- --routing=none |
| 49 | ' |
| 50 | |
| 51 | test_expect_success 'connect A <-> Relay' ' |
| 52 | iptb connect 0 1 |
| 53 | ' |
| 54 | |
| 55 | test_expect_success 'connect B <-> Relay' ' |
| 56 | iptb connect 2 1 |
| 57 | ' |
| 58 | |
| 59 | test_expect_success 'wait until relay is ready to do work' ' |
| 60 | while ! ipfsi 2 swarm connect /p2p/$PEERID_1/p2p-circuit/p2p/$PEERID_0; do |
| 61 | iptb stop && |
| 62 | iptb_wait_stop && |
| 63 | iptb start -wait -- --routing=none && |
| 64 | iptb connect 0 1 && |
| 65 | iptb connect 2 1 && |
| 66 | sleep 5 |
| 67 | done |
| 68 | ' |
| 69 | |
| 70 | test_expect_success 'connect A <-Relay-> B' ' |
| 71 | ipfsi 2 swarm connect /p2p/$PEERID_1/p2p-circuit/p2p/$PEERID_0 > peers_out |
| 72 | ' |
| 73 | |
| 74 | test_expect_success 'output looks good' ' |
| 75 | echo "connect $PEERID_0 success" > peers_exp && |
| 76 | test_cmp peers_exp peers_out |
| 77 | ' |
| 78 | |
| 79 | test_expect_success 'peers for A look good' ' |
| 80 | ipfsi 0 swarm peers > peers_out && |
| 81 | test_should_contain "/p2p/$PEERID_1/p2p-circuit/p2p/$PEERID_2$" peers_out |
| 82 | ' |
| 83 | |
| 84 | test_expect_success 'peers for B look good' ' |
| 85 | ipfsi 2 swarm peers > peers_out && |
| 86 | test_should_contain "/p2p/$PEERID_1/p2p-circuit/p2p/$PEERID_0$" peers_out |
| 87 | ' |
| 88 | |
| 89 | test_expect_success 'stop iptb' ' |
| 90 | iptb stop |
| 91 | ' |
| 92 | |
| 93 | test_done |