Add IPv6 support
This commit is contained in:
1 parent
ab5d660416
commit
ceee08d44e
1 file changed
+9
-2
+9
-2
@@ -612,7 +612,7 @@ func oneTurnConnection(ctx context.Context, turnParams *turnParams, peer *net.UD
|
|||||||
ctx1, cancel := context.WithTimeout(ctx, 5*time.Second)
|
ctx1, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
if turnParams.udp {
|
if turnParams.udp {
|
||||||
conn, err2 := net.DialUDP("udp4", nil, turnServerUdpAddr) // nolint: noctx
|
conn, err2 := net.DialUDP("udp", nil, turnServerUdpAddr) // nolint: noctx
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
err = fmt.Errorf("failed to connect to TURN server: %s", err2)
|
err = fmt.Errorf("failed to connect to TURN server: %s", err2)
|
||||||
return
|
return
|
||||||
@@ -625,7 +625,7 @@ func oneTurnConnection(ctx context.Context, turnParams *turnParams, peer *net.UD
|
|||||||
}()
|
}()
|
||||||
turnConn = &connectedUDPConn{conn}
|
turnConn = &connectedUDPConn{conn}
|
||||||
} else {
|
} else {
|
||||||
conn, err2 := d.DialContext(ctx1, "tcp4", turnServerAddr) // nolint: noctx
|
conn, err2 := d.DialContext(ctx1, "tcp", turnServerAddr) // nolint: noctx
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
err = fmt.Errorf("failed to connect to TURN server: %s", err2)
|
err = fmt.Errorf("failed to connect to TURN server: %s", err2)
|
||||||
return
|
return
|
||||||
@@ -638,6 +638,12 @@ func oneTurnConnection(ctx context.Context, turnParams *turnParams, peer *net.UD
|
|||||||
}()
|
}()
|
||||||
turnConn = turn.NewSTUNConn(conn)
|
turnConn = turn.NewSTUNConn(conn)
|
||||||
}
|
}
|
||||||
|
var addrFamily turn.RequestedAddressFamily
|
||||||
|
if peer.IP.To4() != nil {
|
||||||
|
addrFamily = turn.RequestedAddressFamilyIPv4
|
||||||
|
} else {
|
||||||
|
addrFamily = turn.RequestedAddressFamilyIPv6
|
||||||
|
}
|
||||||
// Start a new TURN Client and wrap our net.Conn in a STUNConn
|
// Start a new TURN Client and wrap our net.Conn in a STUNConn
|
||||||
// This allows us to simulate datagram based communication over a net.Conn
|
// This allows us to simulate datagram based communication over a net.Conn
|
||||||
cfg = &turn.ClientConfig{
|
cfg = &turn.ClientConfig{
|
||||||
@@ -646,6 +652,7 @@ func oneTurnConnection(ctx context.Context, turnParams *turnParams, peer *net.UD
|
|||||||
Conn: turnConn,
|
Conn: turnConn,
|
||||||
Username: user,
|
Username: user,
|
||||||
Password: pass,
|
Password: pass,
|
||||||
|
RequestedAddressFamily: addrFamily,
|
||||||
LoggerFactory: logging.NewDefaultLoggerFactory(),
|
LoggerFactory: logging.NewDefaultLoggerFactory(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user