refactor: add SetIP and optionally return it if it exists in the ws peer

This commit is contained in:
Derrick Hammer 2024-03-10 08:54:22 -04:00
parent 45a483989c
commit fc31653050
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 10 additions and 0 deletions

View File

@ -47,6 +47,7 @@ type Peer interface {
SetHandshakeDone(status bool)
GetIPString() string
GetIP() net.Addr
SetIP(ip net.Addr)
Abuser() bool
}
@ -93,6 +94,10 @@ func (b *BasePeer) GetIP() net.Addr {
panic("must implement in child class")
}
func (b *BasePeer) SetIP(ip net.Addr) {
panic("must implement in child class")
}
func (b *BasePeer) Challenge() []byte {
return b.challenge
}

View File

@ -19,6 +19,7 @@ type WebSocketPeer struct {
BasePeer
socket *websocket.Conn
abuser bool
ip net.Addr
}
func (p *WebSocketPeer) Connect(uri *url.URL) (interface{}, error) {
@ -139,6 +140,10 @@ func (p *WebSocketPeer) GetChallenge() []byte {
}
func (p *WebSocketPeer) GetIP() net.Addr {
if p.ip != nil {
return p.ip
}
ctx, cancel := context.WithCancel(context.Background())
netConn := websocket.NetConn(ctx, p.socket, websocket.MessageBinary)