remove race condition in setting peer.close by requiring it as an argument to newPeer

This commit is contained in:
Arceliar 2019-02-03 15:50:25 -06:00
parent 5ddf84f329
commit 2f8dd5dde0
4 changed files with 7 additions and 11 deletions

View file

@ -113,7 +113,7 @@ type peer struct {
}
// Creates a new peer with the specified box, sig, and linkShared keys, using the lowest unoccupied port number.
func (ps *peers) newPeer(box *crypto.BoxPubKey, sig *crypto.SigPubKey, linkShared *crypto.BoxSharedKey, endpoint string) *peer {
func (ps *peers) newPeer(box *crypto.BoxPubKey, sig *crypto.SigPubKey, linkShared *crypto.BoxSharedKey, endpoint string, closer func()) *peer {
now := time.Now()
p := peer{box: *box,
sig: *sig,
@ -123,6 +123,7 @@ func (ps *peers) newPeer(box *crypto.BoxPubKey, sig *crypto.SigPubKey, linkShare
firstSeen: now,
doSend: make(chan struct{}, 1),
dinfo: make(chan *dhtInfo, 1),
close: closer,
core: ps.core}
ps.mutex.Lock()
defer ps.mutex.Unlock()