return ok
}
-// Returns a connection over UTP or TCP, whichever is first to connect.
-func (cl *Client) dialFirst(ctx context.Context, addr string) (res DialResult) {
- return DialFirst(ctx, addr, cl.dialers)
-}
-
// Returns a connection over UTP or TCP, whichever is first to connect.
func DialFirst(ctx context.Context, addr string, dialers []Dialer) (res DialResult) {
pool := dialPool{
}
}
-func (cl *Client) countHalfOpenFromTorrents() (count int) {
- for t := range cl.torrents {
- count += t.numHalfOpenAttempts()
- }
- return
-}
-
// Performs initiator handshakes and returns a connection. Returns nil *PeerConn if no connection
// for valid reasons.
func (cl *Client) initiateProtocolHandshakes(
messageTypesReceived = expvar.NewMap("messageTypesReceived")
- // Track the effectiveness of Torrent.connPieceInclinationPool.
- pieceInclinationsReused = expvar.NewInt("pieceInclinationsReused")
- pieceInclinationsNew = expvar.NewInt("pieceInclinationsNew")
- pieceInclinationsPut = expvar.NewInt("pieceInclinationsPut")
-
concurrentChunkWrites = expvar.NewInt("torrentConcurrentChunkWrites")
)
return haveAllowedFastRequests
}
-func (cn *Peer) remoteChokingPiece(piece pieceIndex) bool {
- return cn.peerChoking && !cn.peerAllowedFast.Contains(piece)
-}
-
func (cn *Peer) cumInterest() time.Duration {
ret := cn.priorInterest
if cn.requestState.Interested {
Protocol = "\x13BitTorrent protocol"
)
-var protocolStr = Protocol
-
func protocolBytes() []byte {
return unsafe.Slice(unsafe.StringData(Protocol), len(Protocol))
}
return old.Value != state
}
-func (me *PieceRequestOrder) existingItemForKey(key PieceRequestOrderKey) PieceRequestOrderItem {
- return PieceRequestOrderItem{
- Key: key,
- State: me.keys[key],
- }
-}
-
func (me *PieceRequestOrder) Delete(key PieceRequestOrderKey) (deleted bool) {
state, ok := me.keys[key]
if !ok {
type chunkReader struct {
r possum.Reader
values []consecutiveValue
- keys []int64
}
func (c chunkReader) ReadAt(p []byte, off int64) (n int, err error) {
"time"
"github.com/anacrolix/log"
- "github.com/stretchr/testify/require"
-
pp "github.com/anacrolix/torrent/peer_protocol"
)
//})
return cfg
}
-
-func readChannelTimeout[T any](t *testing.T, channel chan T, duration time.Duration) interface{} {
- select {
- case s := <-channel:
- return s
- case <-time.After(duration):
- require.Fail(t, "Timeout reading observer channel.")
- }
- return nil
-}
return t.pieces[piece].Storage().Completion()
}
-// There's a connection to that address already.
-func (t *Torrent) addrActive(addr string) bool {
- if _, ok := t.halfOpen[addr]; ok {
- return true
- }
- for c := range t.conns {
- ra := c.RemoteAddr
- if ra.String() == addr {
- return true
- }
- }
- return false
-}
-
func (t *Torrent) appendUnclosedConns(ret []*PeerConn) []*PeerConn {
return t.appendConns(ret, func(conn *PeerConn) bool {
return !conn.closed.IsSet()
return t._chunksPerRegularPiece
}
-func (t *Torrent) numChunks() RequestIndex {
- if t.numPieces() == 0 {
- return 0
- }
- return RequestIndex(t.numPieces()-1)*t.chunksPerRegularPiece() + t.pieceNumChunks(t.numPieces()-1)
-}
-
func (t *Torrent) pendAllChunkSpecs(pieceIndex pieceIndex) {
t.dirtyChunks.RemoveRange(
uint64(t.pieceRequestIndexOffset(pieceIndex)),
}
}
-func (t *Torrent) peersAsSlice() (ret []*Peer) {
- t.iterPeers(func(p *Peer) {
- ret = append(ret, p)
- })
- return
-}
-
func (t *Torrent) queueInitialPieceCheck(i pieceIndex) {
if !t.initialPieceCheckDisabled && !t.piece(i).storageCompletionOk {
t.queuePieceCheck(i)
return nil
}
-func (t *Torrent) numHalfOpenAttempts() (num int) {
- for _, attempts := range t.halfOpen {
- num += len(attempts)
- }
- return
-}
-
func (t *Torrent) getDialTimeoutUnlocked() time.Duration {
cl := t.cl
cl.rLock()
}
defer writer.Close()
reader, err := second.Accept()
- defer reader.Close()
c.Assert(err, qt.IsNil)
+ defer reader.Close()
return writeAndReadMsg(reader, writer)
}()
if err == nil {