Holepunch but relay by default

This commit is contained in:
Owen
2025-07-24 14:44:12 -07:00
parent 2a832420df
commit 5302f9da34
4 changed files with 51 additions and 64 deletions

View File

@@ -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)