Question about staticrelays

When we new a host.Host, we can use libp2p.StaticRelays([]peer.AddrInfo) to indicate which relay server we want to use. And we
pass in an array of perr.AddrInfo. Why do we need a array? Does libp2p pick one at random?

Yes. See

If one is randomly selected every time, how to ensure that the relay selected by the two peers to communicate is the same? If they are not the same, the relay will not be able to communicate

[image]

how to ensure that the relay selected by the two peers to communicate is the same?

Note, two peers do not need to listen via the same relay in order to communicate over a relayed connection. To add an example, imagine 2 peers (A, B) and two relays (R1 and R2). Peer A listens via R1 for incoming relayed connections, peer B listens via R2. Peer A would advertise a relayed Multiaddr (e.g. /ip6/IP_R1/p2p/PEER_ID_R1/p2p-circuit/PEER_ID_A). Once peer B discovers the relayed connection it connects to relay R1 and asks it to establish a relayed connection to peer A.

Does that make sense @khalid-davis?

Thanks for the reply. It sounds like we need an auto peer routing capability. How do we use this capability in libp2p. The document is currently empty, Peer Routing :: libp2p Documentation.

How do we use this capability in libp2p.

If you give use more context on your concrete use-case, we might be able to help.

Our scenario is edge computing. Mainly based on the kubernetes platform, we have realized the management of edge nodes. We hope to realize the mutual communication between nodes of different subnets through the relay and hole punching capabilities of libp2p. We hope to make the relay server highly available, such as active-standby model or active-active model. Active-active model of relay host is ultimately what we want to do.

Active-active model of relay host is ultimately what we want to do.

You can deploy X relay hosts and have each peer listen for incoming connections via each of them, thus giving you a redundancy of X.

Could you please tell me more detail?
Imagine 2 peers (A, B) and two relays (R1 and R2), do you mean let peer A and peerB connect both R1 and R2?

Hello,what is the best practice for high availability of libp2p relay host? Cloud you give me some post or link about this?

Yes. That would be the way to go. Have A connect to all relay nodes, in other words listen for incoming relayed connections via all relay nodes.

Does this cause too much memory to be wasted?