diff --git a/net/peer.go b/net/peer.go index f592509..eb19240 100644 --- a/net/peer.go +++ b/net/peer.go @@ -81,7 +81,6 @@ func (b *BasePeer) End() error { panic("must implement in child class") } func (b *BasePeer) GetIP() string { - //TODO implement me panic("must implement in child class") } diff --git a/net/ws.go b/net/ws.go index c2e4d48..5ee4943 100644 --- a/net/ws.go +++ b/net/ws.go @@ -115,3 +115,14 @@ func (p *WebSocketPeer) SetChallenge(challenge []byte) { func (p *WebSocketPeer) GetChallenge() []byte { 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 +}