mirror of
https://github.com/fosrl/olm.git
synced 2026-03-12 05:36:43 +00:00
@@ -273,7 +273,6 @@ func StartTunnel(config TunnelConfig) {
|
||||
}
|
||||
|
||||
// Create shared UDP socket for both holepunch and WireGuard
|
||||
if sharedBind == nil {
|
||||
sourcePort, err := util.FindAvailableUDPPort(49152, 65535)
|
||||
if err != nil {
|
||||
logger.Error("Error finding available port: %v", err)
|
||||
@@ -302,12 +301,9 @@ func StartTunnel(config TunnelConfig) {
|
||||
sharedBind.AddRef()
|
||||
|
||||
logger.Info("Created shared UDP socket on port %d (refcount: %d)", sourcePort, sharedBind.GetRefCount())
|
||||
}
|
||||
|
||||
// Create the holepunch manager
|
||||
if holePunchManager == nil {
|
||||
holePunchManager = holepunch.NewManager(sharedBind, id, "olm")
|
||||
}
|
||||
|
||||
olm.RegisterHandler("olm/wg/holepunch/all", func(msg websocket.WSMessage) {
|
||||
logger.Debug("Received message: %v", msg.Data)
|
||||
@@ -828,6 +824,7 @@ func Close() {
|
||||
// Stop hole punch manager
|
||||
if holePunchManager != nil {
|
||||
holePunchManager.Stop()
|
||||
holePunchManager = nil
|
||||
}
|
||||
|
||||
if stopPing != nil {
|
||||
@@ -853,10 +850,12 @@ func Close() {
|
||||
uapiListener.Close()
|
||||
uapiListener = nil
|
||||
}
|
||||
|
||||
if dev != nil {
|
||||
dev.Close() // This will call sharedBind.Close() which releases WireGuard's reference
|
||||
dev = nil
|
||||
}
|
||||
|
||||
// Close TUN device
|
||||
if tdev != nil {
|
||||
tdev.Close()
|
||||
|
||||
Reference in New Issue
Block a user