mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-14 19:00:50 +01:00
Fix remote address in ws client
This commit is contained in:
parent
0261e15aad
commit
81f2330d49
@ -10,14 +10,16 @@ import (
|
||||
)
|
||||
|
||||
type Conn struct {
|
||||
*websocket.Conn
|
||||
ctx context.Context
|
||||
*websocket.Conn
|
||||
srvAddr *net.TCPAddr
|
||||
}
|
||||
|
||||
func NewConn(wsConn *websocket.Conn) net.Conn {
|
||||
func NewConn(wsConn *websocket.Conn, srvAddr *net.TCPAddr) net.Conn {
|
||||
return &Conn{
|
||||
Conn: wsConn,
|
||||
ctx: context.Background(),
|
||||
ctx: context.Background(),
|
||||
Conn: wsConn,
|
||||
srvAddr: srvAddr,
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,8 +42,7 @@ func (c *Conn) Write(b []byte) (n int, err error) {
|
||||
}
|
||||
|
||||
func (c *Conn) RemoteAddr() net.Addr {
|
||||
// todo: implement me
|
||||
return nil
|
||||
return c.srvAddr
|
||||
}
|
||||
|
||||
func (c *Conn) LocalAddr() net.Addr {
|
||||
|
@ -5,18 +5,31 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"nhooyr.io/websocket"
|
||||
)
|
||||
|
||||
func Dial(address string) (net.Conn, error) {
|
||||
|
||||
addr := fmt.Sprintf("ws://" + address)
|
||||
wsConn, _, err := websocket.Dial(context.Background(), addr, nil)
|
||||
hostName, _, err := net.SplitHostPort(address)
|
||||
|
||||
addr, err := net.ResolveTCPAddr("tcp", address)
|
||||
if err != nil {
|
||||
log.Errorf("failed to resolve address of Relay server: %s", address)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("ws://%s:%d"+addr.IP.String(), addr.Port)
|
||||
opts := &websocket.DialOptions{
|
||||
Host: hostName,
|
||||
}
|
||||
|
||||
wsConn, _, err := websocket.Dial(context.Background(), url, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
conn := NewConn(wsConn)
|
||||
conn := NewConn(wsConn, addr)
|
||||
|
||||
return conn, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user