本文整理汇总了Golang中github.com/anacrolix/torrent/peer_protocol.Integer函数的典型用法代码示例。如果您正苦于以下问题:Golang Integer函数的具体用法?Golang Integer怎么用?Golang Integer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Integer函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: pieceLength
func (t *torrent) pieceLength(piece int) (len_ pp.Integer) {
if int(piece) == t.numPieces()-1 {
len_ = pp.Integer(t.Length() % t.Info.PieceLength)
}
if len_ == 0 {
len_ = pp.Integer(t.Info.PieceLength)
}
return
}
开发者ID:soul9,项目名称:torrent,代码行数:9,代码来源:torrent.go
示例2: pieceLength
func (t *Torrent) pieceLength(piece int) (len_ pp.Integer) {
if piece < 0 || piece >= t.info.NumPieces() {
return
}
if piece == t.numPieces()-1 {
len_ = pp.Integer(t.length % t.info.PieceLength)
}
if len_ == 0 {
len_ = pp.Integer(t.info.PieceLength)
}
return
}
开发者ID:CaptainIlu,项目名称:cloud-torrent,代码行数:12,代码来源:torrent.go
示例3: chunkIndexSpec
func chunkIndexSpec(index int, pieceLength, chunkSize pp.Integer) chunkSpec {
ret := chunkSpec{pp.Integer(index) * chunkSize, chunkSize}
if ret.Begin+ret.Length > pieceLength {
ret.Length = pieceLength - ret.Begin
}
return ret
}
开发者ID:ngaut,项目名称:torrent,代码行数:7,代码来源:piece.go
示例4: urgentChunkInPiece
func (t *torrent) urgentChunkInPiece(piece int) bool {
p := pp.Integer(piece)
for req := range t.urgent {
if req.Index == p {
return true
}
}
return false
}
开发者ID:soul9,项目名称:torrent,代码行数:9,代码来源:torrent.go
示例5: torrentOffsetRequest
// Return the request that would include the given offset into the torrent data.
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.Integer(pieceSize - int64(r.Begin))
if r.Length > 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
}
开发者ID:gbjk,项目名称:torrent,代码行数:20,代码来源:misc.go
示例6: connRequestPiecePendingChunks
func (t *Torrent) connRequestPiecePendingChunks(c *connection, piece int) (more bool) {
if !c.PeerHasPiece(piece) {
return true
}
chunkIndices := t.pieces[piece].undirtiedChunkIndices().ToSortedSlice()
return itertools.ForPerm(len(chunkIndices), func(i int) bool {
req := request{pp.Integer(piece), t.chunkIndexSpec(chunkIndices[i], piece)}
return c.Request(req)
})
}
开发者ID:CaptainIlu,项目名称:cloud-torrent,代码行数:10,代码来源:torrent.go
示例7: connRequestPiecePendingChunks
func (t *torrent) connRequestPiecePendingChunks(c *connection, piece int) (more bool) {
if !c.PeerHasPiece(piece) {
return true
}
for _, cs := range t.Pieces[piece].shuffledPendingChunkSpecs(t, piece) {
req := request{pp.Integer(piece), cs}
if !c.Request(req) {
return false
}
}
return true
}
开发者ID:jpillora,项目名称:torrent,代码行数:12,代码来源:torrent.go
示例8: Have
func (cn *connection) Have(piece int) {
for piece >= len(cn.sentHaves) {
cn.sentHaves = append(cn.sentHaves, false)
}
if cn.sentHaves[piece] {
return
}
cn.Post(pp.Message{
Type: pp.Have,
Index: pp.Integer(piece),
})
cn.sentHaves[piece] = true
}
开发者ID:jaswinder-singh,项目名称:torrentsaga,代码行数:13,代码来源:connection.go
示例9: numDirtyBytes
func (p *piece) numDirtyBytes() (ret pp.Integer) {
defer func() {
if ret > p.length() {
panic("too many dirty bytes")
}
}()
numRegularDirtyChunks := p.numDirtyChunks()
if p.chunkIndexDirty(p.numChunks() - 1) {
numRegularDirtyChunks--
ret += p.chunkIndexSpec(p.lastChunkIndex()).Length
}
ret += pp.Integer(numRegularDirtyChunks) * p.chunkSize()
return
}
开发者ID:CaptainIlu,项目名称:cloud-torrent,代码行数:14,代码来源:piece.go
示例10: validOutgoingRequest
func (t *torrent) validOutgoingRequest(r request) bool {
if r.Index >= pp.Integer(t.Info.NumPieces()) {
return false
}
if r.Begin%t.chunkSize != 0 {
return false
}
if r.Length > t.chunkSize {
return false
}
pieceLength := t.pieceLength(int(r.Index))
if r.Begin+r.Length > pieceLength {
return false
}
return r.Length == t.chunkSize || r.Begin+r.Length == pieceLength
}
开发者ID:soul9,项目名称:torrent,代码行数:16,代码来源:torrent.go
示例11: pieceNumPendingBytes
func (t *torrent) pieceNumPendingBytes(index int) (count pp.Integer) {
if t.pieceComplete(index) {
return
}
piece := &t.Pieces[index]
count = t.pieceLength(index)
if !piece.EverHashed {
return
}
regularDirty := piece.numDirtyChunks()
lastChunkIndex := t.pieceNumChunks(index) - 1
if piece.pendingChunkIndex(lastChunkIndex) {
regularDirty--
count -= t.chunkIndexSpec(lastChunkIndex, index).Length
}
count -= pp.Integer(regularDirty) * t.chunkSize
return
}
开发者ID:robaman,项目名称:torrent,代码行数:18,代码来源:torrent.go
示例12: AddTorrentSpec
// Add or merge a torrent spec. If the torrent is already present, the
// trackers will be merged with the existing ones. If the Info isn't yet
// known, it will be set. The display name is replaced if the new spec
// provides one. Returns new if the torrent wasn't already in the client.
func (cl *Client) AddTorrentSpec(spec *TorrentSpec) (t *Torrent, new bool, err error) {
t, new = cl.AddTorrentInfoHash(spec.InfoHash)
if spec.DisplayName != "" {
t.SetDisplayName(spec.DisplayName)
}
if spec.Info != nil {
err = t.SetInfoBytes(spec.Info.Bytes)
if err != nil {
return
}
}
cl.mu.Lock()
defer cl.mu.Unlock()
if spec.ChunkSize != 0 {
t.chunkSize = pp.Integer(spec.ChunkSize)
}
t.addTrackers(spec.Trackers)
t.maybeNewConns()
return
}
开发者ID:jakop345,项目名称:torrent,代码行数:24,代码来源:client.go
示例13: downloadedChunk
// Handle a received chunk from a peer.
func (cl *Client) downloadedChunk(t *Torrent, c *connection, msg *pp.Message) {
chunksReceived.Add(1)
req := newRequest(msg.Index, msg.Begin, pp.Integer(len(msg.Piece)))
// Request has been satisfied.
if cl.connDeleteRequest(t, c, req) {
defer c.updateRequests()
} else {
unexpectedChunksReceived.Add(1)
}
index := int(req.Index)
piece := &t.pieces[index]
// Do we actually want this chunk?
if !t.wantPiece(req) {
unwantedChunksReceived.Add(1)
c.UnwantedChunksReceived++
return
}
c.UsefulChunksReceived++
c.lastUsefulChunkReceived = time.Now()
cl.upload(t, c)
// Need to record that it hasn't been written yet, before we attempt to do
// anything with it.
piece.incrementPendingWrites()
// Record that we have the chunk.
piece.unpendChunkIndex(chunkIndex(req.chunkSpec, t.chunkSize))
// Cancel pending requests for this chunk.
for _, c := range t.conns {
if cl.connCancel(t, c, req) {
c.updateRequests()
}
}
cl.mu.Unlock()
// Write the chunk out. Note that the upper bound on chunk writing
// concurrency will be the number of connections.
err := t.writeChunk(int(msg.Index), int64(msg.Begin), msg.Piece)
cl.mu.Lock()
piece.decrementPendingWrites()
if err != nil {
log.Printf("%s: error writing chunk %v: %s", t, req, err)
t.pendRequest(req)
t.updatePieceCompletion(int(msg.Index))
return
}
// It's important that the piece is potentially queued before we check if
// the piece is still wanted, because if it is queued, it won't be wanted.
if t.pieceAllDirty(index) {
cl.queuePieceCheck(t, int(req.Index))
}
if c.peerTouchedPieces == nil {
c.peerTouchedPieces = make(map[int]struct{})
}
c.peerTouchedPieces[index] = struct{}{}
cl.event.Broadcast()
t.publishPieceChange(int(req.Index))
return
}
开发者ID:jakop345,项目名称:torrent,代码行数:71,代码来源:client.go
注:本文中的github.com/anacrolix/torrent/peer_protocol.Integer函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论