Closed Strernd closed 4 years ago
@Strernd as a sanity check could you make sure this is actually a libp2p issue instead of a Docker config one?
For example, instead of doing a host.Connect()
on your manually discovered peer's address just do a direct TCP connect to it such as:
conn, err := net.Dial("tcp", "172.31.37.27:5500")
if err != nil {
panic(err)
}
fmt.Println(conn.RemoteAddr())
return
If you're concerned about the libp2p server side you could replace that with a go TCP listener as well, such as:
l, err := net.Listen("tcp", 5500)
if err != nil {
fmt.Println(err)
return
}
defer l.Close()
c, err := l.Accept()
if err != nil {
fmt.Println(err)
return
}
Will do it tomorrow!
I finally came around to test the code, it took me a while.
I also tested if the ports are open the following way:
On one instance nc -l <internal_ip> 5500
and on the other instance nc -l <other_inst_ip> 5500
which was successful in creating a connection, while other random ports weren't.
The docker-compose files each have a entry - "5500:5500"
under ports
.
I tried to connect with net.Dial
which fails with dial tcp <other_peer_interal_ip>:5500: connect: connection refused
I also tried to change to addressFactory such that it just returns the fixed address and port.
log.WithFields(log.Fields{"addresses": host.Addrs(), "id": host.ID()}).Info("Listening")
logs addresses=[/ip4/<nodes_internal_ip>/tcp/5500] id=Qm...
with the said change to the addressFactory.
Edit:
I also implemented net
as server now. Connections can be established. So either I'm using libp2p wrong, or something doesn't work as it's intended to.
For future reference, here is what I had to change to fix this:
A bit counter-intuitive for me.
I'm using libp2p to communicate with other instances of the service. All of them are hosted in a docker container on an AWS EC2 machine. They're all configured to each listen on port 5500. The port 5500 is open to all instances of the service. I used the code mentioned in https://github.com/libp2p/go-libp2p/issues/460 .
It works locally in a docker-compose setup.
The nodes are announcing their address, port and Id over another service and then try to connect to their peers. I tried it with the public and private address of the EC2 machine, but had no success.
I'm not sure if this is a bug, but I'd expect it to work, as I'm doing it in a similar way (at least for the network configuration) with a different service in libp2p-js.
Version Information