Add debug information and extra sleep time

This commit is contained in:
Zoltan Papp
2023-04-26 11:17:19 +02:00
parent 91636feb69
commit 49018a4a8e
2 changed files with 19 additions and 9 deletions

View File

@@ -459,25 +459,30 @@ func (conn *Conn) getProxyWithMessageExchange(pair *ice.CandidatePair, remoteWgP
// We decided to ignore the proxy decision when using Bind. Instead, we always punch remote WireGuard port to open a
// hole in the firewall for that remote port to avoid cases when old clients assumes direct mode.
mux := conn.config.UDPMuxSrflx.(*bind.UniversalUDPMuxDefault)
err := punchRemote(pair, remoteWgPort, mux)
if err != nil {
log.Warnf("failed to punch remote WireGuard port")
}
go func() {
err := punchRemote(pair, remoteWgPort, mux)
if err != nil {
log.Warnf("failed to punch remote WireGuard port: %s", err)
}
}()
return proxy.NewNoProxy(conn.config.ProxyConfig)
}
func punchRemote(pair *ice.CandidatePair, remoteWgPort int, muxDefault *bind.UniversalUDPMuxDefault) error {
addr, err := net.ResolveUDPAddr("udp", pair.Remote.Address())
addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", pair.Remote.Address(), remoteWgPort))
if err != nil {
return err
}
addr.Port = remoteWgPort
_, err = muxDefault.GetSharedConn().WriteTo([]byte{1}, addr)
if err != nil {
return err
for i := 0; i < 10; i++ {
_, err = muxDefault.GetSharedConn().WriteTo([]byte{1}, addr)
if err != nil {
return err
}
log.Debugf("puch msg has been sent: %d, %s, %v", i, addr.String(), muxDefault.GetSharedConn().LocalAddr())
time.Sleep(time.Second)
}
return err
}

View File

@@ -109,10 +109,15 @@ func (b *ICEBind) makeReceiveIPv4(c net.PacketConn) conn.ReceiveFunc {
if err != nil {
return 0, nil, err
}
e, err := netip.ParseAddrPort(endpoint.String())
if err != nil {
return 0, nil, err
}
if e.Port() == 51820 {
log.Debugf("received msg from 51820: %v, %d", e.String(), n)
}
if !stun.IsMessage(buff) {
// WireGuard traffic
return n, (conn.StdNetEndpoint)(netip.AddrPortFrom(e.Addr(), e.Port())), nil