Skip to content

Commit

Permalink
natmgr: rename refresh to sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien committed Mar 6, 2019
1 parent a82f420 commit 4d12600
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions p2p/host/basic/natmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type natManager struct {

ready chan struct{} // closed once the nat is ready to process port mappings

refreshMu sync.Mutex
syncMu sync.Mutex

proc goprocess.Process // natManager has a process + children. can be closed.
}
Expand Down Expand Up @@ -111,20 +111,22 @@ func (nmgr *natManager) discoverNAT() {
// we need to sign up here to avoid missing some notifs
// before the NAT has been found.
nmgr.net.Notify((*nmgrNetNotifiee)(nmgr))
nmgr.refresh()
nmgr.sync()
})
}

func (nmgr *natManager) refresh() {
// syncs the current NAT mappings, removing any outdated mappings and adding any
// new mappings.
func (nmgr *natManager) sync() {
nat := nmgr.NAT()
if nat == nil {
// Nothing to do.
return
}

nmgr.proc.Go(func(_ goprocess.Process) {
nmgr.refreshMu.Lock()
defer nmgr.refreshMu.Unlock()
nmgr.syncMu.Lock()
defer nmgr.syncMu.Unlock()

ports := map[string]map[int]bool{
"tcp": map[int]bool{},
Expand Down Expand Up @@ -228,11 +230,11 @@ func (nn *nmgrNetNotifiee) natManager() *natManager {
}

func (nn *nmgrNetNotifiee) Listen(n inet.Network, addr ma.Multiaddr) {
nn.natManager().refresh()
nn.natManager().sync()
}

func (nn *nmgrNetNotifiee) ListenClose(n inet.Network, addr ma.Multiaddr) {
nn.natManager().refresh()
nn.natManager().sync()
}

func (nn *nmgrNetNotifiee) Connected(inet.Network, inet.Conn) {}
Expand Down

0 comments on commit 4d12600

Please sign in to comment.