Skip to content

Commit e4bdbbe

Browse files
Adjust logging
1 parent 07bd283 commit e4bdbbe

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

main.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"flag"
66
"fmt"
7+
"net"
78
"net/http"
89
"net/netip"
910
"os"
@@ -86,8 +87,8 @@ var (
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 {

proxy/manager.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ func (pm *ProxyManager) startTarget(proto, listenIP string, port int, targetAddr
213213
return fmt.Errorf("unsupported protocol: %s", proto)
214214
}
215215

216-
logger.Info("Started %s proxy from %s:%d to %s", proto, listenIP, port, targetAddr)
216+
logger.Info("Started %s proxy to %s", proto, targetAddr)
217+
logger.Debug("Started %s proxy from %s:%d to %s", proto, listenIP, port, targetAddr)
217218

218219
return nil
219220
}

util.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ func pingWithRetry(tnet *netstack.Net, dst string, timeout time.Duration) (stopC
112112
retryDelay := initialRetryDelay
113113

114114
// First try with the initial parameters
115-
logger.Info("Ping attempt %d", attempt)
115+
logger.Debug("Ping attempt %d", attempt)
116116
if latency, err := ping(tnet, dst, timeout); err == nil {
117117
// Successful ping
118-
logger.Info("Ping latency: %v", latency)
118+
logger.Debug("Ping latency: %v", latency)
119119
logger.Info("Tunnel connection to server established successfully!")
120120
if healthFile != "" {
121121
err := os.WriteFile(healthFile, []byte("ok"), 0644)
@@ -137,7 +137,7 @@ func pingWithRetry(tnet *netstack.Net, dst string, timeout time.Duration) (stopC
137137
case <-stopChan:
138138
return
139139
default:
140-
logger.Info("Ping attempt %d", attempt)
140+
logger.Debug("Ping attempt %d", attempt)
141141

142142
if latency, err := ping(tnet, dst, timeout); err != nil {
143143
logger.Warn("Ping attempt %d failed: %v", attempt, err)
@@ -155,8 +155,8 @@ func pingWithRetry(tnet *netstack.Net, dst string, timeout time.Duration) (stopC
155155
attempt++
156156
} else {
157157
// Successful ping
158-
logger.Info("Ping succeeded after %d attempts", attempt)
159-
logger.Info("Ping latency: %v", latency)
158+
logger.Debug("Ping succeeded after %d attempts", attempt)
159+
logger.Debug("Ping latency: %v", latency)
160160
logger.Info("Tunnel connection to server established successfully!")
161161
if healthFile != "" {
162162
err := os.WriteFile(healthFile, []byte("ok"), 0644)

0 commit comments

Comments
 (0)