return
}
-func firstNonEmptyString(ss ...string) string {
- for _, s := range ss {
- if s != "" {
- return s
- }
- }
- return ""
-}
-
func (cl *Client) Closed() <-chan struct{} {
cl.lock()
defer cl.unlock()
return ok
}
-func ipNetworkSuffix(allowIpv4, allowIpv6 bool) string {
- switch {
- case allowIpv4 && allowIpv6:
- return ""
- case allowIpv4 && !allowIpv6:
- return "4"
- case !allowIpv4 && allowIpv6:
- return "6"
- default:
- panic("unhandled ip network combination")
- }
-}
-
-func dialUTP(ctx context.Context, addr string, sock utpSocket) (c net.Conn, err error) {
- return sock.DialContext(ctx, "", addr)
-}
-
var allPeerNetworks = []string{"tcp4", "tcp6", "udp4", "udp6"}
func peerNetworkEnabled(network string, cfg *ClientConfig) bool {
return
}
-func (f *File) exclusivePieces() (begin, end int) {
- return byteRegionExclusivePieces(f.offset, f.length, int64(f.t.usualPieceSize()))
-}
-
// Deprecated: Use File.SetPriority.
func (f *File) Cancel() {
f.SetPriority(PiecePriorityNone)
pieceHashedCorrect = expvar.NewInt("pieceHashedCorrect")
pieceHashedNotCorrect = expvar.NewInt("pieceHashedNotCorrect")
- peerExtensions = expvar.NewMap("peerExtensions")
completedHandshakeConnectionFlags = expvar.NewMap("completedHandshakeConnectionFlags")
// Count of connections to peer with same client ID.
connsToSelf = expvar.NewInt("connsToSelf")
import "strings"
-type peerNetworks struct {
- tcp4, tcp6 bool
- utp4, utp6 bool
-}
-
-func handleErr(h func(), fs ...func() error) error {
- for _, f := range fs {
- err := f()
- if err != nil {
- h()
- return err
- }
- }
- return nil
-}
-
func LoopbackListenHost(network string) string {
if strings.Contains(network, "4") {
return "127.0.0.1"
package torrent
-func strictCmp(same, less bool) cmper {
- return func() (bool, bool) { return same, less }
-}
-
type (
cmper func() (same, less bool)
multiLess struct {
return me.d(ctx, addr)
}
-func setPort(addr string, port int) string {
- host, _, err := net.SplitHostPort(addr)
- if err != nil {
- panic(err)
- }
- return net.JoinHostPort(host, strconv.FormatInt(int64(port), 10))
-}
-
func listenAll(networks []string, getHost func(string) string, port int, proxyURL string, f firewallCallback) ([]socket, error) {
if len(networks) == 0 {
return nil, nil
return chunkIndexSpec(chunkIndex, t.pieceLength(piece), t.chunkSize)
}
-type peersKey struct {
- IPBytes string
- Port int
-}
-
// Maintains state of torrent within a Client.
type Torrent struct {
// Torrent-level aggregate statistics. First in struct to ensure 64-bit
}
}
-func (t *Torrent) metadataSizeKnown() bool {
- return t.metadataBytes != nil
-}
-
func (t *Torrent) metadataSize() int {
return len(t.metadataBytes)
}
return int(cs.Begin / chunkSize)
}
-func (t *Torrent) wantPiece(r request) bool {
- if !t.wantPieceIndex(pieceIndex(r.Index)) {
- return false
- }
- if t.pieces[r.Index].pendingChunk(r.chunkSpec, t.chunkSize) {
- return true
- }
- // TODO: What about pieces that were wanted, but aren't now, and aren't
- // completed either? That used to be done here.
- return false
-}
-
func (t *Torrent) wantPieceIndex(index pieceIndex) bool {
if !t.haveInfo() {
return false
return nil
}
-func (t *Torrent) readerPieces() (ret bitmap.Bitmap) {
- t.forReaderOffsetPieces(func(begin, end pieceIndex) bool {
- ret.AddRange(bitmap.BitIndex(begin), bitmap.BitIndex(end))
- return true
- })
- return
-}
-
func (t *Torrent) readerPiecePriorities() (now, readahead bitmap.Bitmap) {
t.forReaderOffsetPieces(func(begin, end pieceIndex) bool {
if end > begin {