watchtower/wtclient: filter non-target towers from candidates
This commit is contained in:
2 files changed
+27
-1
No files matched your search
@@ -151,6 +151,7 @@ type TowerClient struct {
|
||||
negotiator SessionNegotiator
|
||||
candidateSessions map[wtdb.SessionID]*wtdb.ClientSession
|
||||
activeSessions sessionQueueSet
|
||||
targetTowerIDs map[wtdb.TowerID]struct{}
|
||||
|
||||
sessionQueue *sessionQueue
|
||||
prevTask *backupTask
|
||||
@@ -198,10 +199,14 @@ func New(config *Config) (*TowerClient, error) {
|
||||
log.Infof("Using private watchtower %s, offering policy %s",
|
||||
cfg.PrivateTower, cfg.Policy)
|
||||
|
||||
candidates := newTowerListIterator(tower)
|
||||
targetTowerIDs := candidates.TowerIDs()
|
||||
|
||||
c := &TowerClient{
|
||||
cfg: cfg,
|
||||
pipeline: newTaskPipeline(),
|
||||
activeSessions: make(sessionQueueSet),
|
||||
targetTowerIDs: targetTowerIDs,
|
||||
statTicker: time.NewTicker(DefaultStatInterval),
|
||||
forceQuit: make(chan struct{}),
|
||||
}
|
||||
@@ -213,7 +218,7 @@ func New(config *Config) (*TowerClient, error) {
|
||||
SendMessage: c.sendMessage,
|
||||
ReadMessage: c.readMessage,
|
||||
Dial: c.dial,
|
||||
Candidates: newTowerListIterator(tower),
|
||||
Candidates: candidates,
|
||||
MinBackoff: cfg.MinBackoff,
|
||||
MaxBackoff: cfg.MaxBackoff,
|
||||
})
|
||||
@@ -526,6 +531,12 @@ func (c *TowerClient) nextSessionQueue() *sessionQueue {
|
||||
continue
|
||||
}
|
||||
|
||||
// Skip any sessions that are still active, but are not for the
|
||||
// users currently configured tower.
|
||||
if _, ok := c.targetTowerIDs[sessionInfo.TowerID]; !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
candidateSession = sessionInfo
|
||||
break
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user