Skip to content
Snippets Groups Projects
Commit f4adc5c0 authored by Jake Taylor's avatar Jake Taylor
Browse files

made forceAdd operate singular

parent c57544aa
No related branches found
No related tags found
No related merge requests found
......@@ -284,33 +284,21 @@ func (h *HostPool) replaceHost(newId *id.ID, oldPoolIndex uint32) error {
}
// Force-add the Gateways to the HostPool, each replacing a random Gateway
func (h *HostPool) forceAdd(gwIds []*id.ID) error {
func (h *HostPool) forceAdd(gwId *id.ID) error {
rng := h.rng.GetStream()
h.hostMux.Lock()
defer h.hostMux.Unlock()
defer rng.Close()
checked := make(map[uint32]interface{}) // Keep track of Hosts already replaced
for i := 0; i < len(gwIds); {
// Verify the GwId is not already in the hostMap
if _, ok := h.hostMap[*gwIds[i]]; ok {
if _, ok := h.hostMap[*gwId]; ok {
// If it is, skip
i++
continue
return nil
}
// Randomly select another Gateway in the HostPool for replacement
poolIdx := readRangeUint32(0, h.poolParams.PoolSize, rng)
if _, ok := checked[poolIdx]; !ok {
err := h.replaceHost(gwIds[i], poolIdx)
if err != nil {
return err
}
checked[poolIdx] = nil
i++
}
}
return nil
return h.replaceHost(gwId, poolIdx)
}
// Updates the internal HostPool with any changes to the NDF
......
......@@ -43,7 +43,7 @@ func (s *Sender) SendToSpecific(target *id.ID,
if ok {
result, didAbort, err := sendFunc(host, target)
if err == nil {
return result, s.forceAdd([]*id.ID{host.GetId()})
return result, s.forceAdd(target)
} else {
if didAbort {
return nil, errors.WithMessagef(err, "Aborted SendToSpecific gateway %s", host.GetId().String())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment