}
}
-func (cl *Client) connDeleteRequest(t *Torrent, cn *connection, r request) bool {
- if !cn.RequestPending(r) {
- return false
- }
- delete(cn.requests, r)
- return true
-}
-
// Process incoming ut_metadata message.
func (cl *Client) gotMetadataExtensionMsg(payload []byte, t *Torrent, c *connection) error {
var d map[string]int
cn.writerCond.Broadcast()
}
-func (cn *connection) RequestPending(r request) bool {
- _, ok := cn.requests[r]
- return ok
-}
-
func (cn *connection) requestMetadataPiece(index int) {
eID := cn.PeerExtensionIDs["ut_metadata"]
if eID == 0 {
}
func (cn *connection) stopRequestingPiece(piece int) {
- cn.pieceRequestOrder.Remove(piece)
- cn.writerCond.Broadcast()
+ if cn.pieceRequestOrder.Remove(piece) {
+ cn.writerCond.Broadcast()
+ }
}
// This is distinct from Torrent piece priority, which is the user's
panic(tpp)
}
prio += piece / 3
- cn.pieceRequestOrder.Set(piece, prio)
- cn.updateRequests()
+ if cn.pieceRequestOrder.Set(piece, prio) {
+ cn.updateRequests()
+ }
}
func (cn *connection) getPieceInclination() []int {
// We can then reset our interest.
c.updateRequests()
case pp.Reject:
- cl.connDeleteRequest(t, c, newRequest(msg.Index, msg.Begin, msg.Length))
- c.updateRequests()
+ c.deleteRequest(newRequest(msg.Index, msg.Begin, msg.Length))
case pp.Unchoke:
c.PeerChoked = false
c.writerCond.Broadcast()
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 {
+ if !c.deleteRequest(req) {
unexpectedChunksReceived.Add(1)
}
func (c *connection) numLocalRequests() int {
return len(c.requests)
}
+
+func (c *connection) deleteRequest(r request) bool {
+ if _, ok := c.requests[r]; !ok {
+ return false
+ }
+ delete(c.requests, r)
+ c.writerCond.Broadcast()
+ return true
+}