]> Sergey Matveev's repositories - btrtrc.git/blob - peer_protocol/ut-holepunch/err-code.go
Fix panic logging unknown holepunch error code
[btrtrc.git] / peer_protocol / ut-holepunch / err-code.go
1 package utHolepunch
2
3 import (
4         "fmt"
5 )
6
7 type ErrCode uint32
8
9 var _ error = ErrCode(0)
10
11 const (
12         NoSuchPeer ErrCode = iota + 1
13         NotConnected
14         NoSupport
15         NoSelf
16 )
17
18 func (ec ErrCode) Error() string {
19         switch ec {
20         case NoSuchPeer:
21                 return "target endpoint is invalid"
22         case NotConnected:
23                 return "the relaying peer is not connected to the target peer"
24         case NoSupport:
25                 return "the target peer does not support the holepunch extension"
26         case NoSelf:
27                 return "the target endpoint belongs to the relaying peer"
28         default:
29                 return fmt.Sprintf("error code %d", ec)
30         }
31 }