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
|
RenderLocationURI() string
|
||||||
ListenForMessages(callback EventCallback, options ListenerOptions)
|
ListenForMessages(callback EventCallback, options ListenerOptions)
|
||||||
End() error
|
End() error
|
||||||
|
EndForAbuse() error
|
||||||
SetId(id *encoding.NodeId)
|
SetId(id *encoding.NodeId)
|
||||||
Id() *encoding.NodeId
|
Id() *encoding.NodeId
|
||||||
SetChallenge(challenge []byte)
|
SetChallenge(challenge []byte)
|
||||||
|
@ -46,6 +47,7 @@ type Peer interface {
|
||||||
IsHandshakeDone() bool
|
IsHandshakeDone() bool
|
||||||
SetHandshakeDone(status bool)
|
SetHandshakeDone(status bool)
|
||||||
GetIP() string
|
GetIP() string
|
||||||
|
Abused() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type BasePeer struct {
|
type BasePeer struct {
|
||||||
|
@ -80,6 +82,9 @@ func (b *BasePeer) ListenForMessages(callback EventCallback, options ListenerOpt
|
||||||
func (b *BasePeer) End() error {
|
func (b *BasePeer) End() error {
|
||||||
panic("must implement in child class")
|
panic("must implement in child class")
|
||||||
}
|
}
|
||||||
|
func (b *BasePeer) EndForAbuse() error {
|
||||||
|
panic("must implement in child class")
|
||||||
|
}
|
||||||
func (b *BasePeer) GetIP() string {
|
func (b *BasePeer) GetIP() string {
|
||||||
panic("must implement in child class")
|
panic("must implement in child class")
|
||||||
}
|
}
|
||||||
|
@ -121,3 +126,7 @@ func (b *BasePeer) IsHandshakeDone() bool {
|
||||||
func (b *BasePeer) SetHandshakeDone(status bool) {
|
func (b *BasePeer) SetHandshakeDone(status bool) {
|
||||||
b.handshaked = status
|
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 {
|
type WebSocketPeer struct {
|
||||||
BasePeer
|
BasePeer
|
||||||
socket *websocket.Conn
|
socket *websocket.Conn
|
||||||
|
abused bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *WebSocketPeer) Connect(uri *url.URL) (interface{}, error) {
|
func (p *WebSocketPeer) Connect(uri *url.URL) (interface{}, error) {
|
||||||
|
@ -103,7 +104,16 @@ func (p *WebSocketPeer) End() error {
|
||||||
|
|
||||||
return nil
|
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) {
|
func (p *WebSocketPeer) SetId(id *encoding.NodeId) {
|
||||||
p.id = id
|
p.id = id
|
||||||
}
|
}
|
||||||
|
@ -126,3 +136,6 @@ func (b *WebSocketPeer) GetIP() string {
|
||||||
|
|
||||||
return ipAddr
|
return ipAddr
|
||||||
}
|
}
|
||||||
|
func (p *WebSocketPeer) Abused() bool {
|
||||||
|
return p.abused
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue