feat: add abused to peer so we can know when a peer has abused us and not log errors for them
This commit is contained in:
parent
5e80831335
commit
944067522a
|
@ -33,6 +33,7 @@ type Peer interface {
|
|||
RenderLocationURI() string
|
||||
ListenForMessages(callback EventCallback, options ListenerOptions)
|
||||
End() error
|
||||
EndForAbuse() error
|
||||
SetId(id *encoding.NodeId)
|
||||
Id() *encoding.NodeId
|
||||
SetChallenge(challenge []byte)
|
||||
|
@ -46,6 +47,7 @@ type Peer interface {
|
|||
IsHandshakeDone() bool
|
||||
SetHandshakeDone(status bool)
|
||||
GetIP() string
|
||||
Abused() bool
|
||||
}
|
||||
|
||||
type BasePeer struct {
|
||||
|
@ -80,6 +82,9 @@ func (b *BasePeer) ListenForMessages(callback EventCallback, options ListenerOpt
|
|||
func (b *BasePeer) End() error {
|
||||
panic("must implement in child class")
|
||||
}
|
||||
func (b *BasePeer) EndForAbuse() error {
|
||||
panic("must implement in child class")
|
||||
}
|
||||
func (b *BasePeer) GetIP() string {
|
||||
panic("must implement in child class")
|
||||
}
|
||||
|
@ -121,3 +126,7 @@ func (b *BasePeer) IsHandshakeDone() bool {
|
|||
func (b *BasePeer) SetHandshakeDone(status bool) {
|
||||
b.handshaked = status
|
||||
}
|
||||
|
||||
func (b *BasePeer) Abused() bool {
|
||||
panic("must implement in child class")
|
||||
}
|
||||
|
|
13
net/ws.go
13
net/ws.go
|
@ -16,6 +16,7 @@ var (
|
|||
type WebSocketPeer struct {
|
||||
BasePeer
|
||||
socket *websocket.Conn
|
||||
abused bool
|
||||
}
|
||||
|
||||
func (p *WebSocketPeer) Connect(uri *url.URL) (interface{}, error) {
|
||||
|
@ -103,7 +104,16 @@ func (p *WebSocketPeer) End() error {
|
|||
|
||||
return nil
|
||||
}
|
||||
func (p *WebSocketPeer) EndForAbuse() error {
|
||||
err := p.socket.Close(websocket.StatusPolicyViolation, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p.abused = true
|
||||
|
||||
return nil
|
||||
}
|
||||
func (p *WebSocketPeer) SetId(id *encoding.NodeId) {
|
||||
p.id = id
|
||||
}
|
||||
|
@ -126,3 +136,6 @@ func (b *WebSocketPeer) GetIP() string {
|
|||
|
||||
return ipAddr
|
||||
}
|
||||
func (p *WebSocketPeer) Abused() bool {
|
||||
return p.abused
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue