From 3a75a84fb1b8fe47f1ac9adba3aa497b16da1d7e Mon Sep 17 00:00:00 2001 From: matst80 Date: Tue, 12 Nov 2024 21:40:17 +0100 Subject: [PATCH] tiny cleanup --- synced-pool.go | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/synced-pool.go b/synced-pool.go index 5089167..95f0a5d 100644 --- a/synced-pool.go +++ b/synced-pool.go @@ -351,24 +351,13 @@ func (p *SyncedPool) removeLocalGrain(id CartId) { delete(p.local.grains, id) } -func (p *SyncedPool) addRemoteHost(address string, remote *RemoteHost) error { - known := make([]string, 0, len(p.remotes)+1) - - for _, r := range p.remotes { - known = append(known, r.Host) - if r.Host == address { - log.Printf("Remote %s already exists\n", address) - return fmt.Errorf("remote %s already exists", address) - } - } - known = append([]string{p.Hostname}, known...) +func (p *SyncedPool) addRemoteHost(address string, remote *RemoteHost) { p.remotes = append(p.remotes, remote) connectedRemotes.Set(float64(len(p.remotes))) log.Printf("Added remote %s\n", remote.Host) go remote.Initialize(p) - return nil } func (p *SyncedPool) AddRemote(host string) error { @@ -380,12 +369,6 @@ func (p *SyncedPool) AddRemote(host string) error { log.Printf("Error connecting to remote %s: %v\n", host, err) return err } - _, err = client.Call(Ping, Pong, []byte{}) - - if err != nil { - log.Printf("No response from new remote %s", host) - return err - } remote := RemoteHost{ Client: client, @@ -404,10 +387,10 @@ func (p *SyncedPool) AddRemote(host string) error { for err != nil { time.Sleep(time.Millisecond * 200) err = remote.Ping() - if remote.MissedPings > 3 { + if !remote.IsHealthy() { log.Printf("Removing host, unable to communicate with %s", host) p.RemoveHost(&remote) - return + break } } }