conn.Unchoke()
case peer_protocol.NotInterested:
conn.PeerInterested = false
+ conn.Choke()
case peer_protocol.Have:
me.peerGotPiece(torrent, conn, int(msg.Index))
case peer_protocol.Request:
return true
}
+// Returns true if an unsatisfied request was canceled.
+func (c *connection) Cancel(r request) bool {
+ if c.Requests == nil {
+ return false
+ }
+ if _, ok := c.Requests[r]; !ok {
+ return false
+ }
+ delete(c.Requests, r)
+ c.Post(peer_protocol.Message{
+ Type: peer_protocol.Cancel,
+ Index: r.Index,
+ Begin: r.Begin,
+ Length: r.Length,
+ })
+ return true
+}
+
// Returns true if an unsatisfied request was canceled.
func (c *connection) PeerCancel(r request) bool {
if c.PeerRequests == nil {
return true
}
+func (c *connection) Choke() {
+ if c.Choked {
+ return
+ }
+ c.Post(peer_protocol.Message{
+ Type: peer_protocol.Choke,
+ })
+ c.Choked = true
+}
+
func (c *connection) Unchoke() {
if !c.Choked {
return