diff --git a/net/peer.go b/net/peer.go index eb19240..3173508 100644 --- a/net/peer.go +++ b/net/peer.go @@ -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") +} diff --git a/net/ws.go b/net/ws.go index 5ee4943..ace8c6f 100644 --- a/net/ws.go +++ b/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 +}