p2p: use an error type for disconnect requests
Test-tastic.
This commit is contained in:
parent
65e39bf20e
commit
f0f6727778
@ -100,7 +100,16 @@ func (d DiscReason) String() string {
|
|||||||
return discReasonToString[d]
|
return discReasonToString[d]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type discRequestedError DiscReason
|
||||||
|
|
||||||
|
func (err discRequestedError) Error() string {
|
||||||
|
return fmt.Sprintf("disconnect requested: %v", DiscReason(err))
|
||||||
|
}
|
||||||
|
|
||||||
func discReasonForError(err error) DiscReason {
|
func discReasonForError(err error) DiscReason {
|
||||||
|
if reason, ok := err.(discRequestedError); ok {
|
||||||
|
return DiscReason(reason)
|
||||||
|
}
|
||||||
peerError, ok := err.(*peerError)
|
peerError, ok := err.(*peerError)
|
||||||
if !ok {
|
if !ok {
|
||||||
return DiscSubprotocolError
|
return DiscSubprotocolError
|
||||||
|
@ -158,8 +158,7 @@ func (bp *baseProtocol) handle(rw MsgReadWriter) error {
|
|||||||
if err := msg.Decode(&reason); err != nil {
|
if err := msg.Decode(&reason); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
bp.peer.Disconnect(reason[0])
|
return discRequestedError(reason[0])
|
||||||
return nil
|
|
||||||
|
|
||||||
case pingMsg:
|
case pingMsg:
|
||||||
return bp.rw.EncodeMsg(pongMsg)
|
return bp.rw.EncodeMsg(pongMsg)
|
||||||
|
Loading…
Reference in New Issue
Block a user