feat: implement GetIP

This commit is contained in:
Derrick Hammer 2024-01-15 11:15:11 -05:00
parent e7026459b4
commit fc10a265a7
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 11 additions and 1 deletions

View File

@ -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")
}

View File

@ -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
}