Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -1746,7 +1746,7 @@ func (t *Torrent) openNewConns(lock bool) (initiated int) {
receivedHolepunchConnect: false,
HeaderObfuscationPolicy: t.cl.config.HeaderObfuscationPolicy,
}
initiateConn(opts, false, false, false)
initiateConn(opts, false, false)
initiated++
}

Expand Down Expand Up @@ -2533,10 +2533,6 @@ func (t *Torrent) wantOutgoingConns(lock bool) bool {
conns := t.peerConnsAsSlice(lock)
defer conns.free()

if len(conns) < t.maxEstablishedConns {
return true
}

numOutgoingConns := conns.numOutgoingConns()
numIncomingConns := len(conns) - numOutgoingConns

Expand Down Expand Up @@ -3113,15 +3109,9 @@ func (t *Torrent) addHalfOpen(addrStr string, attemptKey *PeerInfo, lock bool) {

// Start the process of connecting to the given peer for the given torrent if appropriate. I'm not
// sure all the PeerInfo fields are being used.
func initiateConn(opts outgoingConnOpts, ignoreLimits bool, lock bool, lockCLient bool) {
func initiateConn(opts outgoingConnOpts, ignoreLimits bool, lock bool) {
t := opts.t
peer := opts.peerInfo

if lockCLient {
t.cl.rLock()
defer t.cl.rUnlock()
}

if peer.Id == t.cl.peerID {
return
}
Expand Down Expand Up @@ -3661,14 +3651,12 @@ func (t *Torrent) handleReceivedUtHolepunchMsg(msg utHolepunch.Msg, sender *Peer
case utHolepunch.Connect:
holepunchAddr := msg.AddrPort
t.logger.Printf("got holepunch connect request for %v from %p", holepunchAddr, sender)
t.cl.lock()
if g.MapContains(t.cl.undialableWithoutHolepunch, holepunchAddr) {
setAdd(&t.cl.undialableWithoutHolepunchDialedAfterHolepunchConnect, holepunchAddr)
if g.MapContains(t.cl.accepted, holepunchAddr) {
setAdd(&t.cl.probablyOnlyConnectedDueToHolepunch, holepunchAddr)
}
}
t.cl.unlock()
opts := outgoingConnOpts{
peerInfo: PeerInfo{
Addr: msg.AddrPort,
Expand All @@ -3683,7 +3671,7 @@ func (t *Torrent) handleReceivedUtHolepunchMsg(msg utHolepunch.Msg, sender *Peer
// encryption. So we will act normally.
HeaderObfuscationPolicy: t.cl.config.HeaderObfuscationPolicy,
}
initiateConn(opts, true, true, true)
initiateConn(opts, true, true)
return nil
case utHolepunch.Error:
torrent.Add("holepunch error messages received", 1)
Expand Down
2 changes: 1 addition & 1 deletion ut-holepunching_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestHolepunchConnect(t *testing.T) {
requireRendezvous: true,
skipHolepunchRendezvous: false,
HeaderObfuscationPolicy: llg.cl.config.HeaderObfuscationPolicy,
}, true, true, true)
}, true, true)
llg.cl.unlock()
wg.Wait()

Expand Down