refactor: add SetIP and optionally return it if it exists in the ws peer
This commit is contained in:
parent
45a483989c
commit
fc31653050
|
@ -47,6 +47,7 @@ type Peer interface {
|
||||||
SetHandshakeDone(status bool)
|
SetHandshakeDone(status bool)
|
||||||
GetIPString() string
|
GetIPString() string
|
||||||
GetIP() net.Addr
|
GetIP() net.Addr
|
||||||
|
SetIP(ip net.Addr)
|
||||||
Abuser() bool
|
Abuser() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,6 +94,10 @@ func (b *BasePeer) GetIP() net.Addr {
|
||||||
panic("must implement in child class")
|
panic("must implement in child class")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *BasePeer) SetIP(ip net.Addr) {
|
||||||
|
panic("must implement in child class")
|
||||||
|
}
|
||||||
|
|
||||||
func (b *BasePeer) Challenge() []byte {
|
func (b *BasePeer) Challenge() []byte {
|
||||||
return b.challenge
|
return b.challenge
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ type WebSocketPeer struct {
|
||||||
BasePeer
|
BasePeer
|
||||||
socket *websocket.Conn
|
socket *websocket.Conn
|
||||||
abuser bool
|
abuser bool
|
||||||
|
ip net.Addr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *WebSocketPeer) Connect(uri *url.URL) (interface{}, error) {
|
func (p *WebSocketPeer) Connect(uri *url.URL) (interface{}, error) {
|
||||||
|
@ -139,6 +140,10 @@ func (p *WebSocketPeer) GetChallenge() []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *WebSocketPeer) GetIP() net.Addr {
|
func (p *WebSocketPeer) GetIP() net.Addr {
|
||||||
|
if p.ip != nil {
|
||||||
|
return p.ip
|
||||||
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
netConn := websocket.NetConn(ctx, p.socket, websocket.MessageBinary)
|
netConn := websocket.NetConn(ctx, p.socket, websocket.MessageBinary)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue