mirror of
https://github.com/fosrl/olm.git
synced 2026-03-07 03:06:44 +00:00
Make chainId in relay message bckwd compat
This commit is contained in:
21
olm/peer.go
21
olm/peer.go
@@ -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"`
|
||||||
@@ -269,7 +264,7 @@ func (o *Olm) handleWgPeerHolepunchAddSite(msg websocket.WSMessage) {
|
|||||||
logger.Error("Error unmarshaling handshake data: %v", err)
|
logger.Error("Error unmarshaling handshake data: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop the peer init sender for this chain, if any
|
// Stop the peer init sender for this chain, if any
|
||||||
if handshakeData.ChainId != "" {
|
if handshakeData.ChainId != "" {
|
||||||
o.peerSendMu.Lock()
|
o.peerSendMu.Lock()
|
||||||
@@ -278,7 +273,7 @@ func (o *Olm) handleWgPeerHolepunchAddSite(msg websocket.WSMessage) {
|
|||||||
delete(o.stopPeerInits, handshakeData.ChainId)
|
delete(o.stopPeerInits, handshakeData.ChainId)
|
||||||
}
|
}
|
||||||
o.peerSendMu.Unlock()
|
o.peerSendMu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get existing peer from PeerManager
|
// Get existing peer from PeerManager
|
||||||
_, exists := o.peerManager.GetPeer(handshakeData.SiteId)
|
_, exists := o.peerManager.GetPeer(handshakeData.SiteId)
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -567,7 +579,7 @@ func (pm *PeerMonitor) runHolepunchMonitor() {
|
|||||||
pm.holepunchCurrentInterval = pm.holepunchMinInterval
|
pm.holepunchCurrentInterval = pm.holepunchMinInterval
|
||||||
currentInterval := pm.holepunchCurrentInterval
|
currentInterval := pm.holepunchCurrentInterval
|
||||||
pm.mutex.Unlock()
|
pm.mutex.Unlock()
|
||||||
|
|
||||||
timer.Reset(currentInterval)
|
timer.Reset(currentInterval)
|
||||||
logger.Debug("Holepunch monitor interval updated, reset to %v", currentInterval)
|
logger.Debug("Holepunch monitor interval updated, reset to %v", currentInterval)
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
|
|||||||
Reference in New Issue
Block a user