From 9350c5f8d8325fb7b037c48aaac867bf9e958d3d Mon Sep 17 00:00:00 2001 From: braginini Date: Mon, 5 Sep 2022 15:56:36 +0200 Subject: [PATCH] bind --- client/internal/engine.go | 20 +++++++++++--------- client/internal/peer/conn.go | 12 ++++++------ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/client/internal/engine.go b/client/internal/engine.go index 546e90fb4..d664d0395 100644 --- a/client/internal/engine.go +++ b/client/internal/engine.go @@ -216,16 +216,18 @@ func (s *sharedUDPConn) ReadFrom(buff []byte) (n int, addr net.Addr, err error) if n, addr, err = s.PacketConn.ReadFrom(buff); err == nil { bytes := make([]byte, n) copy(bytes, buff) - if !stun.IsMessage(bytes[:n]) { + if !stun.IsMessage(bytes) { e, err := netip.ParseAddrPort(addr.String()) if err != nil { return 0, nil, err } - s.bind.OnData(bytes, &net.UDPAddr{ + a := &net.UDPAddr{ IP: e.Addr().AsSlice(), Port: int(e.Port()), Zone: e.Addr().Zone(), - }) + } + s.bind.OnData(bytes, a) + return 0, a, nil } } @@ -255,17 +257,17 @@ func (e *Engine) Start() error { log.Errorf("failed listening on UDP port %d: [%s]", e.config.UDPMuxPort, err.Error()) return err } - + s := &sharedUDPConn{PacketConn: e.udpMuxConn} + bind := iface.NewUserBind(s) + s.bind = bind e.udpMuxConnSrflx, err = net.ListenUDP("udp4", &net.UDPAddr{Port: e.config.UDPMuxSrflxPort}) if err != nil { log.Errorf("failed listening on UDP port %d: [%s]", e.config.UDPMuxSrflxPort, err.Error()) return err } - e.udpMux = ice.NewUDPMuxDefault(ice.UDPMuxParams{UDPConn: e.udpMuxConn}) - s := &sharedUDPConn{PacketConn: e.udpMuxConnSrflx} - bind := iface.NewUserBind(s) - s.bind = bind - e.udpMuxSrflx = ice.NewUniversalUDPMuxDefault(ice.UniversalUDPMuxParams{UDPConn: s}) + e.udpMux = ice.NewUDPMuxDefault(ice.UDPMuxParams{UDPConn: s}) + + e.udpMuxSrflx = ice.NewUniversalUDPMuxDefault(ice.UniversalUDPMuxParams{UDPConn: e.udpMuxConnSrflx}) err = e.wgInterface.CreateNew(bind) if err != nil { log.Errorf("failed creating tunnel interface %s: [%s]", wgIfaceName, err.Error()) diff --git a/client/internal/peer/conn.go b/client/internal/peer/conn.go index f11db253c..338108bc0 100644 --- a/client/internal/peer/conn.go +++ b/client/internal/peer/conn.go @@ -146,12 +146,12 @@ func (conn *Conn) reCreateAgent() error { conn.agent, err = ice.NewAgent(&ice.AgentConfig{ MulticastDNSMode: ice.MulticastDNSModeDisabled, NetworkTypes: []ice.NetworkType{ice.NetworkTypeUDP4}, - Urls: conn.config.StunTurn, - CandidateTypes: []ice.CandidateType{ice.CandidateTypeServerReflexive}, - FailedTimeout: &failedTimeout, - InterfaceFilter: interfaceFilter(conn.config.InterfaceBlackList), - UDPMux: conn.config.UDPMux, - UDPMuxSrflx: conn.config.UDPMuxSrflx, + //Urls: conn.config.StunTurn, + CandidateTypes: []ice.CandidateType{ice.CandidateTypeHost}, + FailedTimeout: &failedTimeout, + InterfaceFilter: interfaceFilter(conn.config.InterfaceBlackList), + UDPMux: conn.config.UDPMux, + UDPMuxSrflx: conn.config.UDPMuxSrflx, }) if err != nil { return err