feat: implement GetIP
This commit is contained in:
parent
e7026459b4
commit
fc10a265a7
|
@ -81,7 +81,6 @@ func (b *BasePeer) End() error {
|
||||||
panic("must implement in child class")
|
panic("must implement in child class")
|
||||||
}
|
}
|
||||||
func (b *BasePeer) GetIP() string {
|
func (b *BasePeer) GetIP() string {
|
||||||
//TODO implement me
|
|
||||||
panic("must implement in child class")
|
panic("must implement in child class")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
11
net/ws.go
11
net/ws.go
|
@ -115,3 +115,14 @@ func (p *WebSocketPeer) SetChallenge(challenge []byte) {
|
||||||
func (p *WebSocketPeer) GetChallenge() []byte {
|
func (p *WebSocketPeer) GetChallenge() []byte {
|
||||||
return p.challenge
|
return p.challenge
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *WebSocketPeer) GetIP() string {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
netConn := websocket.NetConn(ctx, b.socket, websocket.MessageBinary)
|
||||||
|
|
||||||
|
ipAddr := netConn.RemoteAddr().String()
|
||||||
|
|
||||||
|
cancel()
|
||||||
|
|
||||||
|
return ipAddr
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue