44 "encoding/json"
55 "flag"
66 "fmt"
7+ "net"
78 "net/http"
89 "net/netip"
910 "os"
8687 dockerSocket string
8788 dockerEnforceNetworkValidation string
8889 dockerEnforceNetworkValidationBool bool
89- pingInterval = 1 * time .Second
90- pingTimeout = 2 * time .Second
90+ pingInterval = 2 * time .Second
91+ pingTimeout = 3 * time .Second
9192 publicKey wgtypes.Key
9293 pingStopChan chan struct {}
9394 stopFunc func ()
@@ -330,7 +331,7 @@ func main() {
330331
331332 clientsHandleNewtConnection (wgData .PublicKey )
332333
333- logger .Info ("Received: %+v" , msg )
334+ logger .Debug ("Received: %+v" , msg )
334335 tun , tnet , err = netstack .CreateNetTUN (
335336 []netip.Addr {netip .MustParseAddr (wgData .TunnelIP )},
336337 []netip.Addr {netip .MustParseAddr (dns )},
@@ -345,6 +346,14 @@ func main() {
345346 "wireguard: " ,
346347 ))
347348
349+ host , _ , err := net .SplitHostPort (wgData .Endpoint )
350+ if err != nil {
351+ logger .Error ("Failed to split endpoint: %v" , err )
352+ return
353+ }
354+
355+ logger .Info ("Connecting to endpoint: %s" , host )
356+
348357 endpoint , err := resolveDomain (wgData .Endpoint )
349358 if err != nil {
350359 logger .Error ("Failed to resolve endpoint: %v" , err )
@@ -369,7 +378,7 @@ persistent_keepalive_interval=5`, fixKey(privateKey.String()), fixKey(wgData.Pub
369378 logger .Error ("Failed to bring up WireGuard device: %v" , err )
370379 }
371380
372- logger .Info ("WireGuard device created. Lets ping the server now..." )
381+ logger .Debug ("WireGuard device created. Lets ping the server now..." )
373382
374383 // Even if pingWithRetry returns an error, it will continue trying in the background
375384 if pingWithRetryStopChan != nil {
@@ -382,7 +391,7 @@ persistent_keepalive_interval=5`, fixKey(privateKey.String()), fixKey(wgData.Pub
382391 // Always mark as connected and start the proxy manager regardless of initial ping result
383392 // as the pings will continue in the background
384393 if ! connected {
385- logger .Info ("Starting ping check" )
394+ logger .Debug ("Starting ping check" )
386395 pingStopChan = startPingCheck (tnet , wgData .ServerIP , client )
387396 }
388397
@@ -417,7 +426,6 @@ persistent_keepalive_interval=5`, fixKey(privateKey.String()), fixKey(wgData.Pub
417426 // Mark as disconnected
418427 connected = false
419428
420- // start asking for the exit nodes again
421429 if stopFunc != nil {
422430 stopFunc () // stop the ws from sending more requests
423431 stopFunc = nil // reset stopFunc to nil to avoid double stopping
@@ -438,7 +446,7 @@ persistent_keepalive_interval=5`, fixKey(privateKey.String()), fixKey(wgData.Pub
438446 // Mark as disconnected
439447 connected = false
440448
441- logger .Info ("Tunnel destroyed, ready for reconnection " )
449+ logger .Info ("Tunnel destroyed" )
442450 })
443451
444452 client .RegisterHandler ("newt/ping/exitNodes" , func (msg websocket.WSMessage ) {
@@ -547,7 +555,7 @@ persistent_keepalive_interval=5`, fixKey(privateKey.String()), fixKey(wgData.Pub
547555 })
548556
549557 client .RegisterHandler ("newt/tcp/add" , func (msg websocket.WSMessage ) {
550- logger .Info ("Received: %+v" , msg )
558+ logger .Debug ("Received: %+v" , msg )
551559
552560 // if there is no wgData or pm, we can't add targets
553561 if wgData .TunnelIP == "" || pm == nil {
0 commit comments