mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-21 10:18:50 +02:00
Support exit node in ws client
This commit is contained in:
parent
9ae03046e7
commit
faeae52329
@ -4,9 +4,12 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"nhooyr.io/websocket"
|
||||
|
||||
nbnet "github.com/netbirdio/netbird/util/net"
|
||||
)
|
||||
|
||||
func Dial(address string) (net.Conn, error) {
|
||||
@ -22,6 +25,7 @@ func Dial(address string) (net.Conn, error) {
|
||||
url := fmt.Sprintf("ws://%s:%d", addr.IP.String(), addr.Port)
|
||||
opts := &websocket.DialOptions{
|
||||
Host: hostName,
|
||||
HTTPClient: httpClientNbDialer(),
|
||||
}
|
||||
|
||||
wsConn, _, err := websocket.Dial(context.Background(), url, opts)
|
||||
@ -34,3 +38,17 @@ func Dial(address string) (net.Conn, error) {
|
||||
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
func httpClientNbDialer() *http.Client {
|
||||
customDialer := nbnet.NewDialer()
|
||||
|
||||
customTransport := &http.Transport{
|
||||
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
return customDialer.DialContext(ctx, network, addr)
|
||||
},
|
||||
}
|
||||
|
||||
return &http.Client{
|
||||
Transport: customTransport,
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user