@@ -29,6 +29,7 @@ import (
2929 "fmt"
3030 "io"
3131 "net"
32+ "strings"
3233 "sync"
3334 "sync/atomic"
3435 "time"
@@ -135,7 +136,20 @@ func NewSshUdpClient(opts *UdpClientOptions) (*SshUdpClient, error) {
135136 if err != nil {
136137 return nil , err
137138 }
139+ beginTime := time .Now ()
138140 if err := udpClient .networkProxy .renewTransportPath (opts .ProxyClient , opts .ConnectTimeout ); err != nil {
141+ if opts .ConnectTimeout > 2 * time .Second && time .Since (beginTime ) > (opts .ConnectTimeout - time .Second ) {
142+ net := "UDP"
143+ if opts .ServerInfo .ProxyMode == kProxyModeTCP {
144+ net = "TCP"
145+ }
146+ port := opts .TsshdAddr
147+ if pos := strings .LastIndex (opts .TsshdAddr , ":" ); pos >= 0 {
148+ port = opts .TsshdAddr [pos + 1 :]
149+ }
150+ return nil , fmt .Errorf ("%v\r \n %s" , err , fmt .Sprintf (
151+ "\033 [0;36mHint:\033 [0m This may be caused by a firewall blocking the %s port (%s) that tsshd is listening on." , net , port ))
152+ }
139153 return nil , err
140154 }
141155
@@ -348,7 +362,7 @@ func (c *SshUdpClient) DialUDP(network, addr string, timeout time.Duration) (Pac
348362 }
349363
350364 c .exitWG .Add (1 )
351- return & sshUdpPacketConn {conn , c }, nil
365+ return & sshUdpPacketConn {packetConn : conn , client : c }, nil
352366}
353367
354368// Listen requests the remote peer open a listening socket on addr
@@ -1224,9 +1238,13 @@ func (c *sshUdpChannel) Stderr() io.ReadWriter {
12241238type sshUdpPacketConn struct {
12251239 * packetConn
12261240 client * SshUdpClient
1241+ closed atomic.Bool
12271242}
12281243
12291244func (c * sshUdpPacketConn ) Close () error {
1245+ if ! c .closed .CompareAndSwap (false , true ) {
1246+ return nil
1247+ }
12301248 err := c .packetConn .Close ()
12311249 c .client .exitWG .Done ()
12321250 return err
0 commit comments