id stringlengths 2 7 | text stringlengths 17 51.2k | title stringclasses 1
value |
|---|---|---|
c22000 | e := Decoder{r: buf}
err = e.Decode(v)
if err == nil && buf.Len() != 0 {
err = ErrUnusedTrailingBytes{buf.Len()}
}
return
} | |
c22001 |
r.t.cl.event.Broadcast()
} | |
c22002 | r.mu.Unlock()
r.t.cl.lock()
defer r.t.cl.unlock()
r.posChanged()
} | |
c22003 | max -= len1
ret += len1
off += len1
}
// Ensure that ret hasn't exceeded our original max.
if max < 0 {
ret += max
}
return
} | |
c22004 | ra > r.length-r.pos {
ra = r.length - r.pos
}
ret.begin, ret.end = r.t.byteRegionPieces(r.torrentOffset(r.pos), ra)
return
} | |
c22005 | nil {
r.waitReadable(pos)
}
return r.available(pos, wanted)
} | |
c22006 | r.t.info.Piece(pi)
po := r.torrentOffset(pos) % r.t.info.PieceLength
b1 := missinggo.LimitLen(b, ip.Length()-po, avail)
n, err = r.t.readAt(b1, r.torrentOffset(pos))
if n != 0 {
err = nil
return
}
r.t.cl.lock()
// TODO: Just reset pieces in the readahead window. This might help
// prevent thrashi... | |
c22007 | {
return
}
n, err := c.socket.Write(buf.Bytes())
if err != nil {
return
}
if n != buf.Len() {
panic("write should send all or error")
}
return
} | |
c22008 | ok && opE.Timeout() {
c.contiguousTimeouts++
}
if readErr != nil {
return nil, errors.Wrap(readErr, "reading from socket")
}
buf := bytes.NewBuffer(b[:n])
var h ResponseHeader
err := binary.Read(buf, binary.BigEndian, &h)
switch err {
default:
panic(err)
case io.ErrUnexpectedEOF, io.EOF:
... | |
c22009 | ret := totalSize - piece*(1<<14)
if ret > 1<<14 {
ret = 1 << 14
}
return ret
} | |
c22010 | > pieceLeft {
r.Length = pieceLeft
}
torrentLeft := torrentLength - int64(r.Index)*pieceSize - int64(r.Begin)
if int64(r.Length) > torrentLeft {
r.Length = pp.Integer(torrentLeft)
}
ok = true
return
} | |
c22011 | post(peerID[:])
}
var b [68]byte
_, err = io.ReadFull(sock, b[:68])
if err != nil {
err = nil
return
}
if string(b[:20]) != Protocol {
return
}
missinggo.CopyExact(&res.PeerExtensionBits, b[20:28])
missinggo.CopyExact(&res.Hash, b[28:48])
missinggo.CopyExact(&res.PeerID, b[48:68])
// peerExtensions.Ad... | |
c22012 | {
return
}
d.buf.WriteByte(b)
}
} | |
c22013 | v.SetInt(n)
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
n, err := strconv.ParseUint(s, 10, 64)
checkForIntParseError(err, start)
if v.OverflowUint(n) {
panic(&UnmarshalTypeError{
Value: "integer " + s,
Type: v.Type(),
})
}
v.SetUint(n)
case reflect.Bool... | |
c22014 | dictField{}
}
if sf.r.PkgPath != "" {
panic(&UnmarshalFieldError{
Key: key,
Type: dict.Type(),
Field: sf.r,
})
}
return dictField{
Value: dict.FieldByIndex(sf.r.Index),
Ok: true,
Set: func() {},
IgnoreUnmarshalTypeError: sf.tag.IgnoreUnmarshalTypeError(),
}
default:
r... | |
c22015 | fmt.Errorf("unknown value type %+q", b),
})
} | |
c22016 | ClientIp6: krpc.NodeAddr{IP: me.t.cl.config.PublicIp6},
}.Do()
if err != nil {
ret.Err = fmt.Errorf("error announcing: %s", err)
return
}
me.t.AddPeers(Peers(nil).AppendFromTracker(res.Peers))
ret.NumPeers = len(res.Peers)
ret.Interval = time.Duration(res.Interval) * time.Second
return
} | |
c22017 |
panic("wat")
}
last = make(net.IP, n)
for i := 0; i < n; i++ {
last[i] = in.IP[i] | ^in.Mask[i]
}
return
} | |
c22018 | }
}
m := v.Interface().(Marshaler)
data, err := m.MarshalBencode()
if err != nil {
panic(&MarshalerError{v.Type(), err})
}
e.write(data)
return true
} | |
c22019 | f.t.info.Name
}
return strings.Join(fip, "/")
} | |
c22020 | {
len1 = remaining
}
ps := f.t.pieceState(i)
ret = append(ret, FilePieceState{len1, ps})
off = 0
remaining -= len1
}
return
} | |
c22021 | if prio == f.prio {
return
}
f.prio = prio
f.t.updatePiecePriorities(f.firstPieceIndex(), f.endPieceIndex())
} | |
c22022 | defer f.t.cl.unlock()
return f.prio
} | |
c22023 | if t.name() == "" {
fmt.Fprint(w, "<unknown name>")
} else {
fmt.Fprint(w, t.name())
}
fmt.Fprint(w, "\n")
if t.info != nil {
fmt.Fprintf(w, "%f%% of %d bytes (%s)", 100*(1-float64(t.bytesMissingLocked())/float64(t.info.TotalLength())), t.length, humanize.Bytes(uint64(t.info.TotalLength())))
} else... | |
c22024 | s.Close() })
cl.closeSockets()
for _, t := range cl.torrents {
t.close()
}
for _, f := range cl.onClose {
f()
}
cl.event.Broadcast()
} | |
c22025 | ok bool) {
cl.lock()
defer cl.unlock()
t, ok = cl.torrents[ih]
return
} | |
c22026 | ok := cl.dopplegangerAddrs[addr]
return ok
} | |
c22027 | if c == nil {
if err != nil && forgettableDialError(err) {
cte.Forget()
} else {
cte.Done()
}
} else {
dr.Conn = closeWrapper{c, func() error {
err := c.Close()
cte.Done()
return err
}}
}
resCh <- dr
}()
}
return true
})
}(... | |
c22028 | nil {
if cl.config.Debug {
cl.logger.Printf("error establishing outgoing connection: %s", err)
}
return
}
if c == nil {
return
}
defer c.Close()
c.Discovery = ps
cl.runHandshookConn(c, t)
} | |
c22029 |
defer cl.unlock()
for ih := range cl.torrents {
if !f(ih[:]) {
break
}
}
} | |
c22030 | else {
torrent.Add("handshakes received unencrypted", 1)
}
} else {
torrent.Add("handshakes received with error while handling encryption", 1)
}
if err != nil {
if err == mse.ErrNoSecretKeyMatch {
err = nil
}
return
}
if cl.config.ForceEncryption && !c.headerEncrypted {
err = errors.New("connect... | |
c22031 | = res.Hash
c.PeerExtensionBytes = res.PeerExtensionBits
c.PeerID = res.PeerID
c.completedHandshake = time.Now()
return
} | |
c22032 | msg.M[pp.ExtensionNamePex] = pexExtendedId
}
return bencode.MustMarshal(msg)
}(),
})
}
func() {
if conn.fastEnabled() {
if torrent.haveAllPieces() {
conn.Post(pp.Message{Type: pp.HaveAll})
conn.sentHaves.AddRange(0, bitmap.BitIndex(conn.t.NumPieces()))
return
} else if !torrent.ha... | |
c22033 | piece %d", piece)
}
c.metadataRequests[piece] = false
begin := len(payload) - metadataPieceSize(d["total_size"], piece)
if begin < 0 || begin >= len(payload) {
return fmt.Errorf("data has bad offset in payload: %d", begin)
}
t.saveMetadataPiece(piece, payload[begin:])
c.lastUsefulChunkReceived = time.... | |
c22034 | storageClient,
maxEstablishedConns: cl.config.EstablishedConnsPerTorrent,
networkingEnabled: true,
requestStrategy: 2,
metadataChanged: sync.Cond{
L: cl.locker(),
},
duplicateRequestTimeout: 1 * time.Second,
}
t.logger = cl.logger.Clone().AddValue(t)
t.setChunkSize(defaultChunkSize)
return
... | |
c22035 |
go t.dhtAnnouncer(s)
})
cl.torrents[infoHash] = t
cl.clearAcceptLimits()
t.updateWantPeersEvent()
// Tickle Client.waitAccept, new torrent may want conns.
cl.event.Broadcast()
return
} | |
c22036 | {
if cl.closed.IsSet() {
return false
}
cl.event.Wait()
}
return true
} | |
c22037 | cl.unlock()
return cl.torrentsAsSlice()
} | |
c22038 | {
return IpPort{cl.publicIp(peer), uint16(cl.incomingPeerPort())}
} | |
c22039 | y big.Int
y.Exp(&g, x, &p)
return h.postWrite(paddedLeft(y.Bytes(), 96))
} | |
c22040 | 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
} | |
c22041 | = suffixMatchLen(b1, b)
if i == len(b) {
break
}
if copy(b1, b1[len(b1)-i:]) != i {
panic("wat")
}
}
return nil
} | |
c22042 |
p.ID = []byte(d["peer id"].(string))
}
p.Port = int(d["port"].(int64))
} | |
c22043 | "" || announce == "" {
return true
}
}
}
return false
} | |
c22044 | me.om.ReplaceOrInsert(prioritizedPeersItem{me.getPrio(p), p}) != nil
} | |
c22045 | infoHash metainfo.Hash) string {
return baseDir
} | |
c22046 | infoHash metainfo.Hash) string) ClientImpl {
return newFileWithCustomPathMakerAndCompletion(baseDir, pathMaker, pieceCompletionForDir(baseDir))
} | |
c22047 | fi.Path...)...)
os.MkdirAll(filepath.Dir(name), 0777)
var f io.Closer
f, err = os.Create(name)
if err != nil {
break
}
f.Close()
}
return
} | |
c22048 | > fi.Length-off {
b = b[:fi.Length-off]
}
for off < fi.Length && len(b) != 0 {
n1, err1 := f.ReadAt(b, off)
b = b[n1:]
n += n1
off += int64(n1)
if n1 == 0 {
err = err1
break
}
}
return
} | |
c22049 | }
if n1 != 0 {
// Made progress.
continue
}
err = err1
if err == io.EOF {
// Lies.
err = io.ErrUnexpectedEOF
}
return
}
off -= fi.Length
}
err = io.EOF
return
} | |
c22050 | defer t.cl.unlock()
return t.info
} | |
c22051 | * 1024,
length: *t.length,
}
t.addReader(&r)
return &r
} | |
c22052 | defer t.cl.rUnlock()
return t.pieceStateRuns()
} | |
c22053 |
t.cl.lock()
defer t.cl.unlock()
return int64(t.pieces[piece].bytesLeft())
} | |
c22054 |
t.cl.dropTorrent(t.infoHash)
t.cl.unlock()
} | |
c22055 | t.cl.rUnlock()
return t.bytesCompleted()
} | |
c22056 | t.cl.unlock()
return t.seeding()
} | |
c22057 | if t.haveInfo() {
return
}
t.displayName = dn
} | |
c22058 | defer t.cl.unlock()
return t.newMetaInfo()
} | |
c22059 | defer t.cl.unlock()
t.downloadPiecesLocked(begin, end)
} | |
c22060 | an encrypted connection, I couldn't say
// > what's appropriate. We can carry forward the SupportsEncryption value as we
// > received it from trackers/DHT/PEX, or just use the encryption state for the
// > connection. It's probably easiest to do the latter for now.
// https://github.com/anacrolix/torrent/... | |
c22061 | if ra.String() == addr {
return true
}
}
return false
} | |
c22062 | if f.offset+f.length > pieceOffset {
return i
}
}
return 0
} | |
c22063 | f.offset+f.length >= pieceEndOffset {
return i + 1
}
}
return 0
} | |
c22064 | }
if err := t.setInfo(&info); err != nil {
return err
}
t.metadataBytes = b
t.metadataCompletedChunks = nil
t.onSetInfo()
return nil
} | |
c22065 | t.nameMu.RUnlock()
if t.haveInfo() {
return t.info.Name
}
return t.displayName
} | |
c22066 | return ""
}
}()
if psr.Checking {
ret += "H"
}
if psr.Partial {
ret += "P"
}
if psr.Complete {
ret += "C"
}
if !psr.Ok {
ret += "?"
}
return
} | |
c22067 | client",
CreatedBy: "go.torrent",
AnnounceList: t.metainfo.UpvertedAnnounceList(),
InfoBytes: func() []byte {
if t.haveInfo() {
return t.metadataBytes
} else {
return nil
}
}(),
}
} | |
c22068 | uint64(t.bytesLeft())
} else {
return math.MaxUint64
}
} | |
c22069 | t.info.PieceLength, int64(t.chunkSize), off)
} | |
c22070 |
if wcs.Len() >= (t.maxEstablishedConns+1)/2 {
// Give connections 1 minute to prove themselves.
if time.Since(c.completedHandshake) > time.Minute {
return c
}
}
}
return nil
} | |
c22071 | {
for i := begin; i < end; i++ {
t.updatePiecePriority(i)
}
} | |
c22072 | + size + t.info.PieceLength - 1) / t.info.PieceLength)
if end > pieceIndex(t.info.NumPieces()) {
end = pieceIndex(t.info.NumPieces())
}
return
} | |
c22073 | continue
}
if !f(p.begin, p.end) {
return false
}
}
return true
} | |
c22074 |
p.waitNoPendingWrites()
return p.Storage().ReadAt(b, off-p.Info().Offset())
} | |
c22075 | t.invalidateMetadata()
return fmt.Errorf("error setting info bytes: %s", err)
}
if t.cl.config.Debug {
t.logger.Printf("%s: got metadata from peers", t)
}
return nil
} | |
c22076 | t.info.TotalLength() - t.bytesLeft()
} | |
c22077 | ret = t.conns[c]
delete(t.conns, c)
torrent.Add("deleted connections", 1)
c.deleteAllRequests()
if len(t.conns) == 0 {
t.assertNoPendingRequests()
}
return
} | |
c22078 | if cl.config.DisableAggressiveUpload && t.needData() {
return false
}
return true
} | |
c22079 | := range t.metainfo.AnnounceList {
for _, url := range tier {
t.startScrapingTracker(url)
}
}
} | |
c22080 | described in BEP 3.
Left: t.bytesLeftAnnounce(),
Uploaded: t.stats.BytesWrittenData.Int64(),
// There's no mention of wasted or unwanted download in the BEP.
Downloaded: t.stats.BytesReadUsefulData.Int64(),
}
} | |
c22081 | if cp.Port == 0 {
// Can't do anything with this.
continue
}
t.addPeer(Peer{
IP: cp.IP[:],
Port: cp.Port,
Source: peerSourceDHTGetPeers,
})
}
cl.unlock()
}
} | |
c22082 | for addr := range t.halfOpen {
peers[addr] = struct{}{}
}
t.peers.Each(func(peer Peer) {
peers[fmt.Sprintf("%s:%d", peer.IP, peer.Port)] = struct{}{}
})
return len(peers)
} | |
c22083 | *ConnStats) {
cs.BytesRead.Add(c.stats.BytesRead.Int64())
cs.BytesWritten.Add(c.stats.BytesWritten.Int64())
})
c.reconciledHandshakeStats = true
} | |
c22084 | errors.New("existing connection preferred")
}
}
if len(t.conns) >= t.maxEstablishedConns {
c := t.worstBadConn()
if c == nil {
return errors.New("don't want conns")
}
c.Close()
t.deleteConnection(c)
}
if len(t.conns) >= t.maxEstablishedConns {
panic(len(t.conns))
}
t.conns[c] = struct{}{}
retur... | |
c22085 | any connections that aren't treating us
// favourably anyway.
// for c := range t.conns {
// if c.sentHave(piece) {
// c.Drop()
// }
// }
for conn := range t.conns {
if conn.PeerHasPiece(piece) {
conn.updateRequests()
}
}
} | |
c22086 | t.pieces[piece].dirtiers {
delete(c.peerTouchedPieces, piece)
ret = append(ret, c)
}
t.pieces[piece].dirtiers = nil
return
} | |
c22087 | t.publishPieceChange(pieceIndex)
t.updatePiecePriority(pieceIndex)
go t.verifyPiece(pieceIndex)
} | |
c22088 |
return
}
addr := IpPort{peer.IP, uint16(peer.Port)}
if t.addrActive(addr.String()) {
return
}
t.halfOpen[addr.String()] = peer
go t.cl.outgoingConnection(t, addr, peer.Source)
} | |
c22089 | f(&t.stats)
f(&t.cl.stats)
} | |
c22090 | err != nil {
return fmt.Errorf("error getting relative path: %s", err)
}
info.Files = append(info.Files, FileInfo{
Path: strings.Split(relPath, string(filepath.Separator)),
Length: fi.Size(),
})
return nil
})
if err != nil {
return
}
slices.Sort(info.Files, func(l, r FileInfo) bool {
return ... | |
c22091 | }
wn, err := io.CopyN(w, r, fi.Length)
r.Close()
if wn != fi.Length {
return fmt.Errorf("error copying %v: %s", fi, err)
}
}
return nil
} | |
c22092 | Info.Name is the basename, and
// thus a regular file.
Path: nil,
}}
}
return info.Files
} | |
c22093 | storedLabels[split[0]] = split[0]
} else {
storedLabels[split[1]] = split[0]
}
}
return storedLabels
} | |
c22094 | := make(map[string]string)
for _, s := range labels {
ignoredLabels[s] = ""
}
return ignoredLabels
} | |
c22095 | makeStoredLabels(storedLabels),
ignoredLabels: makeIgnoredLabels(ignoredLabels),
}, nil
} | |
c22096 | ")
if err != nil {
return "", err
}
return string(bytes), nil
} | |
c22097 | nil {
glog.Errorf("issues while creating an InfluxDB sink: %v, will retry on use", err)
}
return &influxdbSink{
client: client, // can be nil
c: c,
}
} | |
c22098 |
datapoint.Value = value.IntValue
} else {
datapoint.Value = value.FloatValue
}
for key, value := range labels {
key = toValidOpenTsdbName(key)
value = toValidOpenTsdbName(value)
if value != "" {
datapoint.Tags[key] = value
}
}
tsdbSink.putDefaultTags(&datapoint)
return datapoint
} | |
c22099 | datapoint.Tags[clusterNameTagName] = tsdbSink.clusterName
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.