func (t *Torrent) addConnection(c *PeerConn) (err error) {
	defer func() {
		if err == nil {
			torrent.Add("added connections", 1)
		}
	}()
	if t.closed.IsSet() {
		return errors.New("torrent closed")
	}
	for c0 := range t.conns {
		if c.PeerID != c0.PeerID {
			continue
		}
		if !t.cl.config.dropDuplicatePeerIds {
			continue
		}
		if left, ok := c.hasPreferredNetworkOver(c0); ok && left {
			c0.close()
			t.deleteConnection(c0)
		} else {
			return errors.New("existing connection preferred")
		}
	}
	if len(t.conns) >= t.maxEstablishedConns {
		c := t.worstBadConn()
		if c == nil {
			return errors.New("don't want conns")
		}
		c.close()
		t.deleteConnection(c)
	}
	if len(t.conns) >= t.maxEstablishedConns {
		panic(len(t.conns))
	}
	t.conns[c] = struct{}{}
	return nil
}
// Returns true if the connection is added.
Returns true if the connection is added.
// Returns true if the connection is added .
func (t *Torrent) addConnection(c *PeerConn) (err error) {
	defer func() {
		if err == nil {
			torrent.Add("added connections", 1)
		}
	}()
	if t.closed.IsSet() {
		return errors.New("torrent closed")
	}
	for c0 := range t.conns {
		if c.PeerID != c0.PeerID {
			continue
		}
		if !t.cl.config.dropDuplicatePeerIds {
			continue
		}
		if left, ok := c.hasPreferredNetworkOver(c0); ok && left {
			c0.close()
			t.deleteConnection(c0)
		} else {
			return errors.New("existing connection preferred")
		}
	}
	if len(t.conns) >= t.maxEstablishedConns {
		c := t.worstBadConn()
		if c == nil {
			return errors.New("don't want conns")
		}
		c.close()
		t.deleteConnection(c)
	}
	if len(t.conns) >= t.maxEstablishedConns {
		panic(len(t.conns))
	}
	t.conns[c] = struct{}{}
	return nil
}
func ( t * Torrent ) addConnection ( c * PeerConn ) ( err error ) { defer func ( ) { if err == nil { torrent . Add ( " " , 1 ) } } ( ) if t . closed . IsSet ( ) { return errors . New ( " " ) } for c0 := range t . conns { if c . PeerID != c0 . PeerID { continue } if ! t . cl . config . dropDuplicatePeerIds { continue } if left , ok := c . hasPreferredNetworkOver ( c0 ) ; ok && left { c0 . close ( ) t . deleteConnection ( c0 ) } else { return errors . New ( " " ) } } if len ( t . conns ) >= t . maxEstablishedConns { c := t . worstBadConn ( ) if c == nil { return errors . New ( " " ) } c . close ( ) t . deleteConnection ( c ) } if len ( t . conns ) >= t . maxEstablishedConns { panic ( len ( t . conns ) ) } t . conns [ c ] = struct { } { } return nil }
Returns true if the connection is added.
Returns true if the connection is added .