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

hostpool improvements

parent 9ec2d7b0
No related branches found
No related tags found
No related merge requests found
...@@ -446,7 +446,7 @@ func (c *Client) StopNetworkFollower(timeout time.Duration) error { ...@@ -446,7 +446,7 @@ func (c *Client) StopNetworkFollower(timeout time.Duration) error {
return nil return nil
} }
// Gets the state of the network follower. Returns: // NetworkFollowerStatus Gets the state of the network follower. Returns:
// Stopped - 0 // Stopped - 0
// Starting - 1000 // Starting - 1000
// Running - 2000 // Running - 2000
......
...@@ -78,7 +78,7 @@ var rootCmd = &cobra.Command{ ...@@ -78,7 +78,7 @@ var rootCmd = &cobra.Command{
jww.INFO.Printf("Message ListenerID: %v", listenerID) jww.INFO.Printf("Message ListenerID: %v", listenerID)
// Set up auth request handler, which simply prints the // Set up auth request handler, which simply prints the
// user id of the requestor. // user id of the requester.
authMgr := client.GetAuthRegistrar() authMgr := client.GetAuthRegistrar()
authMgr.AddGeneralRequestCallback(printChanRequest) authMgr.AddGeneralRequestCallback(printChanRequest)
......
...@@ -116,7 +116,8 @@ func (h *HostPool) getAny(length uint32, excluded []*id.ID) []*connect.Host { ...@@ -116,7 +116,8 @@ func (h *HostPool) getAny(length uint32, excluded []*id.ID) []*connect.Host {
length = h.poolParams.PoolSize length = h.poolParams.PoolSize
} }
if excluded != nil { if excluded != nil {
for _, gwId := range excluded { for i := range excluded {
gwId := excluded[i]
if idx, ok := h.hostMap[*gwId]; ok { if idx, ok := h.hostMap[*gwId]; ok {
checked[idx] = nil checked[idx] = nil
} }
...@@ -314,7 +315,7 @@ func (h *HostPool) updateConns() error { ...@@ -314,7 +315,7 @@ func (h *HostPool) updateConns() error {
for gwId := range h.ndfMap { for gwId := range h.ndfMap {
if _, ok := newMap[gwId]; !ok { if _, ok := newMap[gwId]; !ok {
// If GwId in ndfMap is not in newMap, remove the Gateway // If GwId in ndfMap is not in newMap, remove the Gateway
h.removeGateway(&gwId) h.removeGateway(gwId.DeepCopy())
} }
} }
...@@ -322,7 +323,7 @@ func (h *HostPool) updateConns() error { ...@@ -322,7 +323,7 @@ func (h *HostPool) updateConns() error {
for gwId, ndfIdx := range newMap { for gwId, ndfIdx := range newMap {
if _, ok := h.ndfMap[gwId]; !ok { if _, ok := h.ndfMap[gwId]; !ok {
// If GwId in newMap is not in ndfMap, add the Gateway // If GwId in newMap is not in ndfMap, add the Gateway
h.addGateway(&gwId, ndfIdx) h.addGateway(gwId.DeepCopy(), ndfIdx)
} }
} }
...@@ -339,7 +340,8 @@ func convertNdfToMap(ndf *ndf.NetworkDefinition) (map[id.ID]int, error) { ...@@ -339,7 +340,8 @@ func convertNdfToMap(ndf *ndf.NetworkDefinition) (map[id.ID]int, error) {
} }
// Process gateway Id's into set // Process gateway Id's into set
for i, gw := range ndf.Gateways { for i := range ndf.Gateways {
gw := ndf.Gateways[i]
gwId, err := id.Unmarshal(gw.ID) gwId, err := id.Unmarshal(gw.ID)
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -10,6 +10,7 @@ package gateway ...@@ -10,6 +10,7 @@ package gateway
import ( import (
"github.com/pkg/errors" "github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/storage"
"gitlab.com/elixxir/comms/network" "gitlab.com/elixxir/comms/network"
"gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/comms/connect"
...@@ -40,31 +41,44 @@ func (m *Sender) SendToSpecific(target *id.ID, ...@@ -40,31 +41,44 @@ func (m *Sender) SendToSpecific(target *id.ID,
sendFunc func(host *connect.Host, target *id.ID) (interface{}, error)) (interface{}, error) { sendFunc func(host *connect.Host, target *id.ID) (interface{}, error)) (interface{}, error) {
host, ok := m.getSpecific(target) host, ok := m.getSpecific(target)
if ok { if ok {
jww.WARN.Printf("SendToSpecific %s", host.GetId().String())
result, err := sendFunc(host, target) result, err := sendFunc(host, target)
if err == nil { if err == nil {
return result, m.forceAdd([]*id.ID{host.GetId()}) return result, m.forceAdd([]*id.ID{host.GetId()})
} else {
jww.WARN.Printf("Unable to SendToSpecific %s: %+v", host.GetId().String(), err)
} }
} }
proxies := m.getAny(m.poolParams.ProxyAttempts, []*id.ID{target}) proxies := m.getAny(m.poolParams.ProxyAttempts, []*id.ID{target})
for proxyIdx := 0; proxyIdx < len(proxies); proxyIdx++ { for proxyIdx := 0; proxyIdx < len(proxies); proxyIdx++ {
jww.WARN.Printf("SendToSpecific proxy %s", proxies[proxyIdx].GetId().String())
result, err := sendFunc(proxies[proxyIdx], target) result, err := sendFunc(proxies[proxyIdx], target)
if err == nil { if err == nil {
return result, nil return result, nil
} else {
jww.WARN.Printf("Unable to SendToSpecific proxy %s: %+v", proxies[proxyIdx].GetId().String(), err)
} }
} }
return nil, errors.Errorf("Unable to send to any specifics with proxies") return nil, errors.Errorf("Unable to send to specific with proxies")
} }
// SendToAny Call given sendFunc to any Host in the HostPool, attempting with up to numProxies destinations // SendToAny Call given sendFunc to any Host in the HostPool, attempting with up to numProxies destinations
func (m *Sender) SendToAny(sendFunc func(host *connect.Host) (interface{}, error)) (interface{}, error) { func (m *Sender) SendToAny(sendFunc func(host *connect.Host) (interface{}, error)) (interface{}, error) {
proxies := m.getAny(m.poolParams.ProxyAttempts, nil) proxies := m.getAny(m.poolParams.ProxyAttempts, nil)
for _, proxy := range proxies { for i := range proxies {
jww.WARN.Printf("Sender %d %s", i, proxies[i].GetId().String())
}
for i := range proxies {
proxy := proxies[i]
jww.WARN.Printf("SendToAny %s", proxy.GetId().String())
result, err := sendFunc(proxy) result, err := sendFunc(proxy)
if err == nil { if err == nil {
return result, nil return result, nil
} else {
jww.WARN.Printf("Unable to SendToAny %s: %+v", proxy.GetId().String(), err)
} }
} }
...@@ -76,17 +90,23 @@ func (m *Sender) SendToPreferred(targets []*id.ID, ...@@ -76,17 +90,23 @@ func (m *Sender) SendToPreferred(targets []*id.ID,
sendFunc func(host *connect.Host, target *id.ID) (interface{}, error)) (interface{}, error) { sendFunc func(host *connect.Host, target *id.ID) (interface{}, error)) (interface{}, error) {
targetHosts := m.getPreferred(targets) targetHosts := m.getPreferred(targets)
for i, host := range targetHosts { for i, host := range targetHosts {
jww.WARN.Printf("SendToPreferred %s", host.GetId().String())
result, err := sendFunc(host, targets[i]) result, err := sendFunc(host, targets[i])
if err == nil { if err == nil {
return result, nil return result, nil
} else {
jww.WARN.Printf("Unable to SendToPreferred %s: %+v", host.GetId().String(), err)
} }
} }
proxies := m.getAny(m.poolParams.ProxyAttempts, targets) proxies := m.getAny(m.poolParams.ProxyAttempts, targets)
for i, proxy := range proxies { for i, proxy := range proxies {
jww.WARN.Printf("SendToPreferred proxy %s", proxy.GetId().String())
result, err := sendFunc(proxy, targets[i%len(targets)]) result, err := sendFunc(proxy, targets[i%len(targets)])
if err == nil { if err == nil {
return result, nil return result, nil
} else {
jww.WARN.Printf("Unable to SendToPreferred proxy %s: %+v", proxy.GetId().String(), err)
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment