Closed hot3246624 closed 5 years ago
That's because of a recent change in libp2p, which enables relay by default. The code is faulty and blindly uses the first address, which happens to be a relay address.
Possible solutions:
libp2p.DisableRelay()
to libp2p.New
to turn off relayedit: the simplest solution is to print all addrs in the I am ...
part, not just the first address.
That's because of a recent change in libp2p, which enables relay by default. The code is faulty and blindly uses the first address, which happens to be a relay address.
Possible solutions:
- pass
libp2p.DisableRelay()
tolibp2p.New
to turn off relay- fix the code to be more clever about the use of addresses and don't try to dial the relay address.
edit: the simplest solution is to print all addrs in the
I am ...
part, not just the first address.
it is not ok for me, when i dial other address such as 127.0.10.1, the error is: 19:53:38.817 WARNI swarm2: listen on /ip4/127.0.10.1/tcp/10000 failed: listen tcp4 127.0.10.1:10000: bind: can't assign requested address swarm_listen.go:25 19:53:38.817 WARNI swarm2: swarm listener accept error: process closing swarm_listen.go:77 2018/10/29 19:53:38 failed to listen on any addresses: [listen tcp4 127.0.10.1:10000: bind: can't assign requested address]
when i pass disableRelay() after libp2p.new, there is nothing change. And i cannot understand the the last word。
pass libp2p.DisableRelay() to libp2p.New to turn off relay
this indeed worked as I added opts = append(opts, libp2p.DisableRelay()) Thank you @vyzo
For me, this does the trick:
// Range over the addresses to find the first non relay address
for _, addr := range basicHost.Addrs() {
if strings.SplitN(addr.String(), "/", 3)[1] != "p2p-circuit" {
// Now we can build a full multiaddress to reach this host
// by encapsulating both addresses:
fullAddr := addr.Encapsulate(hostAddr)
log.Printf("I am %s\n", fullAddr)
if secio {
log.Printf("Now run \"./echo -l %d -d %s -secio\" on a different terminal\n",
listenPort+1, fullAddr)
} else {
log.Printf("Now run \"./echo -l %d -d %s\" on a different terminal\n",
listenPort+1, fullAddr)
}
}
}
Is it a realistic scenario to have a relay and not to use it?
Cheers, Stefan
when i follow examplex-echo,in the 2nd terminal, i got the error: 2018/10/29 17:00:06 I am /p2p-circuit/ipfs/QmSNfGzsTDf7RDUtXiZSbmyEqz5tawrtkn7DrQ5GxeYNUM 2018/10/29 17:00:06 Now run "./echo -l 10002 -d /p2p-circuit/ipfs/QmSNfGzsTDf7RDUtXiZSbmyEqz5tawrtkn7DrQ5GxeYNUM -secio" on a different terminal 2018/10/29 17:00:06 opening stream 17:00:06.157 INFO swarm2: got error on dial to /p2p-circuit: <peer.ID QmxeYNUM> --> <peer.ID QmkzqPAp> dial attempt failed: Failed to dial through 0 known relay hosts swarm_dial.go:382 2018/10/29 17:00:06 dial attempt failed: <peer.ID QmxeYNUM> --> <peer.ID QmkzqPAp> dial attempt failed: Failed to dial through 0 known relay hosts