From dfa5a03eccb7d806d2a868911c0d89cd4341ecf2 Mon Sep 17 00:00:00 2001 From: Murtaza Aliakbar Date: Tue, 29 Oct 2024 13:16:21 +0530 Subject: [PATCH] nilaway: retrier,dnscrypt/certs,pipws --- intra/dialers/retrier.go | 13 ++++--------- intra/dnscrypt/certs.go | 4 ++-- intra/ipn/pipws.go | 3 ++- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/intra/dialers/retrier.go b/intra/dialers/retrier.go index 3191796f..a777e14a 100644 --- a/intra/dialers/retrier.go +++ b/intra/dialers/retrier.go @@ -220,11 +220,8 @@ func (r *retrier) dialLocked() (c core.DuplexConn, err error) { begin := time.Now() c, err = r.doDialLocked(strat) - if c == nil { - err = core.OneErr(err, errNoConn) - } - rtt := time.Since(begin) + r.conn = c // c may be nil r.timeout = calcTimeout(rtt) @@ -250,10 +247,8 @@ func (r *retrier) doDialLocked(dialStrat int32) (_ core.DuplexConn, err error) { default: } conn, err = r.dialer.DialTCP(r.raddr.Network(), r.laddr, r.raddr) - if err != nil { + if err != nil || conn == nil { return nil, err - } else if conn == nil { - return nil, errNoConn } // todo: strat must be tcp or tls return &splitter{conn: conn, strat: dialStrat}, nil @@ -265,8 +260,8 @@ func (r *retrier) doDialLocked(dialStrat int32) (_ core.DuplexConn, err error) { func (r *retrier) retryWriteReadLocked(buf []byte) (int, error) { // r.dialLocked also closes provisional socket newConn, err := r.dialLocked() - if err != nil { - return 0, err + if err != nil || newConn == nil { + return 0, core.OneErr(err, errNoConn) } var nw int diff --git a/intra/dnscrypt/certs.go b/intra/dnscrypt/certs.go index 4c09f34b..39488f07 100644 --- a/intra/dnscrypt/certs.go +++ b/intra/dnscrypt/certs.go @@ -69,9 +69,9 @@ func fetchCurrentDNSCryptCert(proxy *DcMulti, serverName *string, pk ed25519.Pub } log.I("dnscrypt: [%v] Fetching DNSCrypt certificate for [%s] at [%v]", *serverName, providerName, serverAddress) in, rtt, err := dnsExchange(proxy.dialer, &query, serverAddress, serverName) - if err != nil { + if err != nil || in == nil { log.W("dnscrypt: [%s] TIMEOUT %v", *serverName, err) - return certinfo{}, err + return certinfo{}, core.OneErr(err, errFetchingCerts) } now := uint32(time.Now().Unix()) certInfo := certinfo{CryptoConstruction: xdns.UndefinedConstruction} diff --git a/intra/ipn/pipws.go b/intra/ipn/pipws.go index 9977b955..64302f1e 100644 --- a/intra/ipn/pipws.go +++ b/intra/ipn/pipws.go @@ -322,7 +322,8 @@ func (t *pipws) forward(network, addr string) (protect.Conn, error) { rurl := u.String() c, res, err := t.wsconn(rurl, msg) t.lastdial = time.Now() - if err != nil { + if err != nil || res == nil { // nilaway + err = core.OneErr(err, errNoProxyConn) core.CloseConn(c) log.E("pipws: req %s err: %v", rurl, err) t.status.Store(TKO)