From: Matt Joiner Date: Mon, 10 May 2021 06:53:08 +0000 (+1000) Subject: Rename Torrent.{add,delete}Connection X-Git-Tag: v1.28.0~15 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=47284cf426ce1e394ef7a55bf2519f18fea5368a;p=btrtrc.git Rename Torrent.{add,delete}Connection --- diff --git a/client.go b/client.go index 1419958b..9506cfd2 100644 --- a/client.go +++ b/client.go @@ -766,7 +766,7 @@ func (cl *Client) outgoingConnection(t *Torrent, addr PeerRemoteAddr, ps PeerSou c, err := cl.establishOutgoingConn(t, addr) cl.lock() defer cl.unlock() - // Don't release lock between here and addConnection, unless it's for + // Don't release lock between here and addPeerConn, unless it's for // failure. cl.noLongerHalfOpen(t, addr.String()) if err != nil { @@ -951,7 +951,7 @@ func (cl *Client) runHandshookConn(c *PeerConn, t *Torrent) error { if connIsIpv6(c.conn) { torrent.Add("completed handshake over ipv6", 1) } - if err := t.addConnection(c); err != nil { + if err := t.addPeerConn(c); err != nil { return fmt.Errorf("adding connection: %w", err) } defer t.dropConnection(c) diff --git a/pexconn_test.go b/pexconn_test.go index 0b78b702..a3ff1d02 100644 --- a/pexconn_test.go +++ b/pexconn_test.go @@ -23,7 +23,7 @@ func TestPexConnState(t *testing.T) { c.PeerExtensionIDs[pp.ExtensionNamePex] = pexExtendedId c.writerCond.L.Lock() c.setTorrent(torrent) - torrent.addConnection(c) + torrent.addPeerConn(c) c.pex.Init(c) require.True(t, c.pex.IsEnabled(), "should get enabled") diff --git a/torrent.go b/torrent.go index 32b7e5fd..78d0f458 100644 --- a/torrent.go +++ b/torrent.go @@ -1283,7 +1283,7 @@ func (t *Torrent) SetInfoBytes(b []byte) (err error) { } // Returns true if connection is removed from torrent.Conns. -func (t *Torrent) deleteConnection(c *PeerConn) (ret bool) { +func (t *Torrent) deletePeerConn(c *PeerConn) (ret bool) { if !c.closed.IsSet() { panic("connection is not closed") // There are behaviours prevented by the closed state that will fail @@ -1325,7 +1325,7 @@ func (t *Torrent) assertNoPendingRequests() { func (t *Torrent) dropConnection(c *PeerConn) { t.cl.event.Broadcast() c.close() - if t.deleteConnection(c) { + if t.deletePeerConn(c) { t.openNewConns() } } @@ -1665,7 +1665,7 @@ func (t *Torrent) reconcileHandshakeStats(c *PeerConn) { } // Returns true if the connection is added. -func (t *Torrent) addConnection(c *PeerConn) (err error) { +func (t *Torrent) addPeerConn(c *PeerConn) (err error) { defer func() { if err == nil { torrent.Add("added connections", 1) @@ -1683,7 +1683,7 @@ func (t *Torrent) addConnection(c *PeerConn) (err error) { } if left, ok := c.hasPreferredNetworkOver(c0); ok && left { c0.close() - t.deleteConnection(c0) + t.deletePeerConn(c0) } else { return errors.New("existing connection preferred") } @@ -1694,7 +1694,7 @@ func (t *Torrent) addConnection(c *PeerConn) (err error) { return errors.New("don't want conns") } c.close() - t.deleteConnection(c) + t.deletePeerConn(c) } if len(t.conns) >= t.maxEstablishedConns { panic(len(t.conns))