try stuff
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 2m6s

This commit is contained in:
matst80
2024-11-12 08:10:09 +01:00
parent de876ccbda
commit f9c1c309b6

View File

@@ -91,9 +91,11 @@ func (p *SyncedPool) NegotiateHandler(data []byte) (uint32, []byte, error) {
negotiationCount.Inc() negotiationCount.Inc()
log.Printf("Handling negotiation\n") log.Printf("Handling negotiation\n")
for _, host := range p.ExcludeKnown(strings.Split(string(data), ";")) { for _, host := range p.ExcludeKnown(strings.Split(string(data), ";")) {
if !p.IsKnown(host) { if host == "" {
go p.AddRemote(host) continue
} }
go p.AddRemote(host)
} }
return RemoteNegotiateResponse, []byte("ok"), nil return RemoteNegotiateResponse, []byte("ok"), nil
@@ -298,6 +300,7 @@ func (p *SyncedPool) Negotiate(knownHosts []string) ([]string, error) {
allHosts[h] = struct{}{} allHosts[h] = struct{}{}
} }
} }
ret := make([]string, 0, len(allHosts)) ret := make([]string, 0, len(allHosts))
for h := range allHosts { for h := range allHosts {
ret = append(ret, h) ret = append(ret, h)
@@ -355,7 +358,7 @@ func (p *SyncedPool) removeLocalGrain(id CartId) {
} }
func (p *SyncedPool) addRemoteHost(address string, remote *RemoteHost) error { func (p *SyncedPool) addRemoteHost(address string, remote *RemoteHost) error {
known := make([]string, 0, len(p.remotes)) known := make([]string, 0, len(p.remotes)+1)
for _, r := range p.remotes { for _, r := range p.remotes {
known = append(known, r.Host) known = append(known, r.Host)
@@ -364,6 +367,7 @@ func (p *SyncedPool) addRemoteHost(address string, remote *RemoteHost) error {
return fmt.Errorf("remote %s already exists", address) return fmt.Errorf("remote %s already exists", address)
} }
} }
known = append([]string{p.Hostname}, known...)
p.remotes = append(p.remotes, remote) p.remotes = append(p.remotes, remote)
connectedRemotes.Set(float64(len(p.remotes))) connectedRemotes.Set(float64(len(p.remotes)))
@@ -395,7 +399,16 @@ func (p *SyncedPool) addRemoteHost(address string, remote *RemoteHost) error {
} }
log.Printf("Removed %d local grains, added %d remote grains\n", local, remoteNo) log.Printf("Removed %d local grains, added %d remote grains\n", local, remoteNo)
p.mu.Unlock() p.mu.Unlock()
go p.Negotiate(known) go func() {
other, err := p.Negotiate(known)
if err != nil {
log.Printf("Error negotiating with remote %s: %v\n", remote.Host, err)
return
}
for _, o := range p.ExcludeKnown(other) {
p.AddRemote(o)
}
}()
}() }()
return nil return nil
} }