Skip to content

Commit

Permalink
Rename Torrent.{add,delete}Connection
Browse files Browse the repository at this point in the history
  • Loading branch information
anacrolix committed May 14, 2021
1 parent 1080c83 commit 47284cf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pexconn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 5 additions & 5 deletions torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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")
}
Expand All @@ -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))
Expand Down

0 comments on commit 47284cf

Please sign in to comment.