Make chainId in relay message bckwd compat

This commit is contained in:
Owen
2026-03-06 15:27:03 -08:00
parent c67c2a60a1
commit 809dbe77de
2 changed files with 31 additions and 24 deletions

View File

@@ -51,7 +51,6 @@ func (o *Olm) handleWgPeerAdd(msg websocket.WSMessage) {
return return
} }
logger.Info("Successfully added peer for site %d", siteConfigMsg.SiteId) logger.Info("Successfully added peer for site %d", siteConfigMsg.SiteId)
} }
@@ -181,10 +180,8 @@ func (o *Olm) handleWgPeerRelay(msg websocket.WSMessage) {
return return
} }
if relayData.ChainId != "" { if monitor := o.peerManager.GetPeerMonitor(); monitor != nil {
if monitor := o.peerManager.GetPeerMonitor(); monitor != nil { monitor.CancelRelaySend(relayData.ChainId)
monitor.CancelRelaySend(relayData.ChainId)
}
} }
primaryRelay, err := util.ResolveDomain(relayData.RelayEndpoint) primaryRelay, err := util.ResolveDomain(relayData.RelayEndpoint)
@@ -223,10 +220,8 @@ func (o *Olm) handleWgPeerUnrelay(msg websocket.WSMessage) {
return return
} }
if relayData.ChainId != "" { if monitor := o.peerManager.GetPeerMonitor(); monitor != nil {
if monitor := o.peerManager.GetPeerMonitor(); monitor != nil { monitor.CancelRelaySend(relayData.ChainId)
monitor.CancelRelaySend(relayData.ChainId)
}
} }
primaryRelay, err := util.ResolveDomain(relayData.Endpoint) primaryRelay, err := util.ResolveDomain(relayData.Endpoint)
@@ -256,8 +251,8 @@ func (o *Olm) handleWgPeerHolepunchAddSite(msg websocket.WSMessage) {
} }
var handshakeData struct { var handshakeData struct {
SiteId int `json:"siteId"` SiteId int `json:"siteId"`
ChainId string `json:"chainId"` ChainId string `json:"chainId"`
ExitNode struct { ExitNode struct {
PublicKey string `json:"publicKey"` PublicKey string `json:"publicKey"`
Endpoint string `json:"endpoint"` Endpoint string `json:"endpoint"`

View File

@@ -33,13 +33,13 @@ type PeerMonitor struct {
monitors map[int]*Client monitors map[int]*Client
mutex sync.Mutex mutex sync.Mutex
running bool running bool
timeout time.Duration timeout time.Duration
maxAttempts int maxAttempts int
wsClient *websocket.Client wsClient *websocket.Client
// Relay sender tracking // Relay sender tracking
relaySends map[string]func() relaySends map[string]func()
relaySendMu sync.Mutex relaySendMu sync.Mutex
// Netstack fields // Netstack fields
middleDev *middleDevice.MiddleDevice middleDev *middleDevice.MiddleDevice
@@ -53,13 +53,13 @@ type PeerMonitor struct {
nsWg sync.WaitGroup nsWg sync.WaitGroup
// Holepunch testing fields // Holepunch testing fields
sharedBind *bind.SharedBind sharedBind *bind.SharedBind
holepunchTester *holepunch.HolepunchTester holepunchTester *holepunch.HolepunchTester
holepunchTimeout time.Duration holepunchTimeout time.Duration
holepunchEndpoints map[int]string // siteID -> endpoint for holepunch testing holepunchEndpoints map[int]string // siteID -> endpoint for holepunch testing
holepunchStatus map[int]bool // siteID -> connected status holepunchStatus map[int]bool // siteID -> connected status
holepunchStopChan chan struct{} holepunchStopChan chan struct{}
holepunchUpdateChan chan struct{} holepunchUpdateChan chan struct{}
// Relay tracking fields // Relay tracking fields
relayedPeers map[int]bool // siteID -> whether the peer is currently relayed relayedPeers map[int]bool // siteID -> whether the peer is currently relayed
@@ -456,10 +456,22 @@ func (pm *PeerMonitor) sendUnRelay(siteID int) error {
} }
// CancelRelaySend stops the interval sender for the given chainId, if one exists. // CancelRelaySend stops the interval sender for the given chainId, if one exists.
// If chainId is empty, all active relay senders are stopped.
func (pm *PeerMonitor) CancelRelaySend(chainId string) { func (pm *PeerMonitor) CancelRelaySend(chainId string) {
pm.relaySendMu.Lock() pm.relaySendMu.Lock()
defer pm.relaySendMu.Unlock() defer pm.relaySendMu.Unlock()
if chainId == "" {
for id, stop := range pm.relaySends {
if stop != nil {
stop()
}
delete(pm.relaySends, id)
}
logger.Info("Cancelled all relay senders")
return
}
if stop, ok := pm.relaySends[chainId]; ok { if stop, ok := pm.relaySends[chainId]; ok {
stop() stop()
delete(pm.relaySends, chainId) delete(pm.relaySends, chainId)