repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
anacrolix/torrent | metainfo/metainfo.go | UpvertedAnnounceList | func (mi *MetaInfo) UpvertedAnnounceList() AnnounceList {
if mi.AnnounceList.OverridesAnnounce(mi.Announce) {
return mi.AnnounceList
}
if mi.Announce != "" {
return [][]string{[]string{mi.Announce}}
}
return nil
} | go | func (mi *MetaInfo) UpvertedAnnounceList() AnnounceList {
if mi.AnnounceList.OverridesAnnounce(mi.Announce) {
return mi.AnnounceList
}
if mi.Announce != "" {
return [][]string{[]string{mi.Announce}}
}
return nil
} | [
"func",
"(",
"mi",
"*",
"MetaInfo",
")",
"UpvertedAnnounceList",
"(",
")",
"AnnounceList",
"{",
"if",
"mi",
".",
"AnnounceList",
".",
"OverridesAnnounce",
"(",
"mi",
".",
"Announce",
")",
"{",
"return",
"mi",
".",
"AnnounceList",
"\n",
"}",
"\n",
"if",
"... | // Returns the announce list converted from the old single announce field if
// necessary. | [
"Returns",
"the",
"announce",
"list",
"converted",
"from",
"the",
"old",
"single",
"announce",
"field",
"if",
"necessary",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/metainfo/metainfo.go#L79-L87 | train |
anacrolix/torrent | cmd/torrent-pick/main.go | totalBytesEstimate | func totalBytesEstimate(tc *torrent.Client) (ret int64) {
var noInfo, hadInfo int64
for _, t := range tc.Torrents() {
info := t.Info()
if info == nil {
noInfo++
continue
}
ret += info.TotalLength()
hadInfo++
}
if hadInfo != 0 {
// Treat each torrent without info as the average of those with,
// ... | go | func totalBytesEstimate(tc *torrent.Client) (ret int64) {
var noInfo, hadInfo int64
for _, t := range tc.Torrents() {
info := t.Info()
if info == nil {
noInfo++
continue
}
ret += info.TotalLength()
hadInfo++
}
if hadInfo != 0 {
// Treat each torrent without info as the average of those with,
// ... | [
"func",
"totalBytesEstimate",
"(",
"tc",
"*",
"torrent",
".",
"Client",
")",
"(",
"ret",
"int64",
")",
"{",
"var",
"noInfo",
",",
"hadInfo",
"int64",
"\n",
"for",
"_",
",",
"t",
":=",
"range",
"tc",
".",
"Torrents",
"(",
")",
"{",
"info",
":=",
"t"... | // Returns an estimate of the total bytes for all torrents. | [
"Returns",
"an",
"estimate",
"of",
"the",
"total",
"bytes",
"for",
"all",
"torrents",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/cmd/torrent-pick/main.go#L51-L68 | train |
anacrolix/torrent | connection.go | ipv6 | func (cn *connection) ipv6() bool {
ip := cn.remoteAddr.IP
if ip.To4() != nil {
return false
}
return len(ip) == net.IPv6len
} | go | func (cn *connection) ipv6() bool {
ip := cn.remoteAddr.IP
if ip.To4() != nil {
return false
}
return len(ip) == net.IPv6len
} | [
"func",
"(",
"cn",
"*",
"connection",
")",
"ipv6",
"(",
")",
"bool",
"{",
"ip",
":=",
"cn",
".",
"remoteAddr",
".",
"IP",
"\n",
"if",
"ip",
".",
"To4",
"(",
")",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"len",
"(",
"ip",
... | // Returns true if the connection is over IPv6. | [
"Returns",
"true",
"if",
"the",
"connection",
"is",
"over",
"IPv6",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/connection.go#L137-L143 | train |
anacrolix/torrent | connection.go | hasPreferredNetworkOver | func (l *connection) hasPreferredNetworkOver(r *connection) (left, ok bool) {
var ml multiLess
ml.NextBool(l.isPreferredDirection(), r.isPreferredDirection())
ml.NextBool(!l.utp(), !r.utp())
ml.NextBool(l.ipv6(), r.ipv6())
return ml.FinalOk()
} | go | func (l *connection) hasPreferredNetworkOver(r *connection) (left, ok bool) {
var ml multiLess
ml.NextBool(l.isPreferredDirection(), r.isPreferredDirection())
ml.NextBool(!l.utp(), !r.utp())
ml.NextBool(l.ipv6(), r.ipv6())
return ml.FinalOk()
} | [
"func",
"(",
"l",
"*",
"connection",
")",
"hasPreferredNetworkOver",
"(",
"r",
"*",
"connection",
")",
"(",
"left",
",",
"ok",
"bool",
")",
"{",
"var",
"ml",
"multiLess",
"\n",
"ml",
".",
"NextBool",
"(",
"l",
".",
"isPreferredDirection",
"(",
")",
","... | // Returns whether the left connection should be preferred over the right one,
// considering only their networking properties. If ok is false, we can't
// decide. | [
"Returns",
"whether",
"the",
"left",
"connection",
"should",
"be",
"preferred",
"over",
"the",
"right",
"one",
"considering",
"only",
"their",
"networking",
"properties",
".",
"If",
"ok",
"is",
"false",
"we",
"can",
"t",
"decide",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/connection.go#L154-L160 | train |
anacrolix/torrent | connection.go | bestPeerNumPieces | func (cn *connection) bestPeerNumPieces() pieceIndex {
if cn.t.haveInfo() {
return cn.t.numPieces()
}
return cn.peerMinPieces
} | go | func (cn *connection) bestPeerNumPieces() pieceIndex {
if cn.t.haveInfo() {
return cn.t.numPieces()
}
return cn.peerMinPieces
} | [
"func",
"(",
"cn",
"*",
"connection",
")",
"bestPeerNumPieces",
"(",
")",
"pieceIndex",
"{",
"if",
"cn",
".",
"t",
".",
"haveInfo",
"(",
")",
"{",
"return",
"cn",
".",
"t",
".",
"numPieces",
"(",
")",
"\n",
"}",
"\n",
"return",
"cn",
".",
"peerMinP... | // The best guess at number of pieces in the torrent for this peer. | [
"The",
"best",
"guess",
"at",
"number",
"of",
"pieces",
"in",
"the",
"torrent",
"for",
"this",
"peer",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/connection.go#L194-L199 | train |
anacrolix/torrent | connection.go | setNumPieces | func (cn *connection) setNumPieces(num pieceIndex) error {
cn.peerPieces.RemoveRange(bitmap.BitIndex(num), bitmap.ToEnd)
cn.peerPiecesChanged()
return nil
} | go | func (cn *connection) setNumPieces(num pieceIndex) error {
cn.peerPieces.RemoveRange(bitmap.BitIndex(num), bitmap.ToEnd)
cn.peerPiecesChanged()
return nil
} | [
"func",
"(",
"cn",
"*",
"connection",
")",
"setNumPieces",
"(",
"num",
"pieceIndex",
")",
"error",
"{",
"cn",
".",
"peerPieces",
".",
"RemoveRange",
"(",
"bitmap",
".",
"BitIndex",
"(",
"num",
")",
",",
"bitmap",
".",
"ToEnd",
")",
"\n",
"cn",
".",
"... | // Correct the PeerPieces slice length. Return false if the existing slice is
// invalid, such as by receiving badly sized BITFIELD, or invalid HAVE
// messages. | [
"Correct",
"the",
"PeerPieces",
"slice",
"length",
".",
"Return",
"false",
"if",
"the",
"existing",
"slice",
"is",
"invalid",
"such",
"as",
"by",
"receiving",
"badly",
"sized",
"BITFIELD",
"or",
"invalid",
"HAVE",
"messages",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/connection.go#L212-L216 | train |
anacrolix/torrent | connection.go | Post | func (cn *connection) Post(msg pp.Message) {
torrent.Add(fmt.Sprintf("messages posted of type %s", msg.Type.String()), 1)
// We don't need to track bytes here because a connection.w Writer wrapper
// takes care of that (although there's some delay between us recording
// the message, and the connection writer flush... | go | func (cn *connection) Post(msg pp.Message) {
torrent.Add(fmt.Sprintf("messages posted of type %s", msg.Type.String()), 1)
// We don't need to track bytes here because a connection.w Writer wrapper
// takes care of that (although there's some delay between us recording
// the message, and the connection writer flush... | [
"func",
"(",
"cn",
"*",
"connection",
")",
"Post",
"(",
"msg",
"pp",
".",
"Message",
")",
"{",
"torrent",
".",
"Add",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"msg",
".",
"Type",
".",
"String",
"(",
")",
")",
",",
"1",
")",
"\n",
"//... | // Writes a message into the write buffer. | [
"Writes",
"a",
"message",
"into",
"the",
"write",
"buffer",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/connection.go#L330-L340 | train |
anacrolix/torrent | connection.go | nominalMaxRequests | func (cn *connection) nominalMaxRequests() (ret int) {
if cn.t.requestStrategy == 3 {
expectingTime := int64(cn.totalExpectingTime())
if expectingTime == 0 {
expectingTime = math.MaxInt64
} else {
expectingTime *= 2
}
return int(clamp(
1,
int64(cn.PeerMaxRequests),
max(
// It makes sense t... | go | func (cn *connection) nominalMaxRequests() (ret int) {
if cn.t.requestStrategy == 3 {
expectingTime := int64(cn.totalExpectingTime())
if expectingTime == 0 {
expectingTime = math.MaxInt64
} else {
expectingTime *= 2
}
return int(clamp(
1,
int64(cn.PeerMaxRequests),
max(
// It makes sense t... | [
"func",
"(",
"cn",
"*",
"connection",
")",
"nominalMaxRequests",
"(",
")",
"(",
"ret",
"int",
")",
"{",
"if",
"cn",
".",
"t",
".",
"requestStrategy",
"==",
"3",
"{",
"expectingTime",
":=",
"int64",
"(",
"cn",
".",
"totalExpectingTime",
"(",
")",
")",
... | // The actual value to use as the maximum outbound requests. | [
"The",
"actual",
"value",
"to",
"use",
"as",
"the",
"maximum",
"outbound",
"requests",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/connection.go#L375-L402 | train |
anacrolix/torrent | connection.go | request | func (cn *connection) request(r request, mw messageWriter) bool {
if _, ok := cn.requests[r]; ok {
panic("chunk already requested")
}
if !cn.PeerHasPiece(pieceIndex(r.Index)) {
panic("requesting piece peer doesn't have")
}
if _, ok := cn.t.conns[cn]; !ok {
panic("requesting but not in active conns")
}
if c... | go | func (cn *connection) request(r request, mw messageWriter) bool {
if _, ok := cn.requests[r]; ok {
panic("chunk already requested")
}
if !cn.PeerHasPiece(pieceIndex(r.Index)) {
panic("requesting piece peer doesn't have")
}
if _, ok := cn.t.conns[cn]; !ok {
panic("requesting but not in active conns")
}
if c... | [
"func",
"(",
"cn",
"*",
"connection",
")",
"request",
"(",
"r",
"request",
",",
"mw",
"messageWriter",
")",
"bool",
"{",
"if",
"_",
",",
"ok",
":=",
"cn",
".",
"requests",
"[",
"r",
"]",
";",
"ok",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",... | // Proxies the messageWriter's response. | [
"Proxies",
"the",
"messageWriter",
"s",
"response",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/connection.go#L482-L535 | train |
anacrolix/torrent | connection.go | writer | func (cn *connection) writer(keepAliveTimeout time.Duration) {
var (
lastWrite time.Time = time.Now()
keepAliveTimer *time.Timer
)
keepAliveTimer = time.AfterFunc(keepAliveTimeout, func() {
cn.mu().Lock()
defer cn.mu().Unlock()
if time.Since(lastWrite) >= keepAliveTimeout {
cn.tickleWriter()
}
... | go | func (cn *connection) writer(keepAliveTimeout time.Duration) {
var (
lastWrite time.Time = time.Now()
keepAliveTimer *time.Timer
)
keepAliveTimer = time.AfterFunc(keepAliveTimeout, func() {
cn.mu().Lock()
defer cn.mu().Unlock()
if time.Since(lastWrite) >= keepAliveTimeout {
cn.tickleWriter()
}
... | [
"func",
"(",
"cn",
"*",
"connection",
")",
"writer",
"(",
"keepAliveTimeout",
"time",
".",
"Duration",
")",
"{",
"var",
"(",
"lastWrite",
"time",
".",
"Time",
"=",
"time",
".",
"Now",
"(",
")",
"\n",
"keepAliveTimer",
"*",
"time",
".",
"Timer",
"\n",
... | // Routine that writes to the peer. Some of what to write is buffered by
// activity elsewhere in the Client, and some is determined locally when the
// connection is writable. | [
"Routine",
"that",
"writes",
"to",
"the",
"peer",
".",
"Some",
"of",
"what",
"to",
"write",
"is",
"buffered",
"by",
"activity",
"elsewhere",
"in",
"the",
"Client",
"and",
"some",
"is",
"determined",
"locally",
"when",
"the",
"connection",
"is",
"writable",
... | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/connection.go#L593-L649 | train |
anacrolix/torrent | connection.go | iterBitmapsDistinct | func iterBitmapsDistinct(skip *bitmap.Bitmap, bms ...bitmap.Bitmap) iter.Func {
return func(cb iter.Callback) {
for _, bm := range bms {
if !iter.All(func(i interface{}) bool {
skip.Add(i.(int))
return cb(i)
}, bitmap.Sub(bm, *skip).Iter) {
return
}
}
}
} | go | func iterBitmapsDistinct(skip *bitmap.Bitmap, bms ...bitmap.Bitmap) iter.Func {
return func(cb iter.Callback) {
for _, bm := range bms {
if !iter.All(func(i interface{}) bool {
skip.Add(i.(int))
return cb(i)
}, bitmap.Sub(bm, *skip).Iter) {
return
}
}
}
} | [
"func",
"iterBitmapsDistinct",
"(",
"skip",
"*",
"bitmap",
".",
"Bitmap",
",",
"bms",
"...",
"bitmap",
".",
"Bitmap",
")",
"iter",
".",
"Func",
"{",
"return",
"func",
"(",
"cb",
"iter",
".",
"Callback",
")",
"{",
"for",
"_",
",",
"bm",
":=",
"range",... | // Emits the indices in the Bitmaps bms in order, never repeating any index.
// skip is mutated during execution, and its initial values will never be
// emitted. | [
"Emits",
"the",
"indices",
"in",
"the",
"Bitmaps",
"bms",
"in",
"order",
"never",
"repeating",
"any",
"index",
".",
"skip",
"is",
"mutated",
"during",
"execution",
"and",
"its",
"initial",
"values",
"will",
"never",
"be",
"emitted",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/connection.go#L684-L695 | train |
anacrolix/torrent | connection.go | shouldRequestWithoutBias | func (cn *connection) shouldRequestWithoutBias() bool {
if cn.t.requestStrategy != 2 {
return false
}
if len(cn.t.readers) == 0 {
return false
}
if len(cn.t.conns) == 1 {
return true
}
if cn == cn.t.fastestConn {
return true
}
return false
} | go | func (cn *connection) shouldRequestWithoutBias() bool {
if cn.t.requestStrategy != 2 {
return false
}
if len(cn.t.readers) == 0 {
return false
}
if len(cn.t.conns) == 1 {
return true
}
if cn == cn.t.fastestConn {
return true
}
return false
} | [
"func",
"(",
"cn",
"*",
"connection",
")",
"shouldRequestWithoutBias",
"(",
")",
"bool",
"{",
"if",
"cn",
".",
"t",
".",
"requestStrategy",
"!=",
"2",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"len",
"(",
"cn",
".",
"t",
".",
"readers",
")",
"... | // The connection should download highest priority pieces first, without any
// inclination toward avoiding wastage. Generally we might do this if there's
// a single connection, or this is the fastest connection, and we have active
// readers that signal an ordering preference. It's conceivable that the best
// connec... | [
"The",
"connection",
"should",
"download",
"highest",
"priority",
"pieces",
"first",
"without",
"any",
"inclination",
"toward",
"avoiding",
"wastage",
".",
"Generally",
"we",
"might",
"do",
"this",
"if",
"there",
"s",
"a",
"single",
"connection",
"or",
"this",
... | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/connection.go#L738-L752 | train |
anacrolix/torrent | connection.go | stopRequestingPiece | func (cn *connection) stopRequestingPiece(piece pieceIndex) bool {
return cn.pieceRequestOrder.Remove(bitmap.BitIndex(piece))
} | go | func (cn *connection) stopRequestingPiece(piece pieceIndex) bool {
return cn.pieceRequestOrder.Remove(bitmap.BitIndex(piece))
} | [
"func",
"(",
"cn",
"*",
"connection",
")",
"stopRequestingPiece",
"(",
"piece",
"pieceIndex",
")",
"bool",
"{",
"return",
"cn",
".",
"pieceRequestOrder",
".",
"Remove",
"(",
"bitmap",
".",
"BitIndex",
"(",
"piece",
")",
")",
"\n",
"}"
] | // check callers updaterequests | [
"check",
"callers",
"updaterequests"
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/connection.go#L811-L813 | train |
anacrolix/torrent | connection.go | updatePiecePriority | func (cn *connection) updatePiecePriority(piece pieceIndex) bool {
tpp := cn.t.piecePriority(piece)
if !cn.PeerHasPiece(piece) {
tpp = PiecePriorityNone
}
if tpp == PiecePriorityNone {
return cn.stopRequestingPiece(piece)
}
prio := cn.getPieceInclination()[piece]
switch cn.t.requestStrategy {
case 1:
swit... | go | func (cn *connection) updatePiecePriority(piece pieceIndex) bool {
tpp := cn.t.piecePriority(piece)
if !cn.PeerHasPiece(piece) {
tpp = PiecePriorityNone
}
if tpp == PiecePriorityNone {
return cn.stopRequestingPiece(piece)
}
prio := cn.getPieceInclination()[piece]
switch cn.t.requestStrategy {
case 1:
swit... | [
"func",
"(",
"cn",
"*",
"connection",
")",
"updatePiecePriority",
"(",
"piece",
"pieceIndex",
")",
"bool",
"{",
"tpp",
":=",
"cn",
".",
"t",
".",
"piecePriority",
"(",
"piece",
")",
"\n",
"if",
"!",
"cn",
".",
"PeerHasPiece",
"(",
"piece",
")",
"{",
... | // This is distinct from Torrent piece priority, which is the user's
// preference. Connection piece priority is specific to a connection and is
// used to pseudorandomly avoid connections always requesting the same pieces
// and thus wasting effort. | [
"This",
"is",
"distinct",
"from",
"Torrent",
"piece",
"priority",
"which",
"is",
"the",
"user",
"s",
"preference",
".",
"Connection",
"piece",
"priority",
"is",
"specific",
"to",
"a",
"connection",
"and",
"is",
"used",
"to",
"pseudorandomly",
"avoid",
"connect... | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/connection.go#L819-L843 | train |
anacrolix/torrent | connection.go | postHandshakeStats | func (cn *connection) postHandshakeStats(f func(*ConnStats)) {
t := cn.t
f(&t.stats)
f(&t.cl.stats)
} | go | func (cn *connection) postHandshakeStats(f func(*ConnStats)) {
t := cn.t
f(&t.stats)
f(&t.cl.stats)
} | [
"func",
"(",
"cn",
"*",
"connection",
")",
"postHandshakeStats",
"(",
"f",
"func",
"(",
"*",
"ConnStats",
")",
")",
"{",
"t",
":=",
"cn",
".",
"t",
"\n",
"f",
"(",
"&",
"t",
".",
"stats",
")",
"\n",
"f",
"(",
"&",
"t",
".",
"cl",
".",
"stats"... | // After handshake, we know what Torrent and Client stats to include for a
// connection. | [
"After",
"handshake",
"we",
"know",
"what",
"Torrent",
"and",
"Client",
"stats",
"to",
"include",
"for",
"a",
"connection",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/connection.go#L962-L966 | train |
anacrolix/torrent | connection.go | allStats | func (cn *connection) allStats(f func(*ConnStats)) {
f(&cn.stats)
if cn.reconciledHandshakeStats {
cn.postHandshakeStats(f)
}
} | go | func (cn *connection) allStats(f func(*ConnStats)) {
f(&cn.stats)
if cn.reconciledHandshakeStats {
cn.postHandshakeStats(f)
}
} | [
"func",
"(",
"cn",
"*",
"connection",
")",
"allStats",
"(",
"f",
"func",
"(",
"*",
"ConnStats",
")",
")",
"{",
"f",
"(",
"&",
"cn",
".",
"stats",
")",
"\n",
"if",
"cn",
".",
"reconciledHandshakeStats",
"{",
"cn",
".",
"postHandshakeStats",
"(",
"f",
... | // All ConnStats that include this connection. Some objects are not known
// until the handshake is complete, after which it's expected to reconcile the
// differences. | [
"All",
"ConnStats",
"that",
"include",
"this",
"connection",
".",
"Some",
"objects",
"are",
"not",
"known",
"until",
"the",
"handshake",
"is",
"complete",
"after",
"which",
"it",
"s",
"expected",
"to",
"reconcile",
"the",
"differences",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/connection.go#L971-L976 | train |
anacrolix/torrent | connection.go | useful | func (c *connection) useful() bool {
t := c.t
if c.closed.IsSet() {
return false
}
if !t.haveInfo() {
return c.supportsExtension("ut_metadata")
}
if t.seeding() && c.PeerInterested {
return true
}
if c.peerHasWantedPieces() {
return true
}
return false
} | go | func (c *connection) useful() bool {
t := c.t
if c.closed.IsSet() {
return false
}
if !t.haveInfo() {
return c.supportsExtension("ut_metadata")
}
if t.seeding() && c.PeerInterested {
return true
}
if c.peerHasWantedPieces() {
return true
}
return false
} | [
"func",
"(",
"c",
"*",
"connection",
")",
"useful",
"(",
")",
"bool",
"{",
"t",
":=",
"c",
".",
"t",
"\n",
"if",
"c",
".",
"closed",
".",
"IsSet",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"!",
"t",
".",
"haveInfo",
"(",
")",
... | // Returns whether the connection could be useful to us. We're seeding and
// they want data, we don't have metainfo and they can provide it, etc. | [
"Returns",
"whether",
"the",
"connection",
"could",
"be",
"useful",
"to",
"us",
".",
"We",
"re",
"seeding",
"and",
"they",
"want",
"data",
"we",
"don",
"t",
"have",
"metainfo",
"and",
"they",
"can",
"provide",
"it",
"etc",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/connection.go#L988-L1003 | train |
anacrolix/torrent | connection.go | setRW | func (cn *connection) setRW(rw io.ReadWriter) {
cn.r = rw
cn.w = rw
} | go | func (cn *connection) setRW(rw io.ReadWriter) {
cn.r = rw
cn.w = rw
} | [
"func",
"(",
"cn",
"*",
"connection",
")",
"setRW",
"(",
"rw",
"io",
".",
"ReadWriter",
")",
"{",
"cn",
".",
"r",
"=",
"rw",
"\n",
"cn",
".",
"w",
"=",
"rw",
"\n",
"}"
] | // Set both the Reader and Writer for the connection from a single ReadWriter. | [
"Set",
"both",
"the",
"Reader",
"and",
"Writer",
"for",
"the",
"connection",
"from",
"a",
"single",
"ReadWriter",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/connection.go#L1253-L1256 | train |
anacrolix/torrent | connection.go | rw | func (cn *connection) rw() io.ReadWriter {
return struct {
io.Reader
io.Writer
}{cn.r, cn.w}
} | go | func (cn *connection) rw() io.ReadWriter {
return struct {
io.Reader
io.Writer
}{cn.r, cn.w}
} | [
"func",
"(",
"cn",
"*",
"connection",
")",
"rw",
"(",
")",
"io",
".",
"ReadWriter",
"{",
"return",
"struct",
"{",
"io",
".",
"Reader",
"\n",
"io",
".",
"Writer",
"\n",
"}",
"{",
"cn",
".",
"r",
",",
"cn",
".",
"w",
"}",
"\n",
"}"
] | // Returns the Reader and Writer as a combined ReadWriter. | [
"Returns",
"the",
"Reader",
"and",
"Writer",
"as",
"a",
"combined",
"ReadWriter",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/connection.go#L1259-L1264 | train |
anacrolix/torrent | connection.go | upload | func (c *connection) upload(msg func(pp.Message) bool) bool {
// Breaking or completing this loop means we don't want to upload to the
// peer anymore, and we choke them.
another:
for c.uploadAllowed() {
// We want to upload to the peer.
if !c.Unchoke(msg) {
return false
}
for r := range c.PeerRequests {
... | go | func (c *connection) upload(msg func(pp.Message) bool) bool {
// Breaking or completing this loop means we don't want to upload to the
// peer anymore, and we choke them.
another:
for c.uploadAllowed() {
// We want to upload to the peer.
if !c.Unchoke(msg) {
return false
}
for r := range c.PeerRequests {
... | [
"func",
"(",
"c",
"*",
"connection",
")",
"upload",
"(",
"msg",
"func",
"(",
"pp",
".",
"Message",
")",
"bool",
")",
"bool",
"{",
"// Breaking or completing this loop means we don't want to upload to the",
"// peer anymore, and we choke them.",
"another",
":",
"for",
... | // Also handles choking and unchoking of the remote peer. | [
"Also",
"handles",
"choking",
"and",
"unchoking",
"of",
"the",
"remote",
"peer",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/connection.go#L1400-L1448 | train |
anacrolix/torrent | iplist/iplist.go | Lookup | func (ipl *IPList) Lookup(ip net.IP) (r Range, ok bool) {
if ipl == nil {
return
}
// TODO: Perhaps all addresses should be converted to IPv6, if the future
// of IP is to always be backwards compatible. But this will cost 4x the
// memory for IPv4 addresses?
v4 := ip.To4()
if v4 != nil {
r, ok = ipl.lookup(... | go | func (ipl *IPList) Lookup(ip net.IP) (r Range, ok bool) {
if ipl == nil {
return
}
// TODO: Perhaps all addresses should be converted to IPv6, if the future
// of IP is to always be backwards compatible. But this will cost 4x the
// memory for IPv4 addresses?
v4 := ip.To4()
if v4 != nil {
r, ok = ipl.lookup(... | [
"func",
"(",
"ipl",
"*",
"IPList",
")",
"Lookup",
"(",
"ip",
"net",
".",
"IP",
")",
"(",
"r",
"Range",
",",
"ok",
"bool",
")",
"{",
"if",
"ipl",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"// TODO: Perhaps all addresses should be converted to IPv6, if th... | // Return the range the given IP is in. ok if false if no range is found. | [
"Return",
"the",
"range",
"the",
"given",
"IP",
"is",
"in",
".",
"ok",
"if",
"false",
"if",
"no",
"range",
"is",
"found",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/iplist/iplist.go#L53-L78 | train |
anacrolix/torrent | iplist/iplist.go | lookup | func lookup(
first func(i int) net.IP,
full func(i int) Range,
n int,
ip net.IP,
) (
r Range, ok bool,
) {
// Find the index of the first range for which the following range exceeds
// it.
i := sort.Search(n, func(i int) bool {
if i+1 >= n {
return true
}
return bytes.Compare(ip, first(i+1)) < 0
})
i... | go | func lookup(
first func(i int) net.IP,
full func(i int) Range,
n int,
ip net.IP,
) (
r Range, ok bool,
) {
// Find the index of the first range for which the following range exceeds
// it.
i := sort.Search(n, func(i int) bool {
if i+1 >= n {
return true
}
return bytes.Compare(ip, first(i+1)) < 0
})
i... | [
"func",
"lookup",
"(",
"first",
"func",
"(",
"i",
"int",
")",
"net",
".",
"IP",
",",
"full",
"func",
"(",
"i",
"int",
")",
"Range",
",",
"n",
"int",
",",
"ip",
"net",
".",
"IP",
",",
")",
"(",
"r",
"Range",
",",
"ok",
"bool",
",",
")",
"{",... | // Return a range that contains ip, or nil. | [
"Return",
"a",
"range",
"that",
"contains",
"ip",
"or",
"nil",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/iplist/iplist.go#L81-L103 | train |
anacrolix/torrent | iplist/iplist.go | lookup | func (ipl *IPList) lookup(ip net.IP) (Range, bool) {
return lookup(func(i int) net.IP {
return ipl.ranges[i].First
}, func(i int) Range {
return ipl.ranges[i]
}, len(ipl.ranges), ip)
} | go | func (ipl *IPList) lookup(ip net.IP) (Range, bool) {
return lookup(func(i int) net.IP {
return ipl.ranges[i].First
}, func(i int) Range {
return ipl.ranges[i]
}, len(ipl.ranges), ip)
} | [
"func",
"(",
"ipl",
"*",
"IPList",
")",
"lookup",
"(",
"ip",
"net",
".",
"IP",
")",
"(",
"Range",
",",
"bool",
")",
"{",
"return",
"lookup",
"(",
"func",
"(",
"i",
"int",
")",
"net",
".",
"IP",
"{",
"return",
"ipl",
".",
"ranges",
"[",
"i",
"... | // Return the range the given IP is in. Returns nil if no range is found. | [
"Return",
"the",
"range",
"the",
"given",
"IP",
"is",
"in",
".",
"Returns",
"nil",
"if",
"no",
"range",
"is",
"found",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/iplist/iplist.go#L106-L112 | train |
anacrolix/torrent | iplist/iplist.go | NewFromReader | func NewFromReader(f io.Reader) (ret *IPList, err error) {
var ranges []Range
// There's a lot of similar descriptions, so we maintain a pool and reuse
// them to reduce memory overhead.
uniqStrs := make(map[string]string)
scanner := bufio.NewScanner(f)
lineNum := 1
for scanner.Scan() {
r, ok, lineErr := Parse... | go | func NewFromReader(f io.Reader) (ret *IPList, err error) {
var ranges []Range
// There's a lot of similar descriptions, so we maintain a pool and reuse
// them to reduce memory overhead.
uniqStrs := make(map[string]string)
scanner := bufio.NewScanner(f)
lineNum := 1
for scanner.Scan() {
r, ok, lineErr := Parse... | [
"func",
"NewFromReader",
"(",
"f",
"io",
".",
"Reader",
")",
"(",
"ret",
"*",
"IPList",
",",
"err",
"error",
")",
"{",
"var",
"ranges",
"[",
"]",
"Range",
"\n",
"// There's a lot of similar descriptions, so we maintain a pool and reuse",
"// them to reduce memory over... | // Creates an IPList from a line-delimited P2P Plaintext file. | [
"Creates",
"an",
"IPList",
"from",
"a",
"line",
"-",
"delimited",
"P2P",
"Plaintext",
"file",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/iplist/iplist.go#L155-L185 | train |
anacrolix/torrent | bencode/api.go | Unmarshal | func Unmarshal(data []byte, v interface{}) (err error) {
buf := bytes.NewBuffer(data)
e := Decoder{r: buf}
err = e.Decode(v)
if err == nil && buf.Len() != 0 {
err = ErrUnusedTrailingBytes{buf.Len()}
}
return
} | go | func Unmarshal(data []byte, v interface{}) (err error) {
buf := bytes.NewBuffer(data)
e := Decoder{r: buf}
err = e.Decode(v)
if err == nil && buf.Len() != 0 {
err = ErrUnusedTrailingBytes{buf.Len()}
}
return
} | [
"func",
"Unmarshal",
"(",
"data",
"[",
"]",
"byte",
",",
"v",
"interface",
"{",
"}",
")",
"(",
"err",
"error",
")",
"{",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"data",
")",
"\n",
"e",
":=",
"Decoder",
"{",
"r",
":",
"buf",
"}",
"\n",
"err... | // Unmarshal the bencode value in the 'data' to a value pointed by the 'v'
// pointer, return a non-nil error if any. | [
"Unmarshal",
"the",
"bencode",
"value",
"in",
"the",
"data",
"to",
"a",
"value",
"pointed",
"by",
"the",
"v",
"pointer",
"return",
"a",
"non",
"-",
"nil",
"error",
"if",
"any",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/bencode/api.go#L133-L141 | train |
anacrolix/torrent | reader.go | SetResponsive | func (r *reader) SetResponsive() {
r.responsive = true
r.t.cl.event.Broadcast()
} | go | func (r *reader) SetResponsive() {
r.responsive = true
r.t.cl.event.Broadcast()
} | [
"func",
"(",
"r",
"*",
"reader",
")",
"SetResponsive",
"(",
")",
"{",
"r",
".",
"responsive",
"=",
"true",
"\n",
"r",
".",
"t",
".",
"cl",
".",
"event",
".",
"Broadcast",
"(",
")",
"\n",
"}"
] | // Don't wait for pieces to complete and be verified. Read calls return as
// soon as they can when the underlying chunks become available. | [
"Don",
"t",
"wait",
"for",
"pieces",
"to",
"complete",
"and",
"be",
"verified",
".",
"Read",
"calls",
"return",
"as",
"soon",
"as",
"they",
"can",
"when",
"the",
"underlying",
"chunks",
"become",
"available",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/reader.go#L54-L57 | train |
anacrolix/torrent | reader.go | SetReadahead | func (r *reader) SetReadahead(readahead int64) {
r.mu.Lock()
r.readahead = readahead
r.mu.Unlock()
r.t.cl.lock()
defer r.t.cl.unlock()
r.posChanged()
} | go | func (r *reader) SetReadahead(readahead int64) {
r.mu.Lock()
r.readahead = readahead
r.mu.Unlock()
r.t.cl.lock()
defer r.t.cl.unlock()
r.posChanged()
} | [
"func",
"(",
"r",
"*",
"reader",
")",
"SetReadahead",
"(",
"readahead",
"int64",
")",
"{",
"r",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"r",
".",
"readahead",
"=",
"readahead",
"\n",
"r",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"r",
".",
"t",... | // Configure the number of bytes ahead of a read that should also be
// prioritized in preparation for further reads. | [
"Configure",
"the",
"number",
"of",
"bytes",
"ahead",
"of",
"a",
"read",
"that",
"should",
"also",
"be",
"prioritized",
"in",
"preparation",
"for",
"further",
"reads",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/reader.go#L67-L74 | train |
anacrolix/torrent | reader.go | available | func (r *reader) available(off, max int64) (ret int64) {
off += r.offset
for max > 0 {
req, ok := r.t.offsetRequest(off)
if !ok {
break
}
if !r.t.haveChunk(req) {
break
}
len1 := int64(req.Length) - (off - r.t.requestOffset(req))
max -= len1
ret += len1
off += len1
}
// Ensure that ret hasn'... | go | func (r *reader) available(off, max int64) (ret int64) {
off += r.offset
for max > 0 {
req, ok := r.t.offsetRequest(off)
if !ok {
break
}
if !r.t.haveChunk(req) {
break
}
len1 := int64(req.Length) - (off - r.t.requestOffset(req))
max -= len1
ret += len1
off += len1
}
// Ensure that ret hasn'... | [
"func",
"(",
"r",
"*",
"reader",
")",
"available",
"(",
"off",
",",
"max",
"int64",
")",
"(",
"ret",
"int64",
")",
"{",
"off",
"+=",
"r",
".",
"offset",
"\n",
"for",
"max",
">",
"0",
"{",
"req",
",",
"ok",
":=",
"r",
".",
"t",
".",
"offsetReq... | // How many bytes are available to read. Max is the most we could require. | [
"How",
"many",
"bytes",
"are",
"available",
"to",
"read",
".",
"Max",
"is",
"the",
"most",
"we",
"could",
"require",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/reader.go#L91-L111 | train |
anacrolix/torrent | reader.go | piecesUncached | func (r *reader) piecesUncached() (ret pieceRange) {
ra := r.readahead
if ra < 1 {
// Needs to be at least 1, because [x, x) means we don't want
// anything.
ra = 1
}
if ra > r.length-r.pos {
ra = r.length - r.pos
}
ret.begin, ret.end = r.t.byteRegionPieces(r.torrentOffset(r.pos), ra)
return
} | go | func (r *reader) piecesUncached() (ret pieceRange) {
ra := r.readahead
if ra < 1 {
// Needs to be at least 1, because [x, x) means we don't want
// anything.
ra = 1
}
if ra > r.length-r.pos {
ra = r.length - r.pos
}
ret.begin, ret.end = r.t.byteRegionPieces(r.torrentOffset(r.pos), ra)
return
} | [
"func",
"(",
"r",
"*",
"reader",
")",
"piecesUncached",
"(",
")",
"(",
"ret",
"pieceRange",
")",
"{",
"ra",
":=",
"r",
".",
"readahead",
"\n",
"if",
"ra",
"<",
"1",
"{",
"// Needs to be at least 1, because [x, x) means we don't want",
"// anything.",
"ra",
"="... | // Calculates the pieces this reader wants downloaded, ignoring the cached
// value at r.pieces. | [
"Calculates",
"the",
"pieces",
"this",
"reader",
"wants",
"downloaded",
"ignoring",
"the",
"cached",
"value",
"at",
"r",
".",
"pieces",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/reader.go#L121-L133 | train |
anacrolix/torrent | reader.go | waitAvailable | func (r *reader) waitAvailable(pos, wanted int64, ctxErr *error) (avail int64) {
r.t.cl.lock()
defer r.t.cl.unlock()
for !r.readable(pos) && *ctxErr == nil {
r.waitReadable(pos)
}
return r.available(pos, wanted)
} | go | func (r *reader) waitAvailable(pos, wanted int64, ctxErr *error) (avail int64) {
r.t.cl.lock()
defer r.t.cl.unlock()
for !r.readable(pos) && *ctxErr == nil {
r.waitReadable(pos)
}
return r.available(pos, wanted)
} | [
"func",
"(",
"r",
"*",
"reader",
")",
"waitAvailable",
"(",
"pos",
",",
"wanted",
"int64",
",",
"ctxErr",
"*",
"error",
")",
"(",
"avail",
"int64",
")",
"{",
"r",
".",
"t",
".",
"cl",
".",
"lock",
"(",
")",
"\n",
"defer",
"r",
".",
"t",
".",
... | // Wait until some data should be available to read. Tickles the client if it
// isn't. Returns how much should be readable without blocking. | [
"Wait",
"until",
"some",
"data",
"should",
"be",
"available",
"to",
"read",
".",
"Tickles",
"the",
"client",
"if",
"it",
"isn",
"t",
".",
"Returns",
"how",
"much",
"should",
"be",
"readable",
"without",
"blocking",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/reader.go#L184-L191 | train |
anacrolix/torrent | reader.go | readOnceAt | func (r *reader) readOnceAt(b []byte, pos int64, ctxErr *error) (n int, err error) {
if pos >= r.length {
err = io.EOF
return
}
for {
avail := r.waitAvailable(pos, int64(len(b)), ctxErr)
if avail == 0 {
if r.t.closed.IsSet() {
err = errors.New("torrent closed")
return
}
if *ctxErr != nil {
... | go | func (r *reader) readOnceAt(b []byte, pos int64, ctxErr *error) (n int, err error) {
if pos >= r.length {
err = io.EOF
return
}
for {
avail := r.waitAvailable(pos, int64(len(b)), ctxErr)
if avail == 0 {
if r.t.closed.IsSet() {
err = errors.New("torrent closed")
return
}
if *ctxErr != nil {
... | [
"func",
"(",
"r",
"*",
"reader",
")",
"readOnceAt",
"(",
"b",
"[",
"]",
"byte",
",",
"pos",
"int64",
",",
"ctxErr",
"*",
"error",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"if",
"pos",
">=",
"r",
".",
"length",
"{",
"err",
"=",
"io... | // Performs at most one successful read to torrent storage. | [
"Performs",
"at",
"most",
"one",
"successful",
"read",
"to",
"torrent",
"storage",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/reader.go#L198-L234 | train |
anacrolix/torrent | tracker/udp.go | write | func (c *udpAnnounce) write(h *RequestHeader, body interface{}, trailer []byte) (err error) {
var buf bytes.Buffer
err = binary.Write(&buf, binary.BigEndian, h)
if err != nil {
panic(err)
}
if body != nil {
err = binary.Write(&buf, binary.BigEndian, body)
if err != nil {
panic(err)
}
}
_, err = buf.Wr... | go | func (c *udpAnnounce) write(h *RequestHeader, body interface{}, trailer []byte) (err error) {
var buf bytes.Buffer
err = binary.Write(&buf, binary.BigEndian, h)
if err != nil {
panic(err)
}
if body != nil {
err = binary.Write(&buf, binary.BigEndian, body)
if err != nil {
panic(err)
}
}
_, err = buf.Wr... | [
"func",
"(",
"c",
"*",
"udpAnnounce",
")",
"write",
"(",
"h",
"*",
"RequestHeader",
",",
"body",
"interface",
"{",
"}",
",",
"trailer",
"[",
"]",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"err",
"=",
... | // body is the binary serializable request body. trailer is optional data
// following it, such as for BEP 41. | [
"body",
"is",
"the",
"binary",
"serializable",
"request",
"body",
".",
"trailer",
"is",
"optional",
"data",
"following",
"it",
"such",
"as",
"for",
"BEP",
"41",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/tracker/udp.go#L156-L180 | train |
anacrolix/torrent | tracker/udp.go | request | func (c *udpAnnounce) request(action Action, args interface{}, options []byte) (*bytes.Buffer, error) {
tid := newTransactionId()
if err := errors.Wrap(
c.write(
&RequestHeader{
ConnectionId: c.connectionId,
Action: action,
TransactionId: tid,
}, args, options),
"writing request",
); er... | go | func (c *udpAnnounce) request(action Action, args interface{}, options []byte) (*bytes.Buffer, error) {
tid := newTransactionId()
if err := errors.Wrap(
c.write(
&RequestHeader{
ConnectionId: c.connectionId,
Action: action,
TransactionId: tid,
}, args, options),
"writing request",
); er... | [
"func",
"(",
"c",
"*",
"udpAnnounce",
")",
"request",
"(",
"action",
"Action",
",",
"args",
"interface",
"{",
"}",
",",
"options",
"[",
"]",
"byte",
")",
"(",
"*",
"bytes",
".",
"Buffer",
",",
"error",
")",
"{",
"tid",
":=",
"newTransactionId",
"(",
... | // args is the binary serializable request body. trailer is optional data
// following it, such as for BEP 41. | [
"args",
"is",
"the",
"binary",
"serializable",
"request",
"body",
".",
"trailer",
"is",
"optional",
"data",
"following",
"it",
"such",
"as",
"for",
"BEP",
"41",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/tracker/udp.go#L192-L251 | train |
anacrolix/torrent | misc.go | metadataPieceSize | func metadataPieceSize(totalSize int, piece int) int {
ret := totalSize - piece*(1<<14)
if ret > 1<<14 {
ret = 1 << 14
}
return ret
} | go | func metadataPieceSize(totalSize int, piece int) int {
ret := totalSize - piece*(1<<14)
if ret > 1<<14 {
ret = 1 << 14
}
return ret
} | [
"func",
"metadataPieceSize",
"(",
"totalSize",
"int",
",",
"piece",
"int",
")",
"int",
"{",
"ret",
":=",
"totalSize",
"-",
"piece",
"*",
"(",
"1",
"<<",
"14",
")",
"\n",
"if",
"ret",
">",
"1",
"<<",
"14",
"{",
"ret",
"=",
"1",
"<<",
"14",
"\n",
... | // The size in bytes of a metadata extension piece. | [
"The",
"size",
"in",
"bytes",
"of",
"a",
"metadata",
"extension",
"piece",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/misc.go#L47-L53 | train |
anacrolix/torrent | misc.go | torrentOffsetRequest | func torrentOffsetRequest(torrentLength, pieceSize, chunkSize, offset int64) (
r request, ok bool) {
if offset < 0 || offset >= torrentLength {
return
}
r.Index = pp.Integer(offset / pieceSize)
r.Begin = pp.Integer(offset % pieceSize / chunkSize * chunkSize)
r.Length = pp.Integer(chunkSize)
pieceLeft := pp.Int... | go | func torrentOffsetRequest(torrentLength, pieceSize, chunkSize, offset int64) (
r request, ok bool) {
if offset < 0 || offset >= torrentLength {
return
}
r.Index = pp.Integer(offset / pieceSize)
r.Begin = pp.Integer(offset % pieceSize / chunkSize * chunkSize)
r.Length = pp.Integer(chunkSize)
pieceLeft := pp.Int... | [
"func",
"torrentOffsetRequest",
"(",
"torrentLength",
",",
"pieceSize",
",",
"chunkSize",
",",
"offset",
"int64",
")",
"(",
"r",
"request",
",",
"ok",
"bool",
")",
"{",
"if",
"offset",
"<",
"0",
"||",
"offset",
">=",
"torrentLength",
"{",
"return",
"\n",
... | // Return the request that would include the given offset into the torrent data. | [
"Return",
"the",
"request",
"that",
"would",
"include",
"the",
"given",
"offset",
"into",
"the",
"torrent",
"data",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/misc.go#L56-L74 | train |
anacrolix/torrent | peer_protocol/handshake.go | Handshake | func Handshake(sock io.ReadWriter, ih *metainfo.Hash, peerID [20]byte, extensions PeerExtensionBits) (res HandshakeResult, ok bool, err error) {
// Bytes to be sent to the peer. Should never block the sender.
postCh := make(chan []byte, 4)
// A single error value sent when the writer completes.
writeDone := make(ch... | go | func Handshake(sock io.ReadWriter, ih *metainfo.Hash, peerID [20]byte, extensions PeerExtensionBits) (res HandshakeResult, ok bool, err error) {
// Bytes to be sent to the peer. Should never block the sender.
postCh := make(chan []byte, 4)
// A single error value sent when the writer completes.
writeDone := make(ch... | [
"func",
"Handshake",
"(",
"sock",
"io",
".",
"ReadWriter",
",",
"ih",
"*",
"metainfo",
".",
"Hash",
",",
"peerID",
"[",
"20",
"]",
"byte",
",",
"extensions",
"PeerExtensionBits",
")",
"(",
"res",
"HandshakeResult",
",",
"ok",
"bool",
",",
"err",
"error",... | // ih is nil if we expect the peer to declare the InfoHash, such as when the
// peer initiated the connection. Returns ok if the Handshake was successful,
// and err if there was an unexpected condition other than the peer simply
// abandoning the Handshake. | [
"ih",
"is",
"nil",
"if",
"we",
"expect",
"the",
"peer",
"to",
"declare",
"the",
"InfoHash",
"such",
"as",
"when",
"the",
"peer",
"initiated",
"the",
"connection",
".",
"Returns",
"ok",
"if",
"the",
"Handshake",
"was",
"successful",
"and",
"err",
"if",
"t... | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/peer_protocol/handshake.go#L76-L137 | train |
anacrolix/torrent | bencode/decode.go | readUntil | func (d *Decoder) readUntil(sep byte) {
for {
b := d.readByte()
if b == sep {
return
}
d.buf.WriteByte(b)
}
} | go | func (d *Decoder) readUntil(sep byte) {
for {
b := d.readByte()
if b == sep {
return
}
d.buf.WriteByte(b)
}
} | [
"func",
"(",
"d",
"*",
"Decoder",
")",
"readUntil",
"(",
"sep",
"byte",
")",
"{",
"for",
"{",
"b",
":=",
"d",
".",
"readByte",
"(",
")",
"\n",
"if",
"b",
"==",
"sep",
"{",
"return",
"\n",
"}",
"\n",
"d",
".",
"buf",
".",
"WriteByte",
"(",
"b"... | // reads data writing it to 'd.buf' until 'sep' byte is encountered, 'sep' byte
// is consumed, but not included into the 'd.buf' | [
"reads",
"data",
"writing",
"it",
"to",
"d",
".",
"buf",
"until",
"sep",
"byte",
"is",
"encountered",
"sep",
"byte",
"is",
"consumed",
"but",
"not",
"included",
"into",
"the",
"d",
".",
"buf"
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/bencode/decode.go#L78-L86 | train |
anacrolix/torrent | bencode/decode.go | parseInt | func (d *Decoder) parseInt(v reflect.Value) {
start := d.Offset - 1
d.readUntil('e')
if d.buf.Len() == 0 {
panic(&SyntaxError{
Offset: start,
What: errors.New("empty integer value"),
})
}
s := bytesAsString(d.buf.Bytes())
switch v.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int3... | go | func (d *Decoder) parseInt(v reflect.Value) {
start := d.Offset - 1
d.readUntil('e')
if d.buf.Len() == 0 {
panic(&SyntaxError{
Offset: start,
What: errors.New("empty integer value"),
})
}
s := bytesAsString(d.buf.Bytes())
switch v.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int3... | [
"func",
"(",
"d",
"*",
"Decoder",
")",
"parseInt",
"(",
"v",
"reflect",
".",
"Value",
")",
"{",
"start",
":=",
"d",
".",
"Offset",
"-",
"1",
"\n",
"d",
".",
"readUntil",
"(",
"'e'",
")",
"\n",
"if",
"d",
".",
"buf",
".",
"Len",
"(",
")",
"=="... | // called when 'i' was consumed | [
"called",
"when",
"i",
"was",
"consumed"
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/bencode/decode.go#L105-L149 | train |
anacrolix/torrent | bencode/decode.go | getDictField | func getDictField(dict reflect.Value, key string) dictField {
// get valuev as a map value or as a struct field
switch dict.Kind() {
case reflect.Map:
value := reflect.New(dict.Type().Elem()).Elem()
return dictField{
Value: value,
Ok: true,
Set: func() {
if dict.IsNil() {
dict.Set(reflect.Ma... | go | func getDictField(dict reflect.Value, key string) dictField {
// get valuev as a map value or as a struct field
switch dict.Kind() {
case reflect.Map:
value := reflect.New(dict.Type().Elem()).Elem()
return dictField{
Value: value,
Ok: true,
Set: func() {
if dict.IsNil() {
dict.Set(reflect.Ma... | [
"func",
"getDictField",
"(",
"dict",
"reflect",
".",
"Value",
",",
"key",
"string",
")",
"dictField",
"{",
"// get valuev as a map value or as a struct field",
"switch",
"dict",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Map",
":",
"value",
":=",
"re... | // Returns specifics for parsing a dict field value. | [
"Returns",
"specifics",
"for",
"parsing",
"a",
"dict",
"field",
"value",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/bencode/decode.go#L217-L254 | train |
anacrolix/torrent | bencode/decode.go | raiseUnknownValueType | func (d *Decoder) raiseUnknownValueType(b byte, offset int64) {
panic(&SyntaxError{
Offset: offset,
What: fmt.Errorf("unknown value type %+q", b),
})
} | go | func (d *Decoder) raiseUnknownValueType(b byte, offset int64) {
panic(&SyntaxError{
Offset: offset,
What: fmt.Errorf("unknown value type %+q", b),
})
} | [
"func",
"(",
"d",
"*",
"Decoder",
")",
"raiseUnknownValueType",
"(",
"b",
"byte",
",",
"offset",
"int64",
")",
"{",
"panic",
"(",
"&",
"SyntaxError",
"{",
"Offset",
":",
"offset",
",",
"What",
":",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"b",
"... | // An unknown bencode type character was encountered. | [
"An",
"unknown",
"bencode",
"type",
"character",
"was",
"encountered",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/bencode/decode.go#L520-L525 | train |
anacrolix/torrent | tracker_scraper.go | announce | func (me *trackerScraper) announce() (ret trackerAnnounceResult) {
defer func() {
ret.Completed = time.Now()
}()
ret.Interval = 5 * time.Minute
ip, err := me.getIp()
if err != nil {
ret.Err = fmt.Errorf("error getting ip: %s", err)
return
}
me.t.cl.lock()
req := me.t.announceRequest()
me.t.cl.unlock()
r... | go | func (me *trackerScraper) announce() (ret trackerAnnounceResult) {
defer func() {
ret.Completed = time.Now()
}()
ret.Interval = 5 * time.Minute
ip, err := me.getIp()
if err != nil {
ret.Err = fmt.Errorf("error getting ip: %s", err)
return
}
me.t.cl.lock()
req := me.t.announceRequest()
me.t.cl.unlock()
r... | [
"func",
"(",
"me",
"*",
"trackerScraper",
")",
"announce",
"(",
")",
"(",
"ret",
"trackerAnnounceResult",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"ret",
".",
"Completed",
"=",
"time",
".",
"Now",
"(",
")",
"\n",
"}",
"(",
")",
"\n",
"ret",
".",
... | // Return how long to wait before trying again. For most errors, we return 5
// minutes, a relatively quick turn around for DNS changes. | [
"Return",
"how",
"long",
"to",
"wait",
"before",
"trying",
"again",
".",
"For",
"most",
"errors",
"we",
"return",
"5",
"minutes",
"a",
"relatively",
"quick",
"turn",
"around",
"for",
"DNS",
"changes",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/tracker_scraper.go#L99-L131 | train |
anacrolix/torrent | iplist/cidr.go | IPNetLast | func IPNetLast(in *net.IPNet) (last net.IP) {
n := len(in.IP)
if n != len(in.Mask) {
panic("wat")
}
last = make(net.IP, n)
for i := 0; i < n; i++ {
last[i] = in.IP[i] | ^in.Mask[i]
}
return
} | go | func IPNetLast(in *net.IPNet) (last net.IP) {
n := len(in.IP)
if n != len(in.Mask) {
panic("wat")
}
last = make(net.IP, n)
for i := 0; i < n; i++ {
last[i] = in.IP[i] | ^in.Mask[i]
}
return
} | [
"func",
"IPNetLast",
"(",
"in",
"*",
"net",
".",
"IPNet",
")",
"(",
"last",
"net",
".",
"IP",
")",
"{",
"n",
":=",
"len",
"(",
"in",
".",
"IP",
")",
"\n",
"if",
"n",
"!=",
"len",
"(",
"in",
".",
"Mask",
")",
"{",
"panic",
"(",
"\"",
"\"",
... | // Returns the last, inclusive IP in a net.IPNet. | [
"Returns",
"the",
"last",
"inclusive",
"IP",
"in",
"a",
"net",
".",
"IPNet",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/iplist/cidr.go#L31-L41 | train |
anacrolix/torrent | bencode/encode.go | reflectMarshaler | func (e *Encoder) reflectMarshaler(v reflect.Value) bool {
if !v.Type().Implements(marshalerType) {
if v.Kind() != reflect.Ptr && v.CanAddr() && v.Addr().Type().Implements(marshalerType) {
v = v.Addr()
} else {
return false
}
}
m := v.Interface().(Marshaler)
data, err := m.MarshalBencode()
if err != ni... | go | func (e *Encoder) reflectMarshaler(v reflect.Value) bool {
if !v.Type().Implements(marshalerType) {
if v.Kind() != reflect.Ptr && v.CanAddr() && v.Addr().Type().Implements(marshalerType) {
v = v.Addr()
} else {
return false
}
}
m := v.Interface().(Marshaler)
data, err := m.MarshalBencode()
if err != ni... | [
"func",
"(",
"e",
"*",
"Encoder",
")",
"reflectMarshaler",
"(",
"v",
"reflect",
".",
"Value",
")",
"bool",
"{",
"if",
"!",
"v",
".",
"Type",
"(",
")",
".",
"Implements",
"(",
"marshalerType",
")",
"{",
"if",
"v",
".",
"Kind",
"(",
")",
"!=",
"ref... | // Returns true if the value implements Marshaler interface and marshaling was
// done successfully. | [
"Returns",
"true",
"if",
"the",
"value",
"implements",
"Marshaler",
"interface",
"and",
"marshaling",
"was",
"done",
"successfully",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/bencode/encode.go#L82-L97 | train |
anacrolix/torrent | file.go | DisplayPath | func (f *File) DisplayPath() string {
fip := f.FileInfo().Path
if len(fip) == 0 {
return f.t.info.Name
}
return strings.Join(fip, "/")
} | go | func (f *File) DisplayPath() string {
fip := f.FileInfo().Path
if len(fip) == 0 {
return f.t.info.Name
}
return strings.Join(fip, "/")
} | [
"func",
"(",
"f",
"*",
"File",
")",
"DisplayPath",
"(",
")",
"string",
"{",
"fip",
":=",
"f",
".",
"FileInfo",
"(",
")",
".",
"Path",
"\n",
"if",
"len",
"(",
"fip",
")",
"==",
"0",
"{",
"return",
"f",
".",
"t",
".",
"info",
".",
"Name",
"\n",... | // The relative file path for a multi-file torrent, and the torrent name for a
// single-file torrent. | [
"The",
"relative",
"file",
"path",
"for",
"a",
"multi",
"-",
"file",
"torrent",
"and",
"the",
"torrent",
"name",
"for",
"a",
"single",
"-",
"file",
"torrent",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/file.go#L45-L52 | train |
anacrolix/torrent | file.go | State | func (f *File) State() (ret []FilePieceState) {
f.t.cl.rLock()
defer f.t.cl.rUnlock()
pieceSize := int64(f.t.usualPieceSize())
off := f.offset % pieceSize
remaining := f.length
for i := pieceIndex(f.offset / pieceSize); ; i++ {
if remaining == 0 {
break
}
len1 := pieceSize - off
if len1 > remaining {
... | go | func (f *File) State() (ret []FilePieceState) {
f.t.cl.rLock()
defer f.t.cl.rUnlock()
pieceSize := int64(f.t.usualPieceSize())
off := f.offset % pieceSize
remaining := f.length
for i := pieceIndex(f.offset / pieceSize); ; i++ {
if remaining == 0 {
break
}
len1 := pieceSize - off
if len1 > remaining {
... | [
"func",
"(",
"f",
"*",
"File",
")",
"State",
"(",
")",
"(",
"ret",
"[",
"]",
"FilePieceState",
")",
"{",
"f",
".",
"t",
".",
"cl",
".",
"rLock",
"(",
")",
"\n",
"defer",
"f",
".",
"t",
".",
"cl",
".",
"rUnlock",
"(",
")",
"\n",
"pieceSize",
... | // Returns the state of pieces in this file. | [
"Returns",
"the",
"state",
"of",
"pieces",
"in",
"this",
"file",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/file.go#L61-L81 | train |
anacrolix/torrent | file.go | SetPriority | func (f *File) SetPriority(prio piecePriority) {
f.t.cl.lock()
defer f.t.cl.unlock()
if prio == f.prio {
return
}
f.prio = prio
f.t.updatePiecePriorities(f.firstPieceIndex(), f.endPieceIndex())
} | go | func (f *File) SetPriority(prio piecePriority) {
f.t.cl.lock()
defer f.t.cl.unlock()
if prio == f.prio {
return
}
f.prio = prio
f.t.updatePiecePriorities(f.firstPieceIndex(), f.endPieceIndex())
} | [
"func",
"(",
"f",
"*",
"File",
")",
"SetPriority",
"(",
"prio",
"piecePriority",
")",
"{",
"f",
".",
"t",
".",
"cl",
".",
"lock",
"(",
")",
"\n",
"defer",
"f",
".",
"t",
".",
"cl",
".",
"unlock",
"(",
")",
"\n",
"if",
"prio",
"==",
"f",
".",
... | // Sets the minimum priority for pieces in the File. | [
"Sets",
"the",
"minimum",
"priority",
"for",
"pieces",
"in",
"the",
"File",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/file.go#L112-L120 | train |
anacrolix/torrent | file.go | Priority | func (f *File) Priority() piecePriority {
f.t.cl.lock()
defer f.t.cl.unlock()
return f.prio
} | go | func (f *File) Priority() piecePriority {
f.t.cl.lock()
defer f.t.cl.unlock()
return f.prio
} | [
"func",
"(",
"f",
"*",
"File",
")",
"Priority",
"(",
")",
"piecePriority",
"{",
"f",
".",
"t",
".",
"cl",
".",
"lock",
"(",
")",
"\n",
"defer",
"f",
".",
"t",
".",
"cl",
".",
"unlock",
"(",
")",
"\n",
"return",
"f",
".",
"prio",
"\n",
"}"
] | // Returns the priority per File.SetPriority. | [
"Returns",
"the",
"priority",
"per",
"File",
".",
"SetPriority",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/file.go#L123-L127 | train |
anacrolix/torrent | client.go | WriteStatus | func (cl *Client) WriteStatus(_w io.Writer) {
cl.rLock()
defer cl.rUnlock()
w := bufio.NewWriter(_w)
defer w.Flush()
fmt.Fprintf(w, "Listen port: %d\n", cl.LocalPort())
fmt.Fprintf(w, "Peer ID: %+q\n", cl.PeerID())
fmt.Fprintf(w, "Announce key: %x\n", cl.announceKey())
fmt.Fprintf(w, "Banned IPs: %d\n", len(cl.... | go | func (cl *Client) WriteStatus(_w io.Writer) {
cl.rLock()
defer cl.rUnlock()
w := bufio.NewWriter(_w)
defer w.Flush()
fmt.Fprintf(w, "Listen port: %d\n", cl.LocalPort())
fmt.Fprintf(w, "Peer ID: %+q\n", cl.PeerID())
fmt.Fprintf(w, "Announce key: %x\n", cl.announceKey())
fmt.Fprintf(w, "Banned IPs: %d\n", len(cl.... | [
"func",
"(",
"cl",
"*",
"Client",
")",
"WriteStatus",
"(",
"_w",
"io",
".",
"Writer",
")",
"{",
"cl",
".",
"rLock",
"(",
")",
"\n",
"defer",
"cl",
".",
"rUnlock",
"(",
")",
"\n",
"w",
":=",
"bufio",
".",
"NewWriter",
"(",
"_w",
")",
"\n",
"defe... | // Writes out a human readable status of the client, such as for writing to a
// HTTP status page. | [
"Writes",
"out",
"a",
"human",
"readable",
"status",
"of",
"the",
"client",
"such",
"as",
"for",
"writing",
"to",
"a",
"HTTP",
"status",
"page",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/client.go#L118-L152 | train |
anacrolix/torrent | client.go | Close | func (cl *Client) Close() {
cl.lock()
defer cl.unlock()
cl.closed.Set()
cl.eachDhtServer(func(s *dht.Server) { s.Close() })
cl.closeSockets()
for _, t := range cl.torrents {
t.close()
}
for _, f := range cl.onClose {
f()
}
cl.event.Broadcast()
} | go | func (cl *Client) Close() {
cl.lock()
defer cl.unlock()
cl.closed.Set()
cl.eachDhtServer(func(s *dht.Server) { s.Close() })
cl.closeSockets()
for _, t := range cl.torrents {
t.close()
}
for _, f := range cl.onClose {
f()
}
cl.event.Broadcast()
} | [
"func",
"(",
"cl",
"*",
"Client",
")",
"Close",
"(",
")",
"{",
"cl",
".",
"lock",
"(",
")",
"\n",
"defer",
"cl",
".",
"unlock",
"(",
")",
"\n",
"cl",
".",
"closed",
".",
"Set",
"(",
")",
"\n",
"cl",
".",
"eachDhtServer",
"(",
"func",
"(",
"s"... | // Stops the client. All connections to peers are closed and all activity will
// come to a halt. | [
"Stops",
"the",
"client",
".",
"All",
"connections",
"to",
"peers",
"are",
"closed",
"and",
"all",
"activity",
"will",
"come",
"to",
"a",
"halt",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/client.go#L352-L365 | train |
anacrolix/torrent | client.go | Torrent | func (cl *Client) Torrent(ih metainfo.Hash) (t *Torrent, ok bool) {
cl.lock()
defer cl.unlock()
t, ok = cl.torrents[ih]
return
} | go | func (cl *Client) Torrent(ih metainfo.Hash) (t *Torrent, ok bool) {
cl.lock()
defer cl.unlock()
t, ok = cl.torrents[ih]
return
} | [
"func",
"(",
"cl",
"*",
"Client",
")",
"Torrent",
"(",
"ih",
"metainfo",
".",
"Hash",
")",
"(",
"t",
"*",
"Torrent",
",",
"ok",
"bool",
")",
"{",
"cl",
".",
"lock",
"(",
")",
"\n",
"defer",
"cl",
".",
"unlock",
"(",
")",
"\n",
"t",
",",
"ok",... | // Returns a handle to the given torrent, if it's present in the client. | [
"Returns",
"a",
"handle",
"to",
"the",
"given",
"torrent",
"if",
"it",
"s",
"present",
"in",
"the",
"client",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/client.go#L465-L470 | train |
anacrolix/torrent | client.go | dopplegangerAddr | func (cl *Client) dopplegangerAddr(addr string) bool {
_, ok := cl.dopplegangerAddrs[addr]
return ok
} | go | func (cl *Client) dopplegangerAddr(addr string) bool {
_, ok := cl.dopplegangerAddrs[addr]
return ok
} | [
"func",
"(",
"cl",
"*",
"Client",
")",
"dopplegangerAddr",
"(",
"addr",
"string",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"cl",
".",
"dopplegangerAddrs",
"[",
"addr",
"]",
"\n",
"return",
"ok",
"\n",
"}"
] | // Returns whether an address is known to connect to a client with our own ID. | [
"Returns",
"whether",
"an",
"address",
"is",
"known",
"to",
"connect",
"to",
"a",
"client",
"with",
"our",
"own",
"ID",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/client.go#L498-L501 | train |
anacrolix/torrent | client.go | dialFirst | func (cl *Client) dialFirst(ctx context.Context, addr string) dialResult {
ctx, cancel := context.WithCancel(ctx)
// As soon as we return one connection, cancel the others.
defer cancel()
left := 0
resCh := make(chan dialResult, left)
func() {
cl.lock()
defer cl.unlock()
cl.eachListener(func(s socket) bool ... | go | func (cl *Client) dialFirst(ctx context.Context, addr string) dialResult {
ctx, cancel := context.WithCancel(ctx)
// As soon as we return one connection, cancel the others.
defer cancel()
left := 0
resCh := make(chan dialResult, left)
func() {
cl.lock()
defer cl.unlock()
cl.eachListener(func(s socket) bool ... | [
"func",
"(",
"cl",
"*",
"Client",
")",
"dialFirst",
"(",
"ctx",
"context",
".",
"Context",
",",
"addr",
"string",
")",
"dialResult",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithCancel",
"(",
"ctx",
")",
"\n",
"// As soon as we return one connection... | // Returns a connection over UTP or TCP, whichever is first to connect. | [
"Returns",
"a",
"connection",
"over",
"UTP",
"or",
"TCP",
"whichever",
"is",
"first",
"to",
"connect",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/client.go#L504-L583 | train |
anacrolix/torrent | client.go | outgoingConnection | func (cl *Client) outgoingConnection(t *Torrent, addr IpPort, ps peerSource) {
cl.dialRateLimiter.Wait(context.Background())
c, err := cl.establishOutgoingConn(t, addr)
cl.lock()
defer cl.unlock()
// Don't release lock between here and addConnection, unless it's for
// failure.
cl.noLongerHalfOpen(t, addr.String... | go | func (cl *Client) outgoingConnection(t *Torrent, addr IpPort, ps peerSource) {
cl.dialRateLimiter.Wait(context.Background())
c, err := cl.establishOutgoingConn(t, addr)
cl.lock()
defer cl.unlock()
// Don't release lock between here and addConnection, unless it's for
// failure.
cl.noLongerHalfOpen(t, addr.String... | [
"func",
"(",
"cl",
"*",
"Client",
")",
"outgoingConnection",
"(",
"t",
"*",
"Torrent",
",",
"addr",
"IpPort",
",",
"ps",
"peerSource",
")",
"{",
"cl",
".",
"dialRateLimiter",
".",
"Wait",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n",
"c",
"... | // Called to dial out and run a connection. The addr we're given is already
// considered half-open. | [
"Called",
"to",
"dial",
"out",
"and",
"run",
"a",
"connection",
".",
"The",
"addr",
"we",
"re",
"given",
"is",
"already",
"considered",
"half",
"-",
"open",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/client.go#L672-L692 | train |
anacrolix/torrent | client.go | forSkeys | func (cl *Client) forSkeys(f func([]byte) bool) {
cl.lock()
defer cl.unlock()
for ih := range cl.torrents {
if !f(ih[:]) {
break
}
}
} | go | func (cl *Client) forSkeys(f func([]byte) bool) {
cl.lock()
defer cl.unlock()
for ih := range cl.torrents {
if !f(ih[:]) {
break
}
}
} | [
"func",
"(",
"cl",
"*",
"Client",
")",
"forSkeys",
"(",
"f",
"func",
"(",
"[",
"]",
"byte",
")",
"bool",
")",
"{",
"cl",
".",
"lock",
"(",
")",
"\n",
"defer",
"cl",
".",
"unlock",
"(",
")",
"\n",
"for",
"ih",
":=",
"range",
"cl",
".",
"torren... | // Calls f with any secret keys. | [
"Calls",
"f",
"with",
"any",
"secret",
"keys",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/client.go#L734-L742 | train |
anacrolix/torrent | client.go | receiveHandshakes | func (cl *Client) receiveHandshakes(c *connection) (t *Torrent, err error) {
defer perf.ScopeTimerErr(&err)()
var rw io.ReadWriter
rw, c.headerEncrypted, c.cryptoMethod, err = handleEncryption(c.rw(), cl.forSkeys, cl.config.EncryptionPolicy)
c.setRW(rw)
if err == nil || err == mse.ErrNoSecretKeyMatch {
if c.head... | go | func (cl *Client) receiveHandshakes(c *connection) (t *Torrent, err error) {
defer perf.ScopeTimerErr(&err)()
var rw io.ReadWriter
rw, c.headerEncrypted, c.cryptoMethod, err = handleEncryption(c.rw(), cl.forSkeys, cl.config.EncryptionPolicy)
c.setRW(rw)
if err == nil || err == mse.ErrNoSecretKeyMatch {
if c.head... | [
"func",
"(",
"cl",
"*",
"Client",
")",
"receiveHandshakes",
"(",
"c",
"*",
"connection",
")",
"(",
"t",
"*",
"Torrent",
",",
"err",
"error",
")",
"{",
"defer",
"perf",
".",
"ScopeTimerErr",
"(",
"&",
"err",
")",
"(",
")",
"\n",
"var",
"rw",
"io",
... | // Do encryption and bittorrent handshakes as receiver. | [
"Do",
"encryption",
"and",
"bittorrent",
"handshakes",
"as",
"receiver",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/client.go#L745-L781 | train |
anacrolix/torrent | client.go | connBTHandshake | func (cl *Client) connBTHandshake(c *connection, ih *metainfo.Hash) (ret metainfo.Hash, ok bool, err error) {
res, ok, err := pp.Handshake(c.rw(), ih, cl.peerID, cl.extensionBytes)
if err != nil || !ok {
return
}
ret = res.Hash
c.PeerExtensionBytes = res.PeerExtensionBits
c.PeerID = res.PeerID
c.completedHands... | go | func (cl *Client) connBTHandshake(c *connection, ih *metainfo.Hash) (ret metainfo.Hash, ok bool, err error) {
res, ok, err := pp.Handshake(c.rw(), ih, cl.peerID, cl.extensionBytes)
if err != nil || !ok {
return
}
ret = res.Hash
c.PeerExtensionBytes = res.PeerExtensionBits
c.PeerID = res.PeerID
c.completedHands... | [
"func",
"(",
"cl",
"*",
"Client",
")",
"connBTHandshake",
"(",
"c",
"*",
"connection",
",",
"ih",
"*",
"metainfo",
".",
"Hash",
")",
"(",
"ret",
"metainfo",
".",
"Hash",
",",
"ok",
"bool",
",",
"err",
"error",
")",
"{",
"res",
",",
"ok",
",",
"er... | // Returns !ok if handshake failed for valid reasons. | [
"Returns",
"!ok",
"if",
"handshake",
"failed",
"for",
"valid",
"reasons",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/client.go#L784-L794 | train |
anacrolix/torrent | client.go | sendInitialMessages | func (cl *Client) sendInitialMessages(conn *connection, torrent *Torrent) {
if conn.PeerExtensionBytes.SupportsExtended() && cl.extensionBytes.SupportsExtended() {
conn.Post(pp.Message{
Type: pp.Extended,
ExtendedID: pp.HandshakeExtendedID,
ExtendedPayload: func() []byte {
msg := pp.ExtendedHandsh... | go | func (cl *Client) sendInitialMessages(conn *connection, torrent *Torrent) {
if conn.PeerExtensionBytes.SupportsExtended() && cl.extensionBytes.SupportsExtended() {
conn.Post(pp.Message{
Type: pp.Extended,
ExtendedID: pp.HandshakeExtendedID,
ExtendedPayload: func() []byte {
msg := pp.ExtendedHandsh... | [
"func",
"(",
"cl",
"*",
"Client",
")",
"sendInitialMessages",
"(",
"conn",
"*",
"connection",
",",
"torrent",
"*",
"Torrent",
")",
"{",
"if",
"conn",
".",
"PeerExtensionBytes",
".",
"SupportsExtended",
"(",
")",
"&&",
"cl",
".",
"extensionBytes",
".",
"Sup... | // See the order given in Transmission's tr_peerMsgsNew. | [
"See",
"the",
"order",
"given",
"in",
"Transmission",
"s",
"tr_peerMsgsNew",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/client.go#L864-L912 | train |
anacrolix/torrent | client.go | gotMetadataExtensionMsg | func (cl *Client) gotMetadataExtensionMsg(payload []byte, t *Torrent, c *connection) error {
var d map[string]int
err := bencode.Unmarshal(payload, &d)
if _, ok := err.(bencode.ErrUnusedTrailingBytes); ok {
} else if err != nil {
return fmt.Errorf("error unmarshalling bencode: %s", err)
}
msgType, ok := d["msg_... | go | func (cl *Client) gotMetadataExtensionMsg(payload []byte, t *Torrent, c *connection) error {
var d map[string]int
err := bencode.Unmarshal(payload, &d)
if _, ok := err.(bencode.ErrUnusedTrailingBytes); ok {
} else if err != nil {
return fmt.Errorf("error unmarshalling bencode: %s", err)
}
msgType, ok := d["msg_... | [
"func",
"(",
"cl",
"*",
"Client",
")",
"gotMetadataExtensionMsg",
"(",
"payload",
"[",
"]",
"byte",
",",
"t",
"*",
"Torrent",
",",
"c",
"*",
"connection",
")",
"error",
"{",
"var",
"d",
"map",
"[",
"string",
"]",
"int",
"\n",
"err",
":=",
"bencode",
... | // Process incoming ut_metadata message. | [
"Process",
"incoming",
"ut_metadata",
"message",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/client.go#L929-L968 | train |
anacrolix/torrent | client.go | newTorrent | func (cl *Client) newTorrent(ih metainfo.Hash, specStorage storage.ClientImpl) (t *Torrent) {
// use provided storage, if provided
storageClient := cl.defaultStorage
if specStorage != nil {
storageClient = storage.NewClient(specStorage)
}
t = &Torrent{
cl: cl,
infoHash: ih,
peers: prioritizedPeers{
... | go | func (cl *Client) newTorrent(ih metainfo.Hash, specStorage storage.ClientImpl) (t *Torrent) {
// use provided storage, if provided
storageClient := cl.defaultStorage
if specStorage != nil {
storageClient = storage.NewClient(specStorage)
}
t = &Torrent{
cl: cl,
infoHash: ih,
peers: prioritizedPeers{
... | [
"func",
"(",
"cl",
"*",
"Client",
")",
"newTorrent",
"(",
"ih",
"metainfo",
".",
"Hash",
",",
"specStorage",
"storage",
".",
"ClientImpl",
")",
"(",
"t",
"*",
"Torrent",
")",
"{",
"// use provided storage, if provided",
"storageClient",
":=",
"cl",
".",
"def... | // Return a Torrent ready for insertion into a Client. | [
"Return",
"a",
"Torrent",
"ready",
"for",
"insertion",
"into",
"a",
"Client",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/client.go#L987-L1021 | train |
anacrolix/torrent | client.go | AddTorrentInfoHashWithStorage | func (cl *Client) AddTorrentInfoHashWithStorage(infoHash metainfo.Hash, specStorage storage.ClientImpl) (t *Torrent, new bool) {
cl.lock()
defer cl.unlock()
t, ok := cl.torrents[infoHash]
if ok {
return
}
new = true
t = cl.newTorrent(infoHash, specStorage)
cl.eachDhtServer(func(s *dht.Server) {
go t.dhtAnn... | go | func (cl *Client) AddTorrentInfoHashWithStorage(infoHash metainfo.Hash, specStorage storage.ClientImpl) (t *Torrent, new bool) {
cl.lock()
defer cl.unlock()
t, ok := cl.torrents[infoHash]
if ok {
return
}
new = true
t = cl.newTorrent(infoHash, specStorage)
cl.eachDhtServer(func(s *dht.Server) {
go t.dhtAnn... | [
"func",
"(",
"cl",
"*",
"Client",
")",
"AddTorrentInfoHashWithStorage",
"(",
"infoHash",
"metainfo",
".",
"Hash",
",",
"specStorage",
"storage",
".",
"ClientImpl",
")",
"(",
"t",
"*",
"Torrent",
",",
"new",
"bool",
")",
"{",
"cl",
".",
"lock",
"(",
")",
... | // Adds a torrent by InfoHash with a custom Storage implementation.
// If the torrent already exists then this Storage is ignored and the
// existing torrent returned with `new` set to `false` | [
"Adds",
"a",
"torrent",
"by",
"InfoHash",
"with",
"a",
"custom",
"Storage",
"implementation",
".",
"If",
"the",
"torrent",
"already",
"exists",
"then",
"this",
"Storage",
"is",
"ignored",
"and",
"the",
"existing",
"torrent",
"returned",
"with",
"new",
"set",
... | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/client.go#L1038-L1057 | train |
anacrolix/torrent | client.go | WaitAll | func (cl *Client) WaitAll() bool {
cl.lock()
defer cl.unlock()
for !cl.allTorrentsCompleted() {
if cl.closed.IsSet() {
return false
}
cl.event.Wait()
}
return true
} | go | func (cl *Client) WaitAll() bool {
cl.lock()
defer cl.unlock()
for !cl.allTorrentsCompleted() {
if cl.closed.IsSet() {
return false
}
cl.event.Wait()
}
return true
} | [
"func",
"(",
"cl",
"*",
"Client",
")",
"WaitAll",
"(",
")",
"bool",
"{",
"cl",
".",
"lock",
"(",
")",
"\n",
"defer",
"cl",
".",
"unlock",
"(",
")",
"\n",
"for",
"!",
"cl",
".",
"allTorrentsCompleted",
"(",
")",
"{",
"if",
"cl",
".",
"closed",
"... | // Returns true when all torrents are completely downloaded and false if the
// client is stopped before that. | [
"Returns",
"true",
"when",
"all",
"torrents",
"are",
"completely",
"downloaded",
"and",
"false",
"if",
"the",
"client",
"is",
"stopped",
"before",
"that",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/client.go#L1114-L1124 | train |
anacrolix/torrent | client.go | Torrents | func (cl *Client) Torrents() []*Torrent {
cl.lock()
defer cl.unlock()
return cl.torrentsAsSlice()
} | go | func (cl *Client) Torrents() []*Torrent {
cl.lock()
defer cl.unlock()
return cl.torrentsAsSlice()
} | [
"func",
"(",
"cl",
"*",
"Client",
")",
"Torrents",
"(",
")",
"[",
"]",
"*",
"Torrent",
"{",
"cl",
".",
"lock",
"(",
")",
"\n",
"defer",
"cl",
".",
"unlock",
"(",
")",
"\n",
"return",
"cl",
".",
"torrentsAsSlice",
"(",
")",
"\n",
"}"
] | // Returns handles to all the torrents loaded in the Client. | [
"Returns",
"handles",
"to",
"all",
"the",
"torrents",
"loaded",
"in",
"the",
"Client",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/client.go#L1127-L1131 | train |
anacrolix/torrent | client.go | publicAddr | func (cl *Client) publicAddr(peer net.IP) IpPort {
return IpPort{cl.publicIp(peer), uint16(cl.incomingPeerPort())}
} | go | func (cl *Client) publicAddr(peer net.IP) IpPort {
return IpPort{cl.publicIp(peer), uint16(cl.incomingPeerPort())}
} | [
"func",
"(",
"cl",
"*",
"Client",
")",
"publicAddr",
"(",
"peer",
"net",
".",
"IP",
")",
"IpPort",
"{",
"return",
"IpPort",
"{",
"cl",
".",
"publicIp",
"(",
"peer",
")",
",",
"uint16",
"(",
"cl",
".",
"incomingPeerPort",
"(",
")",
")",
"}",
"\n",
... | // Our IP as a peer should see it. | [
"Our",
"IP",
"as",
"a",
"peer",
"should",
"see",
"it",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/client.go#L1277-L1279 | train |
anacrolix/torrent | mse/mse.go | postY | func (h *handshake) postY(x *big.Int) error {
var y big.Int
y.Exp(&g, x, &p)
return h.postWrite(paddedLeft(y.Bytes(), 96))
} | go | func (h *handshake) postY(x *big.Int) error {
var y big.Int
y.Exp(&g, x, &p)
return h.postWrite(paddedLeft(y.Bytes(), 96))
} | [
"func",
"(",
"h",
"*",
"handshake",
")",
"postY",
"(",
"x",
"*",
"big",
".",
"Int",
")",
"error",
"{",
"var",
"y",
"big",
".",
"Int",
"\n",
"y",
".",
"Exp",
"(",
"&",
"g",
",",
"x",
",",
"&",
"p",
")",
"\n",
"return",
"h",
".",
"postWrite",... | // Calculate, and send Y, our public key. | [
"Calculate",
"and",
"send",
"Y",
"our",
"public",
"key",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/mse/mse.go#L175-L179 | train |
anacrolix/torrent | mse/mse.go | suffixMatchLen | func suffixMatchLen(a, b []byte) int {
if len(b) > len(a) {
b = b[:len(a)]
}
// i is how much of b to try to match
for i := len(b); i > 0; i-- {
// j is how many chars we've compared
j := 0
for ; j < i; j++ {
if b[i-1-j] != a[len(a)-1-j] {
goto shorter
}
}
return j
shorter:
}
return 0
} | go | func suffixMatchLen(a, b []byte) int {
if len(b) > len(a) {
b = b[:len(a)]
}
// i is how much of b to try to match
for i := len(b); i > 0; i-- {
// j is how many chars we've compared
j := 0
for ; j < i; j++ {
if b[i-1-j] != a[len(a)-1-j] {
goto shorter
}
}
return j
shorter:
}
return 0
} | [
"func",
"suffixMatchLen",
"(",
"a",
",",
"b",
"[",
"]",
"byte",
")",
"int",
"{",
"if",
"len",
"(",
"b",
")",
">",
"len",
"(",
"a",
")",
"{",
"b",
"=",
"b",
"[",
":",
"len",
"(",
"a",
")",
"]",
"\n",
"}",
"\n",
"// i is how much of b to try to m... | // Looking for b at the end of a. | [
"Looking",
"for",
"b",
"at",
"the",
"end",
"of",
"a",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/mse/mse.go#L322-L339 | train |
anacrolix/torrent | mse/mse.go | readUntil | func readUntil(r io.Reader, b []byte) error {
b1 := make([]byte, len(b))
i := 0
for {
_, err := io.ReadFull(r, b1[i:])
if err != nil {
return err
}
i = suffixMatchLen(b1, b)
if i == len(b) {
break
}
if copy(b1, b1[len(b1)-i:]) != i {
panic("wat")
}
}
return nil
} | go | func readUntil(r io.Reader, b []byte) error {
b1 := make([]byte, len(b))
i := 0
for {
_, err := io.ReadFull(r, b1[i:])
if err != nil {
return err
}
i = suffixMatchLen(b1, b)
if i == len(b) {
break
}
if copy(b1, b1[len(b1)-i:]) != i {
panic("wat")
}
}
return nil
} | [
"func",
"readUntil",
"(",
"r",
"io",
".",
"Reader",
",",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"b1",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"b",
")",
")",
"\n",
"i",
":=",
"0",
"\n",
"for",
"{",
"_",
",",
"err",
":=",
"... | // Reads from r until b has been seen. Keeps the minimum amount of data in
// memory. | [
"Reads",
"from",
"r",
"until",
"b",
"has",
"been",
"seen",
".",
"Keeps",
"the",
"minimum",
"amount",
"of",
"data",
"in",
"memory",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/mse/mse.go#L343-L360 | train |
anacrolix/torrent | tracker/peer.go | fromDictInterface | func (p *Peer) fromDictInterface(d map[string]interface{}) {
p.IP = net.ParseIP(d["ip"].(string))
if _, ok := d["peer id"]; ok {
p.ID = []byte(d["peer id"].(string))
}
p.Port = int(d["port"].(int64))
} | go | func (p *Peer) fromDictInterface(d map[string]interface{}) {
p.IP = net.ParseIP(d["ip"].(string))
if _, ok := d["peer id"]; ok {
p.ID = []byte(d["peer id"].(string))
}
p.Port = int(d["port"].(int64))
} | [
"func",
"(",
"p",
"*",
"Peer",
")",
"fromDictInterface",
"(",
"d",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"p",
".",
"IP",
"=",
"net",
".",
"ParseIP",
"(",
"d",
"[",
"\"",
"\"",
"]",
".",
"(",
"string",
")",
")",
"\n",
"if... | // Set from the non-compact form in BEP 3. | [
"Set",
"from",
"the",
"non",
"-",
"compact",
"form",
"in",
"BEP",
"3",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/tracker/peer.go#L16-L22 | train |
anacrolix/torrent | metainfo/announcelist.go | OverridesAnnounce | func (al AnnounceList) OverridesAnnounce(announce string) bool {
for _, tier := range al {
for _, url := range tier {
if url != "" || announce == "" {
return true
}
}
}
return false
} | go | func (al AnnounceList) OverridesAnnounce(announce string) bool {
for _, tier := range al {
for _, url := range tier {
if url != "" || announce == "" {
return true
}
}
}
return false
} | [
"func",
"(",
"al",
"AnnounceList",
")",
"OverridesAnnounce",
"(",
"announce",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"tier",
":=",
"range",
"al",
"{",
"for",
"_",
",",
"url",
":=",
"range",
"tier",
"{",
"if",
"url",
"!=",
"\"",
"\"",
"||",
"a... | // Whether the AnnounceList should be preferred over a single URL announce. | [
"Whether",
"the",
"AnnounceList",
"should",
"be",
"preferred",
"over",
"a",
"single",
"URL",
"announce",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/metainfo/announcelist.go#L6-L15 | train |
anacrolix/torrent | prioritized_peers.go | Add | func (me *prioritizedPeers) Add(p Peer) bool {
return me.om.ReplaceOrInsert(prioritizedPeersItem{me.getPrio(p), p}) != nil
} | go | func (me *prioritizedPeers) Add(p Peer) bool {
return me.om.ReplaceOrInsert(prioritizedPeersItem{me.getPrio(p), p}) != nil
} | [
"func",
"(",
"me",
"*",
"prioritizedPeers",
")",
"Add",
"(",
"p",
"Peer",
")",
"bool",
"{",
"return",
"me",
".",
"om",
".",
"ReplaceOrInsert",
"(",
"prioritizedPeersItem",
"{",
"me",
".",
"getPrio",
"(",
"p",
")",
",",
"p",
"}",
")",
"!=",
"nil",
"... | // Returns true if a peer is replaced. | [
"Returns",
"true",
"if",
"a",
"peer",
"is",
"replaced",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/prioritized_peers.go#L33-L35 | train |
anacrolix/torrent | storage/file.go | defaultPathMaker | func defaultPathMaker(baseDir string, info *metainfo.Info, infoHash metainfo.Hash) string {
return baseDir
} | go | func defaultPathMaker(baseDir string, info *metainfo.Info, infoHash metainfo.Hash) string {
return baseDir
} | [
"func",
"defaultPathMaker",
"(",
"baseDir",
"string",
",",
"info",
"*",
"metainfo",
".",
"Info",
",",
"infoHash",
"metainfo",
".",
"Hash",
")",
"string",
"{",
"return",
"baseDir",
"\n",
"}"
] | // The Default path maker just returns the current path | [
"The",
"Default",
"path",
"maker",
"just",
"returns",
"the",
"current",
"path"
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/storage/file.go#L21-L23 | train |
anacrolix/torrent | storage/file.go | NewFileWithCustomPathMaker | func NewFileWithCustomPathMaker(baseDir string, pathMaker func(baseDir string, info *metainfo.Info, infoHash metainfo.Hash) string) ClientImpl {
return newFileWithCustomPathMakerAndCompletion(baseDir, pathMaker, pieceCompletionForDir(baseDir))
} | go | func NewFileWithCustomPathMaker(baseDir string, pathMaker func(baseDir string, info *metainfo.Info, infoHash metainfo.Hash) string) ClientImpl {
return newFileWithCustomPathMakerAndCompletion(baseDir, pathMaker, pieceCompletionForDir(baseDir))
} | [
"func",
"NewFileWithCustomPathMaker",
"(",
"baseDir",
"string",
",",
"pathMaker",
"func",
"(",
"baseDir",
"string",
",",
"info",
"*",
"metainfo",
".",
"Info",
",",
"infoHash",
"metainfo",
".",
"Hash",
")",
"string",
")",
"ClientImpl",
"{",
"return",
"newFileWi... | // Allows passing a function to determine the path for storing torrent data | [
"Allows",
"passing",
"a",
"function",
"to",
"determine",
"the",
"path",
"for",
"storing",
"torrent",
"data"
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/storage/file.go#L44-L46 | train |
anacrolix/torrent | storage/file.go | CreateNativeZeroLengthFiles | func CreateNativeZeroLengthFiles(info *metainfo.Info, dir string) (err error) {
for _, fi := range info.UpvertedFiles() {
if fi.Length != 0 {
continue
}
name := filepath.Join(append([]string{dir, info.Name}, fi.Path...)...)
os.MkdirAll(filepath.Dir(name), 0777)
var f io.Closer
f, err = os.Create(name)
... | go | func CreateNativeZeroLengthFiles(info *metainfo.Info, dir string) (err error) {
for _, fi := range info.UpvertedFiles() {
if fi.Length != 0 {
continue
}
name := filepath.Join(append([]string{dir, info.Name}, fi.Path...)...)
os.MkdirAll(filepath.Dir(name), 0777)
var f io.Closer
f, err = os.Create(name)
... | [
"func",
"CreateNativeZeroLengthFiles",
"(",
"info",
"*",
"metainfo",
".",
"Info",
",",
"dir",
"string",
")",
"(",
"err",
"error",
")",
"{",
"for",
"_",
",",
"fi",
":=",
"range",
"info",
".",
"UpvertedFiles",
"(",
")",
"{",
"if",
"fi",
".",
"Length",
... | // Creates natives files for any zero-length file entries in the info. This is
// a helper for file-based storages, which don't address or write to zero-
// length files because they have no corresponding pieces. | [
"Creates",
"natives",
"files",
"for",
"any",
"zero",
"-",
"length",
"file",
"entries",
"in",
"the",
"info",
".",
"This",
"is",
"a",
"helper",
"for",
"file",
"-",
"based",
"storages",
"which",
"don",
"t",
"address",
"or",
"write",
"to",
"zero",
"-",
"le... | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/storage/file.go#L103-L118 | train |
anacrolix/torrent | storage/file.go | readFileAt | func (fst *fileTorrentImplIO) readFileAt(fi metainfo.FileInfo, b []byte, off int64) (n int, err error) {
f, err := os.Open(fst.fts.fileInfoName(fi))
if os.IsNotExist(err) {
// File missing is treated the same as a short file.
err = io.EOF
return
}
if err != nil {
return
}
defer f.Close()
// Limit the rea... | go | func (fst *fileTorrentImplIO) readFileAt(fi metainfo.FileInfo, b []byte, off int64) (n int, err error) {
f, err := os.Open(fst.fts.fileInfoName(fi))
if os.IsNotExist(err) {
// File missing is treated the same as a short file.
err = io.EOF
return
}
if err != nil {
return
}
defer f.Close()
// Limit the rea... | [
"func",
"(",
"fst",
"*",
"fileTorrentImplIO",
")",
"readFileAt",
"(",
"fi",
"metainfo",
".",
"FileInfo",
",",
"b",
"[",
"]",
"byte",
",",
"off",
"int64",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open... | // Returns EOF on short or missing file. | [
"Returns",
"EOF",
"on",
"short",
"or",
"missing",
"file",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/storage/file.go#L126-L152 | train |
anacrolix/torrent | storage/file.go | ReadAt | func (fst fileTorrentImplIO) ReadAt(b []byte, off int64) (n int, err error) {
for _, fi := range fst.fts.info.UpvertedFiles() {
for off < fi.Length {
n1, err1 := fst.readFileAt(fi, b, off)
n += n1
off += int64(n1)
b = b[n1:]
if len(b) == 0 {
// Got what we need.
return
}
if n1 != 0 {
... | go | func (fst fileTorrentImplIO) ReadAt(b []byte, off int64) (n int, err error) {
for _, fi := range fst.fts.info.UpvertedFiles() {
for off < fi.Length {
n1, err1 := fst.readFileAt(fi, b, off)
n += n1
off += int64(n1)
b = b[n1:]
if len(b) == 0 {
// Got what we need.
return
}
if n1 != 0 {
... | [
"func",
"(",
"fst",
"fileTorrentImplIO",
")",
"ReadAt",
"(",
"b",
"[",
"]",
"byte",
",",
"off",
"int64",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"for",
"_",
",",
"fi",
":=",
"range",
"fst",
".",
"fts",
".",
"info",
".",
"UpvertedFile... | // Only returns EOF at the end of the torrent. Premature EOF is ErrUnexpectedEOF. | [
"Only",
"returns",
"EOF",
"at",
"the",
"end",
"of",
"the",
"torrent",
".",
"Premature",
"EOF",
"is",
"ErrUnexpectedEOF",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/storage/file.go#L155-L181 | train |
anacrolix/torrent | t.go | Info | func (t *Torrent) Info() *metainfo.Info {
t.cl.lock()
defer t.cl.unlock()
return t.info
} | go | func (t *Torrent) Info() *metainfo.Info {
t.cl.lock()
defer t.cl.unlock()
return t.info
} | [
"func",
"(",
"t",
"*",
"Torrent",
")",
"Info",
"(",
")",
"*",
"metainfo",
".",
"Info",
"{",
"t",
".",
"cl",
".",
"lock",
"(",
")",
"\n",
"defer",
"t",
".",
"cl",
".",
"unlock",
"(",
")",
"\n",
"return",
"t",
".",
"info",
"\n",
"}"
] | // Returns the metainfo info dictionary, or nil if it's not yet available. | [
"Returns",
"the",
"metainfo",
"info",
"dictionary",
"or",
"nil",
"if",
"it",
"s",
"not",
"yet",
"available",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/t.go#L26-L30 | train |
anacrolix/torrent | t.go | NewReader | func (t *Torrent) NewReader() Reader {
r := reader{
mu: t.cl.locker(),
t: t,
readahead: 5 * 1024 * 1024,
length: *t.length,
}
t.addReader(&r)
return &r
} | go | func (t *Torrent) NewReader() Reader {
r := reader{
mu: t.cl.locker(),
t: t,
readahead: 5 * 1024 * 1024,
length: *t.length,
}
t.addReader(&r)
return &r
} | [
"func",
"(",
"t",
"*",
"Torrent",
")",
"NewReader",
"(",
")",
"Reader",
"{",
"r",
":=",
"reader",
"{",
"mu",
":",
"t",
".",
"cl",
".",
"locker",
"(",
")",
",",
"t",
":",
"t",
",",
"readahead",
":",
"5",
"*",
"1024",
"*",
"1024",
",",
"length"... | // Returns a Reader bound to the torrent's data. All read calls block until
// the data requested is actually available. | [
"Returns",
"a",
"Reader",
"bound",
"to",
"the",
"torrent",
"s",
"data",
".",
"All",
"read",
"calls",
"block",
"until",
"the",
"data",
"requested",
"is",
"actually",
"available",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/t.go#L34-L43 | train |
anacrolix/torrent | t.go | PieceStateRuns | func (t *Torrent) PieceStateRuns() []PieceStateRun {
t.cl.rLock()
defer t.cl.rUnlock()
return t.pieceStateRuns()
} | go | func (t *Torrent) PieceStateRuns() []PieceStateRun {
t.cl.rLock()
defer t.cl.rUnlock()
return t.pieceStateRuns()
} | [
"func",
"(",
"t",
"*",
"Torrent",
")",
"PieceStateRuns",
"(",
")",
"[",
"]",
"PieceStateRun",
"{",
"t",
".",
"cl",
".",
"rLock",
"(",
")",
"\n",
"defer",
"t",
".",
"cl",
".",
"rUnlock",
"(",
")",
"\n",
"return",
"t",
".",
"pieceStateRuns",
"(",
"... | // Returns the state of pieces of the torrent. They are grouped into runs of
// same state. The sum of the state run lengths is the number of pieces
// in the torrent. | [
"Returns",
"the",
"state",
"of",
"pieces",
"of",
"the",
"torrent",
".",
"They",
"are",
"grouped",
"into",
"runs",
"of",
"same",
"state",
".",
"The",
"sum",
"of",
"the",
"state",
"run",
"lengths",
"is",
"the",
"number",
"of",
"pieces",
"in",
"the",
"tor... | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/t.go#L48-L52 | train |
anacrolix/torrent | t.go | PieceBytesMissing | func (t *Torrent) PieceBytesMissing(piece int) int64 {
t.cl.lock()
defer t.cl.unlock()
return int64(t.pieces[piece].bytesLeft())
} | go | func (t *Torrent) PieceBytesMissing(piece int) int64 {
t.cl.lock()
defer t.cl.unlock()
return int64(t.pieces[piece].bytesLeft())
} | [
"func",
"(",
"t",
"*",
"Torrent",
")",
"PieceBytesMissing",
"(",
"piece",
"int",
")",
"int64",
"{",
"t",
".",
"cl",
".",
"lock",
"(",
")",
"\n",
"defer",
"t",
".",
"cl",
".",
"unlock",
"(",
")",
"\n\n",
"return",
"int64",
"(",
"t",
".",
"pieces",... | // Get missing bytes count for specific piece. | [
"Get",
"missing",
"bytes",
"count",
"for",
"specific",
"piece",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/t.go#L67-L72 | train |
anacrolix/torrent | t.go | Drop | func (t *Torrent) Drop() {
t.cl.lock()
t.cl.dropTorrent(t.infoHash)
t.cl.unlock()
} | go | func (t *Torrent) Drop() {
t.cl.lock()
t.cl.dropTorrent(t.infoHash)
t.cl.unlock()
} | [
"func",
"(",
"t",
"*",
"Torrent",
")",
"Drop",
"(",
")",
"{",
"t",
".",
"cl",
".",
"lock",
"(",
")",
"\n",
"t",
".",
"cl",
".",
"dropTorrent",
"(",
"t",
".",
"infoHash",
")",
"\n",
"t",
".",
"cl",
".",
"unlock",
"(",
")",
"\n",
"}"
] | // Drop the torrent from the client, and close it. It's always safe to do
// this. No data corruption can, or should occur to either the torrent's data,
// or connected peers. | [
"Drop",
"the",
"torrent",
"from",
"the",
"client",
"and",
"close",
"it",
".",
"It",
"s",
"always",
"safe",
"to",
"do",
"this",
".",
"No",
"data",
"corruption",
"can",
"or",
"should",
"occur",
"to",
"either",
"the",
"torrent",
"s",
"data",
"or",
"connec... | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/t.go#L77-L81 | train |
anacrolix/torrent | t.go | BytesCompleted | func (t *Torrent) BytesCompleted() int64 {
t.cl.rLock()
defer t.cl.rUnlock()
return t.bytesCompleted()
} | go | func (t *Torrent) BytesCompleted() int64 {
t.cl.rLock()
defer t.cl.rUnlock()
return t.bytesCompleted()
} | [
"func",
"(",
"t",
"*",
"Torrent",
")",
"BytesCompleted",
"(",
")",
"int64",
"{",
"t",
".",
"cl",
".",
"rLock",
"(",
")",
"\n",
"defer",
"t",
".",
"cl",
".",
"rUnlock",
"(",
")",
"\n",
"return",
"t",
".",
"bytesCompleted",
"(",
")",
"\n",
"}"
] | // Number of bytes of the entire torrent we have completed. This is the sum of
// completed pieces, and dirtied chunks of incomplete pieces. Do not use this
// for download rate, as it can go down when pieces are lost or fail checks.
// Sample Torrent.Stats.DataBytesRead for actual file data download rate. | [
"Number",
"of",
"bytes",
"of",
"the",
"entire",
"torrent",
"we",
"have",
"completed",
".",
"This",
"is",
"the",
"sum",
"of",
"completed",
"pieces",
"and",
"dirtied",
"chunks",
"of",
"incomplete",
"pieces",
".",
"Do",
"not",
"use",
"this",
"for",
"download"... | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/t.go#L87-L91 | train |
anacrolix/torrent | t.go | Seeding | func (t *Torrent) Seeding() bool {
t.cl.lock()
defer t.cl.unlock()
return t.seeding()
} | go | func (t *Torrent) Seeding() bool {
t.cl.lock()
defer t.cl.unlock()
return t.seeding()
} | [
"func",
"(",
"t",
"*",
"Torrent",
")",
"Seeding",
"(",
")",
"bool",
"{",
"t",
".",
"cl",
".",
"lock",
"(",
")",
"\n",
"defer",
"t",
".",
"cl",
".",
"unlock",
"(",
")",
"\n",
"return",
"t",
".",
"seeding",
"(",
")",
"\n",
"}"
] | // Returns true if the torrent is currently being seeded. This occurs when the
// client is willing to upload without wanting anything in return. | [
"Returns",
"true",
"if",
"the",
"torrent",
"is",
"currently",
"being",
"seeded",
".",
"This",
"occurs",
"when",
"the",
"client",
"is",
"willing",
"to",
"upload",
"without",
"wanting",
"anything",
"in",
"return",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/t.go#L101-L105 | train |
anacrolix/torrent | t.go | SetDisplayName | func (t *Torrent) SetDisplayName(dn string) {
t.nameMu.Lock()
defer t.nameMu.Unlock()
if t.haveInfo() {
return
}
t.displayName = dn
} | go | func (t *Torrent) SetDisplayName(dn string) {
t.nameMu.Lock()
defer t.nameMu.Unlock()
if t.haveInfo() {
return
}
t.displayName = dn
} | [
"func",
"(",
"t",
"*",
"Torrent",
")",
"SetDisplayName",
"(",
"dn",
"string",
")",
"{",
"t",
".",
"nameMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"nameMu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"t",
".",
"haveInfo",
"(",
")",
"{",
"ret... | // Clobbers the torrent display name. The display name is used as the torrent
// name if the metainfo is not available. | [
"Clobbers",
"the",
"torrent",
"display",
"name",
".",
"The",
"display",
"name",
"is",
"used",
"as",
"the",
"torrent",
"name",
"if",
"the",
"metainfo",
"is",
"not",
"available",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/t.go#L109-L116 | train |
anacrolix/torrent | t.go | Metainfo | func (t *Torrent) Metainfo() metainfo.MetaInfo {
t.cl.lock()
defer t.cl.unlock()
return t.newMetaInfo()
} | go | func (t *Torrent) Metainfo() metainfo.MetaInfo {
t.cl.lock()
defer t.cl.unlock()
return t.newMetaInfo()
} | [
"func",
"(",
"t",
"*",
"Torrent",
")",
"Metainfo",
"(",
")",
"metainfo",
".",
"MetaInfo",
"{",
"t",
".",
"cl",
".",
"lock",
"(",
")",
"\n",
"defer",
"t",
".",
"cl",
".",
"unlock",
"(",
")",
"\n",
"return",
"t",
".",
"newMetaInfo",
"(",
")",
"\n... | // Returns a run-time generated metainfo for the torrent that includes the
// info bytes and announce-list as currently known to the client. | [
"Returns",
"a",
"run",
"-",
"time",
"generated",
"metainfo",
"for",
"the",
"torrent",
"that",
"includes",
"the",
"info",
"bytes",
"and",
"announce",
"-",
"list",
"as",
"currently",
"known",
"to",
"the",
"client",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/t.go#L132-L136 | train |
anacrolix/torrent | t.go | DownloadPieces | func (t *Torrent) DownloadPieces(begin, end pieceIndex) {
t.cl.lock()
defer t.cl.unlock()
t.downloadPiecesLocked(begin, end)
} | go | func (t *Torrent) DownloadPieces(begin, end pieceIndex) {
t.cl.lock()
defer t.cl.unlock()
t.downloadPiecesLocked(begin, end)
} | [
"func",
"(",
"t",
"*",
"Torrent",
")",
"DownloadPieces",
"(",
"begin",
",",
"end",
"pieceIndex",
")",
"{",
"t",
".",
"cl",
".",
"lock",
"(",
")",
"\n",
"defer",
"t",
".",
"cl",
".",
"unlock",
"(",
")",
"\n",
"t",
".",
"downloadPiecesLocked",
"(",
... | // Raise the priorities of pieces in the range [begin, end) to at least Normal
// priority. Piece indexes are not the same as bytes. Requires that the info
// has been obtained, see Torrent.Info and Torrent.GotInfo. | [
"Raise",
"the",
"priorities",
"of",
"pieces",
"in",
"the",
"range",
"[",
"begin",
"end",
")",
"to",
"at",
"least",
"Normal",
"priority",
".",
"Piece",
"indexes",
"are",
"not",
"the",
"same",
"as",
"bytes",
".",
"Requires",
"that",
"the",
"info",
"has",
... | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/t.go#L156-L160 | train |
anacrolix/torrent | torrent.go | KnownSwarm | func (t *Torrent) KnownSwarm() (ks []Peer) {
// Add pending peers to the list
t.peers.Each(func(peer Peer) {
ks = append(ks, peer)
})
// Add half-open peers to the list
for _, peer := range t.halfOpen {
ks = append(ks, peer)
}
// Add active peers to the list
for conn := range t.conns {
ks = append(ks, ... | go | func (t *Torrent) KnownSwarm() (ks []Peer) {
// Add pending peers to the list
t.peers.Each(func(peer Peer) {
ks = append(ks, peer)
})
// Add half-open peers to the list
for _, peer := range t.halfOpen {
ks = append(ks, peer)
}
// Add active peers to the list
for conn := range t.conns {
ks = append(ks, ... | [
"func",
"(",
"t",
"*",
"Torrent",
")",
"KnownSwarm",
"(",
")",
"(",
"ks",
"[",
"]",
"Peer",
")",
"{",
"// Add pending peers to the list",
"t",
".",
"peers",
".",
"Each",
"(",
"func",
"(",
"peer",
"Peer",
")",
"{",
"ks",
"=",
"append",
"(",
"ks",
",... | // KnownSwarm returns the known subset of the peers in the Torrent's swarm, including active,
// pending, and half-open peers. | [
"KnownSwarm",
"returns",
"the",
"known",
"subset",
"of",
"the",
"peers",
"in",
"the",
"Torrent",
"s",
"swarm",
"including",
"active",
"pending",
"and",
"half",
"-",
"open",
"peers",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/torrent.go#L157-L187 | train |
anacrolix/torrent | torrent.go | addrActive | 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
} | go | 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",
")",
"addrActive",
"(",
"addr",
"string",
")",
"bool",
"{",
"if",
"_",
",",
"ok",
":=",
"t",
".",
"halfOpen",
"[",
"addr",
"]",
";",
"ok",
"{",
"return",
"true",
"\n",
"}",
"\n",
"for",
"c",
":=",
"range",
"t",... | // There's a connection to that address already. | [
"There",
"s",
"a",
"connection",
"to",
"that",
"address",
"already",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/torrent.go#L208-L219 | train |
anacrolix/torrent | torrent.go | pieceFirstFileIndex | func pieceFirstFileIndex(pieceOffset int64, files []*File) int {
for i, f := range files {
if f.offset+f.length > pieceOffset {
return i
}
}
return 0
} | go | func pieceFirstFileIndex(pieceOffset int64, files []*File) int {
for i, f := range files {
if f.offset+f.length > pieceOffset {
return i
}
}
return 0
} | [
"func",
"pieceFirstFileIndex",
"(",
"pieceOffset",
"int64",
",",
"files",
"[",
"]",
"*",
"File",
")",
"int",
"{",
"for",
"i",
",",
"f",
":=",
"range",
"files",
"{",
"if",
"f",
".",
"offset",
"+",
"f",
".",
"length",
">",
"pieceOffset",
"{",
"return",... | // Returns the index of the first file containing the piece. files must be
// ordered by offset. | [
"Returns",
"the",
"index",
"of",
"the",
"first",
"file",
"containing",
"the",
"piece",
".",
"files",
"must",
"be",
"ordered",
"by",
"offset",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/torrent.go#L315-L322 | train |
anacrolix/torrent | torrent.go | pieceEndFileIndex | func pieceEndFileIndex(pieceEndOffset int64, files []*File) int {
for i, f := range files {
if f.offset+f.length >= pieceEndOffset {
return i + 1
}
}
return 0
} | go | func pieceEndFileIndex(pieceEndOffset int64, files []*File) int {
for i, f := range files {
if f.offset+f.length >= pieceEndOffset {
return i + 1
}
}
return 0
} | [
"func",
"pieceEndFileIndex",
"(",
"pieceEndOffset",
"int64",
",",
"files",
"[",
"]",
"*",
"File",
")",
"int",
"{",
"for",
"i",
",",
"f",
":=",
"range",
"files",
"{",
"if",
"f",
".",
"offset",
"+",
"f",
".",
"length",
">=",
"pieceEndOffset",
"{",
"ret... | // Returns the index after the last file containing the piece. files must be
// ordered by offset. | [
"Returns",
"the",
"index",
"after",
"the",
"last",
"file",
"containing",
"the",
"piece",
".",
"files",
"must",
"be",
"ordered",
"by",
"offset",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/torrent.go#L326-L333 | train |
anacrolix/torrent | torrent.go | setInfoBytes | func (t *Torrent) setInfoBytes(b []byte) error {
if metainfo.HashBytes(b) != t.infoHash {
return errors.New("info bytes have wrong hash")
}
var info metainfo.Info
if err := bencode.Unmarshal(b, &info); err != nil {
return fmt.Errorf("error unmarshalling info bytes: %s", err)
}
if err := t.setInfo(&info); err ... | go | func (t *Torrent) setInfoBytes(b []byte) error {
if metainfo.HashBytes(b) != t.infoHash {
return errors.New("info bytes have wrong hash")
}
var info metainfo.Info
if err := bencode.Unmarshal(b, &info); err != nil {
return fmt.Errorf("error unmarshalling info bytes: %s", err)
}
if err := t.setInfo(&info); err ... | [
"func",
"(",
"t",
"*",
"Torrent",
")",
"setInfoBytes",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"metainfo",
".",
"HashBytes",
"(",
"b",
")",
"!=",
"t",
".",
"infoHash",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
... | // Called when metadata for a torrent becomes available. | [
"Called",
"when",
"metadata",
"for",
"a",
"torrent",
"becomes",
"available",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/torrent.go#L387-L402 | train |
anacrolix/torrent | torrent.go | name | func (t *Torrent) name() string {
t.nameMu.RLock()
defer t.nameMu.RUnlock()
if t.haveInfo() {
return t.info.Name
}
return t.displayName
} | go | func (t *Torrent) name() string {
t.nameMu.RLock()
defer t.nameMu.RUnlock()
if t.haveInfo() {
return t.info.Name
}
return t.displayName
} | [
"func",
"(",
"t",
"*",
"Torrent",
")",
"name",
"(",
")",
"string",
"{",
"t",
".",
"nameMu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"t",
".",
"nameMu",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"t",
".",
"haveInfo",
"(",
")",
"{",
"return",
"t",
"... | // The current working name for the torrent. Either the name in the info dict,
// or a display name given such as by the dn value in a magnet link, or "". | [
"The",
"current",
"working",
"name",
"for",
"the",
"torrent",
".",
"Either",
"the",
"name",
"in",
"the",
"info",
"dict",
"or",
"a",
"display",
"name",
"given",
"such",
"as",
"by",
"the",
"dn",
"value",
"in",
"a",
"magnet",
"link",
"or",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/torrent.go#L442-L449 | train |
anacrolix/torrent | torrent.go | pieceStateRunStatusChars | func pieceStateRunStatusChars(psr PieceStateRun) (ret string) {
ret = fmt.Sprintf("%d", psr.Length)
ret += func() string {
switch psr.Priority {
case PiecePriorityNext:
return "N"
case PiecePriorityNormal:
return "."
case PiecePriorityReadahead:
return "R"
case PiecePriorityNow:
return "!"
cas... | go | func pieceStateRunStatusChars(psr PieceStateRun) (ret string) {
ret = fmt.Sprintf("%d", psr.Length)
ret += func() string {
switch psr.Priority {
case PiecePriorityNext:
return "N"
case PiecePriorityNormal:
return "."
case PiecePriorityReadahead:
return "R"
case PiecePriorityNow:
return "!"
cas... | [
"func",
"pieceStateRunStatusChars",
"(",
"psr",
"PieceStateRun",
")",
"(",
"ret",
"string",
")",
"{",
"ret",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"psr",
".",
"Length",
")",
"\n",
"ret",
"+=",
"func",
"(",
")",
"string",
"{",
"switch",
"p... | // Produces a small string representing a PieceStateRun. | [
"Produces",
"a",
"small",
"string",
"representing",
"a",
"PieceStateRun",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/torrent.go#L499-L530 | train |
anacrolix/torrent | torrent.go | newMetaInfo | func (t *Torrent) newMetaInfo() metainfo.MetaInfo {
return metainfo.MetaInfo{
CreationDate: time.Now().Unix(),
Comment: "dynamic metainfo from client",
CreatedBy: "go.torrent",
AnnounceList: t.metainfo.UpvertedAnnounceList(),
InfoBytes: func() []byte {
if t.haveInfo() {
return t.metadataBytes
... | go | func (t *Torrent) newMetaInfo() metainfo.MetaInfo {
return metainfo.MetaInfo{
CreationDate: time.Now().Unix(),
Comment: "dynamic metainfo from client",
CreatedBy: "go.torrent",
AnnounceList: t.metainfo.UpvertedAnnounceList(),
InfoBytes: func() []byte {
if t.haveInfo() {
return t.metadataBytes
... | [
"func",
"(",
"t",
"*",
"Torrent",
")",
"newMetaInfo",
"(",
")",
"metainfo",
".",
"MetaInfo",
"{",
"return",
"metainfo",
".",
"MetaInfo",
"{",
"CreationDate",
":",
"time",
".",
"Now",
"(",
")",
".",
"Unix",
"(",
")",
",",
"Comment",
":",
"\"",
"\"",
... | // Returns a run-time generated MetaInfo that includes the info bytes and
// announce-list as currently known to the client. | [
"Returns",
"a",
"run",
"-",
"time",
"generated",
"MetaInfo",
"that",
"includes",
"the",
"info",
"bytes",
"and",
"announce",
"-",
"list",
"as",
"currently",
"known",
"to",
"the",
"client",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/torrent.go#L602-L616 | train |
anacrolix/torrent | torrent.go | bytesLeftAnnounce | func (t *Torrent) bytesLeftAnnounce() uint64 {
if t.haveInfo() {
return uint64(t.bytesLeft())
} else {
return math.MaxUint64
}
} | go | func (t *Torrent) bytesLeftAnnounce() uint64 {
if t.haveInfo() {
return uint64(t.bytesLeft())
} else {
return math.MaxUint64
}
} | [
"func",
"(",
"t",
"*",
"Torrent",
")",
"bytesLeftAnnounce",
"(",
")",
"uint64",
"{",
"if",
"t",
".",
"haveInfo",
"(",
")",
"{",
"return",
"uint64",
"(",
"t",
".",
"bytesLeft",
"(",
")",
")",
"\n",
"}",
"else",
"{",
"return",
"math",
".",
"MaxUint64... | // Bytes left to give in tracker announces. | [
"Bytes",
"left",
"to",
"give",
"in",
"tracker",
"announces",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/torrent.go#L638-L644 | train |
anacrolix/torrent | torrent.go | offsetRequest | func (t *Torrent) offsetRequest(off int64) (req request, ok bool) {
return torrentOffsetRequest(*t.length, t.info.PieceLength, int64(t.chunkSize), off)
} | go | func (t *Torrent) offsetRequest(off int64) (req request, ok bool) {
return torrentOffsetRequest(*t.length, t.info.PieceLength, int64(t.chunkSize), off)
} | [
"func",
"(",
"t",
"*",
"Torrent",
")",
"offsetRequest",
"(",
"off",
"int64",
")",
"(",
"req",
"request",
",",
"ok",
"bool",
")",
"{",
"return",
"torrentOffsetRequest",
"(",
"*",
"t",
".",
"length",
",",
"t",
".",
"info",
".",
"PieceLength",
",",
"int... | // Return the request that would include the given offset into the torrent
// data. Returns !ok if there is no such request. | [
"Return",
"the",
"request",
"that",
"would",
"include",
"the",
"given",
"offset",
"into",
"the",
"torrent",
"data",
".",
"Returns",
"!ok",
"if",
"there",
"is",
"no",
"such",
"request",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/torrent.go#L691-L693 | train |
anacrolix/torrent | torrent.go | worstBadConn | func (t *Torrent) worstBadConn() *connection {
wcs := worseConnSlice{t.unclosedConnsAsSlice()}
heap.Init(&wcs)
for wcs.Len() != 0 {
c := heap.Pop(&wcs).(*connection)
if c.stats.ChunksReadWasted.Int64() >= 6 && c.stats.ChunksReadWasted.Int64() > c.stats.ChunksReadUseful.Int64() {
return c
}
// If the conne... | go | func (t *Torrent) worstBadConn() *connection {
wcs := worseConnSlice{t.unclosedConnsAsSlice()}
heap.Init(&wcs)
for wcs.Len() != 0 {
c := heap.Pop(&wcs).(*connection)
if c.stats.ChunksReadWasted.Int64() >= 6 && c.stats.ChunksReadWasted.Int64() > c.stats.ChunksReadUseful.Int64() {
return c
}
// If the conne... | [
"func",
"(",
"t",
"*",
"Torrent",
")",
"worstBadConn",
"(",
")",
"*",
"connection",
"{",
"wcs",
":=",
"worseConnSlice",
"{",
"t",
".",
"unclosedConnsAsSlice",
"(",
")",
"}",
"\n",
"heap",
".",
"Init",
"(",
"&",
"wcs",
")",
"\n",
"for",
"wcs",
".",
... | // 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
// than a minute. | [
"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",
... | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/torrent.go#L815-L833 | train |
anacrolix/torrent | torrent.go | updatePiecePriorities | func (t *Torrent) updatePiecePriorities(begin, end pieceIndex) {
for i := begin; i < end; i++ {
t.updatePiecePriority(i)
}
} | go | func (t *Torrent) updatePiecePriorities(begin, end pieceIndex) {
for i := begin; i < end; i++ {
t.updatePiecePriority(i)
}
} | [
"func",
"(",
"t",
"*",
"Torrent",
")",
"updatePiecePriorities",
"(",
"begin",
",",
"end",
"pieceIndex",
")",
"{",
"for",
"i",
":=",
"begin",
";",
"i",
"<",
"end",
";",
"i",
"++",
"{",
"t",
".",
"updatePiecePriority",
"(",
"i",
")",
"\n",
"}",
"\n",... | // Update all piece priorities in one hit. This function should have the same
// output as updatePiecePriority, but across all pieces. | [
"Update",
"all",
"piece",
"priorities",
"in",
"one",
"hit",
".",
"This",
"function",
"should",
"have",
"the",
"same",
"output",
"as",
"updatePiecePriority",
"but",
"across",
"all",
"pieces",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/torrent.go#L936-L940 | train |
anacrolix/torrent | torrent.go | byteRegionPieces | func (t *Torrent) byteRegionPieces(off, size int64) (begin, end pieceIndex) {
if off >= *t.length {
return
}
if off < 0 {
size += off
off = 0
}
if size <= 0 {
return
}
begin = pieceIndex(off / t.info.PieceLength)
end = pieceIndex((off + size + t.info.PieceLength - 1) / t.info.PieceLength)
if end > piec... | go | func (t *Torrent) byteRegionPieces(off, size int64) (begin, end pieceIndex) {
if off >= *t.length {
return
}
if off < 0 {
size += off
off = 0
}
if size <= 0 {
return
}
begin = pieceIndex(off / t.info.PieceLength)
end = pieceIndex((off + size + t.info.PieceLength - 1) / t.info.PieceLength)
if end > piec... | [
"func",
"(",
"t",
"*",
"Torrent",
")",
"byteRegionPieces",
"(",
"off",
",",
"size",
"int64",
")",
"(",
"begin",
",",
"end",
"pieceIndex",
")",
"{",
"if",
"off",
">=",
"*",
"t",
".",
"length",
"{",
"return",
"\n",
"}",
"\n",
"if",
"off",
"<",
"0",... | // Returns the range of pieces [begin, end) that contains the extent of bytes. | [
"Returns",
"the",
"range",
"of",
"pieces",
"[",
"begin",
"end",
")",
"that",
"contains",
"the",
"extent",
"of",
"bytes",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/torrent.go#L943-L960 | train |
anacrolix/torrent | torrent.go | forReaderOffsetPieces | func (t *Torrent) forReaderOffsetPieces(f func(begin, end pieceIndex) (more bool)) (all bool) {
for r := range t.readers {
p := r.pieces
if p.begin >= p.end {
continue
}
if !f(p.begin, p.end) {
return false
}
}
return true
} | go | func (t *Torrent) forReaderOffsetPieces(f func(begin, end pieceIndex) (more bool)) (all bool) {
for r := range t.readers {
p := r.pieces
if p.begin >= p.end {
continue
}
if !f(p.begin, p.end) {
return false
}
}
return true
} | [
"func",
"(",
"t",
"*",
"Torrent",
")",
"forReaderOffsetPieces",
"(",
"f",
"func",
"(",
"begin",
",",
"end",
"pieceIndex",
")",
"(",
"more",
"bool",
")",
")",
"(",
"all",
"bool",
")",
"{",
"for",
"r",
":=",
"range",
"t",
".",
"readers",
"{",
"p",
... | // Returns true if all iterations complete without breaking. Returns the read
// regions for all readers. The reader regions should not be merged as some
// callers depend on this method to enumerate readers. | [
"Returns",
"true",
"if",
"all",
"iterations",
"complete",
"without",
"breaking",
".",
"Returns",
"the",
"read",
"regions",
"for",
"all",
"readers",
".",
"The",
"reader",
"regions",
"should",
"not",
"be",
"merged",
"as",
"some",
"callers",
"depend",
"on",
"th... | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/torrent.go#L965-L976 | train |
anacrolix/torrent | torrent.go | readAt | func (t *Torrent) readAt(b []byte, off int64) (n int, err error) {
p := &t.pieces[off/t.info.PieceLength]
p.waitNoPendingWrites()
return p.Storage().ReadAt(b, off-p.Info().Offset())
} | go | func (t *Torrent) readAt(b []byte, off int64) (n int, err error) {
p := &t.pieces[off/t.info.PieceLength]
p.waitNoPendingWrites()
return p.Storage().ReadAt(b, off-p.Info().Offset())
} | [
"func",
"(",
"t",
"*",
"Torrent",
")",
"readAt",
"(",
"b",
"[",
"]",
"byte",
",",
"off",
"int64",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"p",
":=",
"&",
"t",
".",
"pieces",
"[",
"off",
"/",
"t",
".",
"info",
".",
"PieceLength",
... | // Non-blocking read. Client lock is not required. | [
"Non",
"-",
"blocking",
"read",
".",
"Client",
"lock",
"is",
"not",
"required",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/torrent.go#L1074-L1078 | train |
anacrolix/torrent | torrent.go | maybeCompleteMetadata | func (t *Torrent) maybeCompleteMetadata() error {
if t.haveInfo() {
// Nothing to do.
return nil
}
if !t.haveAllMetadataPieces() {
// Don't have enough metadata pieces.
return nil
}
err := t.setInfoBytes(t.metadataBytes)
if err != nil {
t.invalidateMetadata()
return fmt.Errorf("error setting info byte... | go | func (t *Torrent) maybeCompleteMetadata() error {
if t.haveInfo() {
// Nothing to do.
return nil
}
if !t.haveAllMetadataPieces() {
// Don't have enough metadata pieces.
return nil
}
err := t.setInfoBytes(t.metadataBytes)
if err != nil {
t.invalidateMetadata()
return fmt.Errorf("error setting info byte... | [
"func",
"(",
"t",
"*",
"Torrent",
")",
"maybeCompleteMetadata",
"(",
")",
"error",
"{",
"if",
"t",
".",
"haveInfo",
"(",
")",
"{",
"// Nothing to do.",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"!",
"t",
".",
"haveAllMetadataPieces",
"(",
")",
"{",
"// D... | // Returns an error if the metadata was completed, but couldn't be set for
// some reason. Blame it on the last peer to contribute. | [
"Returns",
"an",
"error",
"if",
"the",
"metadata",
"was",
"completed",
"but",
"couldn",
"t",
"be",
"set",
"for",
"some",
"reason",
".",
"Blame",
"it",
"on",
"the",
"last",
"peer",
"to",
"contribute",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/torrent.go#L1088-L1106 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.