Skip to content

Commit

Permalink
immediately get a reservation when connecting to a static relay
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Nov 16, 2021
1 parent f69064e commit 46953c6
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions p2p/host/autorelay/autorelay.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,29 @@ func (ar *AutoRelay) background(ctx context.Context) {
return
}
evt := ev.(event.EvtPeerConnectednessChanged)
if evt.Connectedness != network.NotConnected {
continue
}
ar.mx.Lock()
if ar.usingRelay(evt.Peer) { // we were disconnected from a relay
delete(ar.relays, evt.Peer)
push = true
continue
switch evt.Connectedness {
case network.Connected:
// If we just connect to one of our static relays, get a reservation immediately.
for _, pi := range ar.static {
if pi.ID == evt.Peer {
rsvp, ok := ar.tryRelay(ctx, pi)
if ok {
ar.mx.Lock()
ar.relays[pi.ID] = rsvp
ar.mx.Unlock()
}
push = true
break
}
}
case network.NotConnected:
ar.mx.Lock()
if ar.usingRelay(evt.Peer) { // we were disconnected from a relay
delete(ar.relays, evt.Peer)
push = true
}
ar.mx.Unlock()
}
ar.mx.Unlock()
case ev, ok := <-subReachability.Out():
if !ok {
return
Expand Down

0 comments on commit 46953c6

Please sign in to comment.