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:
Steven Allen
2024-05-08 03:21:22 -07:00
committed by GitHub
parent 0385ec924b
commit af0161e83e
20 changed files with 525 additions and 112 deletions
+3 -1
View File
@@ -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
}
}