Skip to content

Commit

Permalink
p2p: use an error type for disconnect requests
Browse files Browse the repository at this point in the history
Test-tastic.
  • Loading branch information
fjl committed Dec 14, 2014
1 parent 65e39bf commit f0f6727
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 9 additions & 0 deletions p2p/peer_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,16 @@ func (d DiscReason) String() string {
return discReasonToString[d]
}

type discRequestedError DiscReason

func (err discRequestedError) Error() string {
return fmt.Sprintf("disconnect requested: %v", DiscReason(err))
}

func discReasonForError(err error) DiscReason {
if reason, ok := err.(discRequestedError); ok {
return DiscReason(reason)
}
peerError, ok := err.(*peerError)
if !ok {
return DiscSubprotocolError
Expand Down
3 changes: 1 addition & 2 deletions p2p/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ func (bp *baseProtocol) handle(rw MsgReadWriter) error {
if err := msg.Decode(&reason); err != nil {
return err
}
bp.peer.Disconnect(reason[0])
return nil
return discRequestedError(reason[0])

case pingMsg:
return bp.rw.EncodeMsg(pongMsg)
Expand Down

0 comments on commit f0f6727

Please sign in to comment.