mirror of
https://github.com/fosrl/olm.git
synced 2026-02-21 12:26:46 +00:00
Holepunch but relay by default
This commit is contained in:
31
common.go
31
common.go
@@ -65,7 +65,7 @@ type EncryptedHolePunchMessage struct {
|
||||
var (
|
||||
peerMonitor *peermonitor.PeerMonitor
|
||||
stopHolepunch chan struct{}
|
||||
stopRegister chan struct{}
|
||||
stopRegister func()
|
||||
stopPing chan struct{}
|
||||
olmToken string
|
||||
gerbilServerPubKey string
|
||||
@@ -378,35 +378,6 @@ func keepSendingUDPHolePunch(endpoint string, olmID string, sourcePort uint16) {
|
||||
}
|
||||
}
|
||||
|
||||
func sendRegistration(olm *websocket.Client, publicKey string) error {
|
||||
err := olm.SendMessage("olm/wg/register", map[string]interface{}{
|
||||
"publicKey": publicKey,
|
||||
})
|
||||
if err != nil {
|
||||
logger.Error("Failed to send registration message: %v", err)
|
||||
return err
|
||||
}
|
||||
logger.Info("Sent registration message")
|
||||
return nil
|
||||
}
|
||||
|
||||
func keepSendingRegistration(olm *websocket.Client, publicKey string) {
|
||||
ticker := time.NewTicker(1 * time.Second)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-stopRegister:
|
||||
logger.Info("Stopping registration messages")
|
||||
return
|
||||
case <-ticker.C:
|
||||
if err := sendRegistration(olm, publicKey); err != nil {
|
||||
logger.Error("Failed to send periodic registration: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func FindAvailableUDPPort(minPort, maxPort uint16) (uint16, error) {
|
||||
if maxPort < minPort {
|
||||
return 0, fmt.Errorf("invalid port range: min=%d, max=%d", minPort, maxPort)
|
||||
|
||||
Reference in New Issue
Block a user