From 9cf09dba8a4ee1692eb1a5779c89859deea21850 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 1 Jan 2017 11:03:02 +1100 Subject: [PATCH] Remove unused funcs and idents --- client.go | 12 ++------ connection.go | 4 --- torrent.go | 77 --------------------------------------------------- 3 files changed, 3 insertions(+), 90 deletions(-) diff --git a/client.go b/client.go index 4250ef4f..53188a58 100644 --- a/client.go +++ b/client.go @@ -96,7 +96,7 @@ func (cl *Client) PeerID() string { type torrentAddr string -func (me torrentAddr) Network() string { return "" } +func (torrentAddr) Network() string { return "" } func (me torrentAddr) String() string { return string(me) } @@ -107,12 +107,6 @@ func (cl *Client) ListenAddr() net.Addr { 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 // HTTP status page. func (cl *Client) WriteStatus(_w io.Writer) { @@ -452,7 +446,7 @@ type dialResult struct { 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 @@ func (cl *Client) dialTCP(addr string, t *Torrent) (c net.Conn, err error) { 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 945fc879..01f75dd0 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 6702be85..ac4d1c06 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 @@ func (t *Torrent) bitfield() (bf []bool) { 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 @@ func (t *Torrent) wantPieceIndex(index int) bool { }) } -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 @@ -832,17 +770,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() { t.updateReaderPieces() t.updateAllPiecePriorities() @@ -985,10 +912,6 @@ func (t *Torrent) pendPiece(piece int) { t.updatePiecePriority(piece) } -func (t *Torrent) getCompletedPieces() (ret bitmap.Bitmap) { - return t.completedPieces.Copy() -} - func (t *Torrent) unpendPieces(unpend *bitmap.Bitmap) { t.pendingPieces.Sub(unpend) unpend.IterTyped(func(piece int) (again bool) { -- 2.48.1