Add propper logging - remove windows routing?

This commit is contained in:
Owen
2025-05-11 10:28:01 -04:00
parent becc214078
commit c04e727bd3
4 changed files with 25 additions and 12 deletions

3
go.sum
View File

@@ -6,6 +6,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/kardianos/service v1.2.2 h1:ZvePhAHfvo0A7Mftk/tEzqEZ7Q4lgnR8sGz4xu1YX60=
github.com/kardianos/service v1.2.2/go.mod h1:CIMRFEJVL+0DS1a3Nx06NaMn4Dz63Ng6O7dl0qH0zVM=
github.com/vishvananda/netlink v1.3.0 h1:X7l42GfcV4S6E4vHTsw48qbrV+9PVojNfIhZcwQdrZk= github.com/vishvananda/netlink v1.3.0 h1:X7l42GfcV4S6E4vHTsw48qbrV+9PVojNfIhZcwQdrZk=
github.com/vishvananda/netlink v1.3.0/go.mod h1:i6NetklAujEcC6fK0JPjT8qSwWyO0HLn4UKG+hGqeJs= github.com/vishvananda/netlink v1.3.0/go.mod h1:i6NetklAujEcC6fK0JPjT8qSwWyO0HLn4UKG+hGqeJs=
github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8= github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8=
@@ -16,6 +18,7 @@ golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa h1:t2QcU6V556bFjYgu4L6C+6VrC
golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa/go.mod h1:BHOTPb3L19zxehTsLoJXVaTktb06DFgmdW6Wb9s8jqk= golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa/go.mod h1:BHOTPb3L19zxehTsLoJXVaTktb06DFgmdW6Wb9s8jqk=
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=

11
main.go
View File

@@ -324,11 +324,12 @@ func main() {
logger.Error("Failed to add route for peer: %v", err) logger.Error("Failed to add route for peer: %v", err)
return return
} }
err = WindowsAddRoute(site.ServerIP, "", interfaceName) // this causes routing issues on Windows
if err != nil { // err = WindowsAddRoute(site.ServerIP, "", interfaceName)
logger.Error("Failed to add route for peer: %v", err) // if err != nil {
return // logger.Error("Failed to add route for peer: %v", err)
} // return
// }
logger.Info("Configured peer %s", site.PublicKey) logger.Info("Configured peer %s", site.PublicKey)
} }

View File

@@ -159,9 +159,14 @@ func (pm *PeerMonitor) Start() {
// Start monitoring all peers // Start monitoring all peers
for siteID, client := range pm.monitors { for siteID, client := range pm.monitors {
siteIDCopy := siteID // Create a copy for the closure siteIDCopy := siteID // Create a copy for the closure
client.StartMonitor(func(status wgtester.ConnectionStatus) { err := client.StartMonitor(func(status wgtester.ConnectionStatus) {
pm.handleConnectionStatusChange(siteIDCopy, status) pm.handleConnectionStatusChange(siteIDCopy, status)
}) })
if err != nil {
logger.Error("Failed to start monitoring peer %d: %v\n", siteID, err)
continue
}
logger.Info("Started monitoring peer %d\n", siteID)
} }
} }
@@ -197,11 +202,11 @@ persistent_keepalive_interval=1`, pm.privateKey, config.PublicKey, config.Server
err := pm.device.IpcSet(wgConfig) err := pm.device.IpcSet(wgConfig)
if err != nil { if err != nil {
fmt.Printf("Failed to configure WireGuard device: %v\n", err) logger.Error("Failed to configure WireGuard device: %v\n", err)
return return
} }
fmt.Printf("Adjusted peer %d to point to relay!\n", siteID) logger.Info("Adjusted peer %d to point to relay!\n", siteID)
// Send relay message to the server // Send relay message to the server
if pm.wsClient != nil { if pm.wsClient != nil {

View File

@@ -3,10 +3,11 @@ package wgtester
import ( import (
"context" "context"
"encoding/binary" "encoding/binary"
"log"
"net" "net"
"sync" "sync"
"time" "time"
"github.com/fosrl/newt/logger"
) )
const ( const (
@@ -99,6 +100,7 @@ func (c *Client) ensureConnection() error {
// Returns true if connected, false otherwise // Returns true if connected, false otherwise
func (c *Client) TestConnection(ctx context.Context) (bool, time.Duration) { func (c *Client) TestConnection(ctx context.Context) (bool, time.Duration) {
if err := c.ensureConnection(); err != nil { if err := c.ensureConnection(); err != nil {
logger.Warn("Failed to ensure connection: %v", err)
return false, 0 return false, 0
} }
@@ -117,12 +119,13 @@ func (c *Client) TestConnection(ctx context.Context) (bool, time.Duration) {
timestamp := time.Now().UnixNano() timestamp := time.Now().UnixNano()
binary.BigEndian.PutUint64(packet[5:13], uint64(timestamp)) binary.BigEndian.PutUint64(packet[5:13], uint64(timestamp))
// Send the packet logger.Debug("Attempting to send monitor packet to %s", c.serverAddr)
_, err := c.conn.Write(packet) _, err := c.conn.Write(packet)
if err != nil { if err != nil {
log.Printf("Error sending packet: %v", err) logger.Info("Error sending packet: %v", err)
continue continue
} }
logger.Debug("Successfully sent monitor packet")
// Set read deadline // Set read deadline
c.conn.SetReadDeadline(time.Now().Add(c.timeout)) c.conn.SetReadDeadline(time.Now().Add(c.timeout))
@@ -136,7 +139,7 @@ func (c *Client) TestConnection(ctx context.Context) (bool, time.Duration) {
time.Sleep(100 * time.Millisecond) // Brief pause between attempts time.Sleep(100 * time.Millisecond) // Brief pause between attempts
continue continue
} }
log.Printf("Error reading response: %v", err) logger.Error("Error reading response: %v", err)
continue continue
} }
@@ -180,6 +183,7 @@ func (c *Client) StartMonitor(callback MonitorCallback) error {
defer c.monitorLock.Unlock() defer c.monitorLock.Unlock()
if c.monitorRunning { if c.monitorRunning {
logger.Info("Monitor already running")
return nil // Already running return nil // Already running
} }