client.go | 12 +++--------- connection.go | 4 ---- torrent.go | 77 ----------------------------------------------------- diff --git a/client.go b/client.go index 4250ef4f43428f11a54cf4133254037e7f83a04f..53188a582458eda353ca5b411f769d7c2d0df82d 100644 --- a/client.go +++ b/client.go @@ -96,7 +96,7 @@ } type torrentAddr string -func (me torrentAddr) Network() string { return "" } +func (torrentAddr) Network() string { return "" } func (me torrentAddr) String() string { return string(me) } @@ -105,12 +105,6 @@ if cl.listenAddr == "" { return nil } return torrentAddr(cl.listenAddr) -} - -func (cl *Client) sortedTorrents() (ret []*Torrent) { - return slices.Sort(slices.FromMapElems(cl.torrents), func(l, r metainfo.Hash) bool { - return l.AsString() < r.AsString() - }).([]*Torrent) } // Writes out a human readable status of the client, such as for writing to a @@ -452,7 +446,7 @@ Conn net.Conn UTP bool } -func doDial(dial func(addr string, t *Torrent) (net.Conn, error), ch chan dialResult, utp bool, addr string, t *Torrent) { +func doDial(dial func(string, *Torrent) (net.Conn, error), ch chan dialResult, utp bool, addr string, t *Torrent) { conn, err := dial(addr, t) if err != nil { if conn != nil { @@ -515,7 +509,7 @@ c = pproffd.WrapNetConn(c) return } -func (cl *Client) dialUTP(addr string, t *Torrent) (c net.Conn, err error) { +func (cl *Client) dialUTP(addr string, t *Torrent) (net.Conn, error) { return cl.utpSock.DialTimeout(addr, cl.dialTimeout(t)) } diff --git a/connection.go b/connection.go index 945fc879958c80235658a1a32e8f99fa42e1ab94..01f75dd09910245b76231608cc90ad404ba0bed7 100644 --- a/connection.go +++ b/connection.go @@ -1064,10 +1064,6 @@ func (cn *connection) Drop() { cn.t.dropConnection(cn) } -func (cn *connection) sentHave(piece int) bool { - return piece < len(cn.sentHaves) && cn.sentHaves[piece] -} - func (cn *connection) netGoodPiecesDirtied() int { return cn.goodPiecesDirtied - cn.badPiecesDirtied } diff --git a/torrent.go b/torrent.go index 6702be8510e9ba5576a8f318ce53becc13c2f8df..ac4d1c065c9d0b5c4998b559ba77224d5f120465 100644 --- a/torrent.go +++ b/torrent.go @@ -144,15 +144,6 @@ func (t *Torrent) pieceCompleteUncached(piece int) bool { return t.pieces[piece].Storage().GetIsComplete() } -func (t *Torrent) numConnsUnchoked() (num int) { - for c := range t.conns { - if !c.PeerChoked { - num++ - } - } - return -} - // There's a connection to that address already. func (t *Torrent) addrActive(addr string) bool { if _, ok := t.halfOpen[addr]; ok { @@ -551,10 +542,6 @@ func (t *Torrent) usualPieceSize() int { return int(t.info.PieceLength) } -func (t *Torrent) lastPieceSize() int { - return int(t.pieceLength(t.numPieces() - 1)) -} - func (t *Torrent) numPieces() int { return t.info.NumPieces() } @@ -608,37 +595,6 @@ }) return } -func (t *Torrent) validOutgoingRequest(r request) bool { - if r.Index >= pp.Integer(t.info.NumPieces()) { - return false - } - if r.Begin%t.chunkSize != 0 { - return false - } - if r.Length > t.chunkSize { - return false - } - pieceLength := t.pieceLength(int(r.Index)) - if r.Begin+r.Length > pieceLength { - return false - } - return r.Length == t.chunkSize || r.Begin+r.Length == pieceLength -} - -func (t *Torrent) pieceChunks(piece int) (css []chunkSpec) { - css = make([]chunkSpec, 0, (t.pieceLength(piece)+t.chunkSize-1)/t.chunkSize) - var cs chunkSpec - for left := t.pieceLength(piece); left != 0; left -= cs.Length { - cs.Length = left - if cs.Length > t.chunkSize { - cs.Length = t.chunkSize - } - css = append(css, cs) - cs.Begin += cs.Length - } - return -} - func (t *Torrent) pieceNumChunks(piece int) int { return int((t.pieceLength(piece) + t.chunkSize - 1) / t.chunkSize) } @@ -761,28 +717,10 @@ return index < begin || index >= end }) } -func (t *Torrent) forNeededPieces(f func(piece int) (more bool)) (all bool) { - return t.forReaderOffsetPieces(func(begin, end int) (more bool) { - for i := begin; begin < end; i++ { - if !f(i) { - return false - } - } - return true - }) -} - func (t *Torrent) connHasWantedPieces(c *connection) bool { return !c.pieceRequestOrder.IsEmpty() } -func (t *Torrent) extentPieces(off, _len int64) (pieces []int) { - for i := off / int64(t.usualPieceSize()); i*int64(t.usualPieceSize()) < off+_len; i++ { - pieces = append(pieces, int(i)) - } - return -} - // The worst connection is one that hasn't been sent, or sent anything useful // for the longest. A bad connection is one that usually sends us unwanted // pieces, or has been in worser half of the established connections for more @@ -830,17 +768,6 @@ } func (t *Torrent) pieceAllDirty(piece int) bool { return t.pieces[piece].DirtyChunks.Len() == t.pieceNumChunks(piece) -} - -func (t *Torrent) forUrgentPieces(f func(piece int) (again bool)) (all bool) { - return t.forReaderOffsetPieces(func(begin, end int) (again bool) { - if begin < end { - if !f(begin) { - return false - } - } - return true - }) } func (t *Torrent) readersChanged() { @@ -983,10 +910,6 @@ return } t.pendingPieces.Add(piece) t.updatePiecePriority(piece) -} - -func (t *Torrent) getCompletedPieces() (ret bitmap.Bitmap) { - return t.completedPieces.Copy() } func (t *Torrent) unpendPieces(unpend *bitmap.Bitmap) {