From fc10a265a7726948e0e51189178eaa7d3694c724 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 15 Jan 2024 11:15:11 -0500 Subject: [PATCH] feat: implement GetIP --- net/peer.go | 1 - net/ws.go | 11 +++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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 +}