mirror of
https://github.com/libp2p/go-libp2p.git
synced 2026-04-23 00:27:05 +08:00
Add a "Limited" network connectivity state (#2696)
Rename the Transient state on connection to Limited. This is more appropriate and also doesn't conflict with the transient resource manager scope. Adds a Limited connectedness state for peers connected to us over Limited connections. This allows users to ignore such peers if they are interested in only peers connected to us over Unlimited connections. For some peers who disconnect before we sent a Connectedness event, we will now only send a Disconnected event. --------- Co-authored-by: guillaumemichel <guillaume@michel.id> Co-authored-by: sukun <sukunrt@gmail.com> Co-authored-by: Marco Munizaga <git@marcopolo.io>
This commit is contained in:
@@ -724,8 +724,10 @@ func (h *BasicHost) Connect(ctx context.Context, pi peer.AddrInfo) error {
|
||||
h.Peerstore().AddAddrs(pi.ID, pi.Addrs, peerstore.TempAddrTTL)
|
||||
|
||||
forceDirect, _ := network.GetForceDirectDial(ctx)
|
||||
canUseLimitedConn, _ := network.GetAllowLimitedConn(ctx)
|
||||
if !forceDirect {
|
||||
if h.Network().Connectedness(pi.ID) == network.Connected {
|
||||
connectedness := h.Network().Connectedness(pi.ID)
|
||||
if connectedness == network.Connected || (canUseLimitedConn && connectedness == network.Limited) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user