mirror of
https://github.com/fosrl/newt.git
synced 2026-02-08 05:56:40 +00:00
Rename logs, optional port
This commit is contained in:
@@ -37,7 +37,7 @@ func setupClients(client *websocket.Client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create WireGuard service
|
// Create WireGuard service
|
||||||
wgService, err = wgnetstack.NewWireGuardService(interfaceName, mtuInt, host, id, client, dns, useNativeInterface)
|
wgService, err = wgnetstack.NewWireGuardService(interfaceName, port, mtuInt, host, id, client, dns, useNativeInterface)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatal("Failed to create WireGuard service: %v", err)
|
logger.Fatal("Failed to create WireGuard service: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,17 +104,19 @@ type WireGuardService struct {
|
|||||||
wgTesterServer *wgtester.Server
|
wgTesterServer *wgtester.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWireGuardService(interfaceName string, mtu int, host string, newtId string, wsClient *websocket.Client, dns string, useNativeInterface bool) (*WireGuardService, error) {
|
func NewWireGuardService(interfaceName string, port uint16, mtu int, host string, newtId string, wsClient *websocket.Client, dns string, useNativeInterface bool) (*WireGuardService, error) {
|
||||||
key, err := wgtypes.GeneratePrivateKey()
|
key, err := wgtypes.GeneratePrivateKey()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to generate private key: %v", err)
|
return nil, fmt.Errorf("failed to generate private key: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find an available port
|
if port == 0 {
|
||||||
port, err := util.FindAvailableUDPPort(49152, 65535)
|
// Find an available port
|
||||||
|
portRandom, err := util.FindAvailableUDPPort(49152, 65535)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error finding available port: %v", err)
|
return nil, fmt.Errorf("error finding available port: %v", err)
|
||||||
|
}
|
||||||
|
port = uint16(portRandom)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create shared UDP socket for both holepunch and WireGuard
|
// Create shared UDP socket for both holepunch and WireGuard
|
||||||
@@ -522,7 +524,7 @@ func (s *WireGuardService) ensureWireguardInterface(wgconfig WgConfig) error {
|
|||||||
// Create WireGuard device using the shared bind
|
// Create WireGuard device using the shared bind
|
||||||
s.device = device.NewDevice(s.tun, s.sharedBind, device.NewLogger(
|
s.device = device.NewDevice(s.tun, s.sharedBind, device.NewLogger(
|
||||||
device.LogLevelSilent,
|
device.LogLevelSilent,
|
||||||
"wireguard: ",
|
"client-wireguard: ",
|
||||||
))
|
))
|
||||||
|
|
||||||
fileUAPI, err := func() (*os.File, error) {
|
fileUAPI, err := func() (*os.File, error) {
|
||||||
|
|||||||
16
main.go
16
main.go
@@ -116,6 +116,7 @@ var (
|
|||||||
err error
|
err error
|
||||||
logLevel string
|
logLevel string
|
||||||
interfaceName string
|
interfaceName string
|
||||||
|
port uint16
|
||||||
disableClients bool
|
disableClients bool
|
||||||
updownScript string
|
updownScript string
|
||||||
dockerSocket string
|
dockerSocket string
|
||||||
@@ -167,6 +168,7 @@ func main() {
|
|||||||
logLevel = os.Getenv("LOG_LEVEL")
|
logLevel = os.Getenv("LOG_LEVEL")
|
||||||
updownScript = os.Getenv("UPDOWN_SCRIPT")
|
updownScript = os.Getenv("UPDOWN_SCRIPT")
|
||||||
interfaceName = os.Getenv("INTERFACE")
|
interfaceName = os.Getenv("INTERFACE")
|
||||||
|
portStr := os.Getenv("PORT")
|
||||||
|
|
||||||
// Metrics/observability env mirrors
|
// Metrics/observability env mirrors
|
||||||
metricsEnabledEnv := os.Getenv("NEWT_METRICS_PROMETHEUS_ENABLED")
|
metricsEnabledEnv := os.Getenv("NEWT_METRICS_PROMETHEUS_ENABLED")
|
||||||
@@ -235,6 +237,9 @@ func main() {
|
|||||||
if interfaceName == "" {
|
if interfaceName == "" {
|
||||||
flag.StringVar(&interfaceName, "interface", "newt", "Name of the WireGuard interface")
|
flag.StringVar(&interfaceName, "interface", "newt", "Name of the WireGuard interface")
|
||||||
}
|
}
|
||||||
|
if portStr == "" {
|
||||||
|
flag.StringVar(&portStr, "port", "", "Port for client WireGuard interface")
|
||||||
|
}
|
||||||
if useNativeInterfaceEnv == "" {
|
if useNativeInterfaceEnv == "" {
|
||||||
flag.BoolVar(&useNativeInterface, "native", false, "Use native WireGuard interface")
|
flag.BoolVar(&useNativeInterface, "native", false, "Use native WireGuard interface")
|
||||||
}
|
}
|
||||||
@@ -297,6 +302,15 @@ func main() {
|
|||||||
pingTimeout = 5 * time.Second
|
pingTimeout = 5 * time.Second
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if portStr != "" {
|
||||||
|
portInt, err := strconv.Atoi(portStr)
|
||||||
|
if err != nil {
|
||||||
|
logger.Warn("Failed to parse PORT, choosing a random port")
|
||||||
|
} else {
|
||||||
|
port = uint16(portInt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if dockerEnforceNetworkValidation == "" {
|
if dockerEnforceNetworkValidation == "" {
|
||||||
flag.StringVar(&dockerEnforceNetworkValidation, "docker-enforce-network-validation", "false", "Enforce validation of container on newt network (true or false)")
|
flag.StringVar(&dockerEnforceNetworkValidation, "docker-enforce-network-validation", "false", "Enforce validation of container on newt network (true or false)")
|
||||||
}
|
}
|
||||||
@@ -641,7 +655,7 @@ func main() {
|
|||||||
// Create WireGuard device
|
// Create WireGuard device
|
||||||
dev = device.NewDevice(tun, conn.NewDefaultBind(), device.NewLogger(
|
dev = device.NewDevice(tun, conn.NewDefaultBind(), device.NewLogger(
|
||||||
util.MapToWireGuardLogLevel(loggerLevel),
|
util.MapToWireGuardLogLevel(loggerLevel),
|
||||||
"wireguard: ",
|
"gerbil-wireguard: ",
|
||||||
))
|
))
|
||||||
|
|
||||||
host, _, err := net.SplitHostPort(wgData.Endpoint)
|
host, _, err := net.SplitHostPort(wgData.Endpoint)
|
||||||
|
|||||||
Reference in New Issue
Block a user