Browse Source

Add IPv6 support

ish_v.1.2.1
cacggghp 4 months ago
committed by GitHub
parent
commit
ceee08d44e
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 23
      client/main.go

23
client/main.go

@ -612,7 +612,7 @@ func oneTurnConnection(ctx context.Context, turnParams *turnParams, peer *net.UD
ctx1, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
if turnParams.udp {
conn, err2 := net.DialUDP("udp4", nil, turnServerUdpAddr) // nolint: noctx
conn, err2 := net.DialUDP("udp", nil, turnServerUdpAddr) // nolint: noctx
if err2 != nil {
err = fmt.Errorf("failed to connect to TURN server: %s", err2)
return
@ -625,7 +625,7 @@ func oneTurnConnection(ctx context.Context, turnParams *turnParams, peer *net.UD
}()
turnConn = &connectedUDPConn{conn}
} else {
conn, err2 := d.DialContext(ctx1, "tcp4", turnServerAddr) // nolint: noctx
conn, err2 := d.DialContext(ctx1, "tcp", turnServerAddr) // nolint: noctx
if err2 != nil {
err = fmt.Errorf("failed to connect to TURN server: %s", err2)
return
@ -638,15 +638,22 @@ func oneTurnConnection(ctx context.Context, turnParams *turnParams, peer *net.UD
}()
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
// This allows us to simulate datagram based communication over a net.Conn
cfg = &turn.ClientConfig{
STUNServerAddr: turnServerAddr,
TURNServerAddr: turnServerAddr,
Conn: turnConn,
Username: user,
Password: pass,
LoggerFactory: logging.NewDefaultLoggerFactory(),
STUNServerAddr: turnServerAddr,
TURNServerAddr: turnServerAddr,
Conn: turnConn,
Username: user,
Password: pass,
RequestedAddressFamily: addrFamily,
LoggerFactory: logging.NewDefaultLoggerFactory(),
}
client, err1 := turn.NewClient(cfg)

Loading…
Cancel
Save