mirror of
https://github.com/fosrl/olm.git
synced 2026-03-01 16:26:43 +00:00
Include on windows as well
This commit is contained in:
@@ -176,6 +176,7 @@ func main() {
|
|||||||
// Create TUN device and network stack
|
// Create TUN device and network stack
|
||||||
var dev *device.Device
|
var dev *device.Device
|
||||||
var wgData WgData
|
var wgData WgData
|
||||||
|
var holePunchData HolePunchData
|
||||||
var uapi net.Listener
|
var uapi net.Listener
|
||||||
var tdev tun.Device
|
var tdev tun.Device
|
||||||
|
|
||||||
@@ -320,16 +321,36 @@ persistent_keepalive_interval=1`, fixKey(privateKey.String()), fixKey(wgData.Pub
|
|||||||
logger.Info("WireGuard device created.")
|
logger.Info("WireGuard device created.")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
olm.RegisterHandler("olm/wg/holepunch", func(msg websocket.WSMessage) {
|
||||||
|
logger.Info("Received message: %v", msg.Data)
|
||||||
|
|
||||||
|
jsonData, err := json.Marshal(msg.Data)
|
||||||
|
if err != nil {
|
||||||
|
logger.Info("Error marshaling data: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := json.Unmarshal(jsonData, &holePunchData); err != nil {
|
||||||
|
logger.Info("Error unmarshaling target data: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
gerbilServerPubKey = holePunchData.ServerPubKey
|
||||||
|
})
|
||||||
|
|
||||||
olm.OnConnect(func() error {
|
olm.OnConnect(func() error {
|
||||||
publicKey := privateKey.PublicKey()
|
publicKey := privateKey.PublicKey()
|
||||||
logger.Debug("Public key: %s", publicKey)
|
logger.Debug("Public key: %s", publicKey)
|
||||||
|
|
||||||
go keepSendingRegistration(olm, publicKey.String())
|
go keepSendingRegistration(olm, publicKey.String())
|
||||||
|
|
||||||
logger.Info("Sent registration message")
|
logger.Info("Sent registration message")
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
// start sending UDP hole punch
|
olm.OnTokenUpdate(func(token string) {
|
||||||
go keepSendingUDPHolePunch(endpoint, id, sourcePort)
|
olmToken = token
|
||||||
|
})
|
||||||
|
|
||||||
// Connect to the WebSocket server
|
// Connect to the WebSocket server
|
||||||
if err := olm.Connect(); err != nil {
|
if err := olm.Connect(); err != nil {
|
||||||
@@ -337,6 +358,8 @@ persistent_keepalive_interval=1`, fixKey(privateKey.String()), fixKey(wgData.Pub
|
|||||||
}
|
}
|
||||||
defer olm.Close()
|
defer olm.Close()
|
||||||
|
|
||||||
|
go keepSendingUDPHolePunch(endpoint, id, sourcePort)
|
||||||
|
|
||||||
// Wait for interrupt signal
|
// Wait for interrupt signal
|
||||||
sigCh := make(chan os.Signal, 1)
|
sigCh := make(chan os.Signal, 1)
|
||||||
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM, windows.SIGTERM)
|
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM, windows.SIGTERM)
|
||||||
|
|||||||
Reference in New Issue
Block a user