type torrentAddr string
-func (me torrentAddr) Network() string { return "" }
+func (torrentAddr) Network() string { return "" }
func (me torrentAddr) String() string { return string(me) }
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) {
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 {
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))
}
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 {
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()
}
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)
}
})
}
-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
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()
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) {