mirror of
https://github.com/status-im/status-go.git
synced 2025-01-15 01:05:06 +00:00
eeca435064
Update vendor Integrate rendezvous into status node Add a test with failover using rendezvous Use multiple servers in client Use discovery V5 by default and test that node can be started with rendezvous discovet Fix linter Update rendezvous client to one with instrumented stream Address feedback Fix test with updated topic limits Apply several suggestions Change log to debug for request errors because we continue execution Remove web3js after rebase Update rendezvous package
58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
package relay
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
|
|
inet "github.com/libp2p/go-libp2p-net"
|
|
pstore "github.com/libp2p/go-libp2p-peerstore"
|
|
ma "github.com/multiformats/go-multiaddr"
|
|
manet "github.com/multiformats/go-multiaddr-net"
|
|
)
|
|
|
|
type Conn struct {
|
|
inet.Stream
|
|
remote pstore.PeerInfo
|
|
}
|
|
|
|
type NetAddr struct {
|
|
Relay string
|
|
Remote string
|
|
}
|
|
|
|
func (n *NetAddr) Network() string {
|
|
return "libp2p-circuit-relay"
|
|
}
|
|
|
|
func (n *NetAddr) String() string {
|
|
return fmt.Sprintf("relay[%s-%s]", n.Remote, n.Relay)
|
|
}
|
|
|
|
func (c *Conn) RemoteAddr() net.Addr {
|
|
return &NetAddr{
|
|
Relay: c.Conn().RemotePeer().Pretty(),
|
|
Remote: c.remote.ID.Pretty(),
|
|
}
|
|
}
|
|
|
|
func (c *Conn) RemoteMultiaddr() ma.Multiaddr {
|
|
a, err := ma.NewMultiaddr(fmt.Sprintf("/ipfs/%s/p2p-circuit/ipfs/%s", c.Conn().RemotePeer().Pretty(), c.remote.ID.Pretty()))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return a
|
|
}
|
|
|
|
func (c *Conn) LocalMultiaddr() ma.Multiaddr {
|
|
return c.Conn().LocalMultiaddr()
|
|
}
|
|
|
|
func (c *Conn) LocalAddr() net.Addr {
|
|
na, err := manet.ToNetAddr(c.Conn().LocalMultiaddr())
|
|
if err != nil {
|
|
log.Error("failed to convert local multiaddr to net addr:", err)
|
|
return nil
|
|
}
|
|
return na
|
|
}
|