Skip to content

Commit

Permalink
handle block errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cenkalti committed Mar 4, 2019
1 parent 3c7d069 commit 3736b1c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion torrent/messagehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/cenkalti/rain/internal/peer"
"github.com/cenkalti/rain/internal/peerconn/peerwriter"
"github.com/cenkalti/rain/internal/peerprotocol"
"github.com/cenkalti/rain/internal/piecedownloader"
"github.com/cenkalti/rain/internal/piecewriter"
"github.com/cenkalti/rain/internal/tracker"
)
Expand Down Expand Up @@ -56,7 +57,19 @@ func (t *torrent) handlePieceMessage(pm peer.PieceMessage) {
msg.Buffer.Release()
return
}
pd.GotBlock(block, msg.Buffer.Data)
err := pd.GotBlock(block, msg.Buffer.Data)
switch err {
case piecedownloader.ErrBlockDuplicate:
pe.Logger().Warningln("received duplicate block:", block.Index)
case piecedownloader.ErrBlockNotRequested:
pe.Logger().Warningln("received not requested block:", block.Index)
case nil:
default:
pe.Logger().Error(err)
t.closePeer(pe)
msg.Buffer.Release()
return
}
msg.Buffer.Release()
if !pd.Done() {
if pd.AllowedFast || !pd.Peer.(*peer.Peer).PeerChoking {
Expand Down

0 comments on commit 3736b1c

Please sign in to comment.