}
}
-type unmarshaler_int struct {
+type unmarshalerInt struct {
x int
}
-func (this *unmarshaler_int) UnmarshalBencode(data []byte) error {
- return Unmarshal(data, &this.x)
+func (me *unmarshalerInt) UnmarshalBencode(data []byte) error {
+ return Unmarshal(data, &me.x)
}
-type unmarshaler_string struct {
+type unmarshalerString struct {
x string
}
-func (this *unmarshaler_string) UnmarshalBencode(data []byte) error {
- this.x = string(data)
+func (me *unmarshalerString) UnmarshalBencode(data []byte) error {
+ me.x = string(data)
return nil
}
func TestUnmarshalerBencode(t *testing.T) {
- var i unmarshaler_int
- var ss []unmarshaler_string
+ var i unmarshalerInt
+ var ss []unmarshalerString
check_error(t, Unmarshal([]byte("i71e"), &i))
assert_equal(t, i.x, 71)
check_error(t, Unmarshal([]byte("l5:hello5:fruit3:waye"), &ss))
return block
}
-func (cl *Client) enabledPeerNetworks() (ns []network) {
- for _, n := range allPeerNetworks {
- if peerNetworkEnabled(n, cl.config) {
- ns = append(ns, n)
- }
- }
- return
-}
-
func (cl *Client) listenOnNetwork(n network) bool {
if n.Ipv4 && cl.config.DisableIPv4 {
return false
addr := c.conn.RemoteAddr().String()
cl.dopplegangerAddrs[addr] = struct{}{}
} else {
- // Because the remote address is not necessarily the same as its
- // client's torrent listen address, we won't record the remote address
- // as a doppleganger. Instead, the initiator can record *us* as the
- // doppleganger.
+ // Because the remote address is not necessarily the same as its client's torrent listen
+ // address, we won't record the remote address as a doppleganger. Instead, the initiator
+ // can record *us* as the doppleganger.
}
return
}
"fmt"
"io"
"io/ioutil"
- "log"
"os"
"path/filepath"
"reflect"
LeecherDownloadRateLimiter *rate.Limiter
}
-func logPieceStateChanges(t *Torrent) {
- sub := t.SubscribePieceStateChanges()
- go func() {
- defer sub.Close()
- for e := range sub.Values {
- log.Printf("%p %#v", t, e)
- }
- }()
-}
-
// Creates a seeder and a leecher, and ensures the data transfers when a read
// is attempted on the leecher.
func testClientTransfer(t *testing.T, ps testClientTransferParams) {
assert.True(t, new)
require.True(t, cl.WaitAll())
tor.Drop()
- tor, new, err = cl.AddTorrentSpec(TorrentSpecFromMetaInfo(mi))
+ _, new, err = cl.AddTorrentSpec(TorrentSpecFromMetaInfo(mi))
require.NoError(t, err)
assert.True(t, new)
require.True(t, cl.WaitAll())
)
var (
- torrentfsReadRequests = expvar.NewInt("torrentfsReadRequests")
- torrentfsDelayedReadRequests = expvar.NewInt("torrentfsDelayedReadRequests")
- interruptedReads = expvar.NewInt("interruptedReads")
+ torrentfsReadRequests = expvar.NewInt("torrentfsReadRequests")
)
type TorrentFS struct {
// Checking if the magnet instance struct is built correctly from parsing
m, err = ParseMagnetURI(exampleMagnetURI)
assert.EqualValues(t, exampleMagnet, m)
+ assert.NoError(t, err)
// empty string URI case
_, err = ParseMagnetURI("")
type (
multiLess = missinggo.MultiLess
- cmper = missinggo.SameLessFunc
)
return errors.Wrap(err, "reading piece data")
}
case Extended:
- b, err := readByte(r)
+ var b byte
+ b, err = readByte(r)
if err != nil {
break
}
return p.t.pieceNumChunks(p.index)
}
-func (p *Piece) undirtiedChunkIndices() (ret bitmap.Bitmap) {
- ret = p._dirtyChunks.Copy()
- ret.FlipRange(0, bitmap.BitIndex(p.numChunks()))
- return
-}
-
func (p *Piece) incrementPendingWrites() {
p.pendingWritesMutex.Lock()
p.pendingWrites++
"github.com/anacrolix/torrent/tracker"
)
-func (t *Torrent) chunkIndexSpec(chunkIndex pp.Integer, piece pieceIndex) chunkSpec {
- return chunkIndexSpec(chunkIndex, t.pieceLength(piece), t.chunkSize)
-}
-
// Maintains state of torrent within a Client. Many methods should not be called before the info is
// available, see .Info and .GotInfo.
type Torrent struct {
func (t *Torrent) makePieces() {
hashes := infoPieceHashes(t.info)
- t.pieces = make([]Piece, len(hashes), len(hashes))
+ t.pieces = make([]Piece, len(hashes))
for i, hash := range hashes {
piece := &t.pieces[i]
piece.t = t
return p.Storage().ReadAt(b, off-p.Info().Offset())
}
-func (t *Torrent) updateAllPieceCompletions() {
- for i := pieceIndex(0); i < t.numPieces(); i++ {
- t.updatePieceCompletion(i)
- }
-}
-
// Returns an error if the metadata was completed, but couldn't be set for
// some reason. Blame it on the last peer to contribute.
func (t *Torrent) maybeCompleteMetadata() error {
"github.com/anacrolix/torrent/bencode"
)
-var defaultHTTPUserAgent = "Go-Torrent"
-
func TestUnmarshalHTTPResponsePeerDicts(t *testing.T) {
var hr HttpResponse
require.NoError(t, bencode.Unmarshal(