// Add adds new node and returns it, it replaces existing without notification. func (s *nodeStore) Add(n *api.Node, expireFunc func()) *registeredNode { s.mu.Lock() defer s.mu.Unlock() var attempts int var registered time.Time if existRn, ok := s.nodes[n.ID]; ok { attempts = existRn.Attempts registered = existRn.Registered existRn.Heartbeat.Stop() delete(s.nodes, n.ID) } if registered.IsZero() { registered = time.Now() } rn := ®isteredNode{ SessionID: identity.NewID(), // session ID is local to the dispatcher. Node: n, Registered: registered, Attempts: attempts, Disconnect: make(chan struct{}), } s.nodes[n.ID] = rn rn.Heartbeat = heartbeat.New(s.periodChooser.Choose()*s.gracePeriodMultiplierNormal, expireFunc) return rn }
func (s *nodeStore) AddUnknown(n *api.Node, expireFunc func()) error { s.mu.Lock() defer s.mu.Unlock() rn := ®isteredNode{ Node: n, } s.nodes[n.ID] = rn rn.Heartbeat = heartbeat.New(s.periodChooser.Choose()*s.gracePeriodMultiplierUnknown, expireFunc) return nil }
// Add adds new node and returns it, it replaces existing without notification. func (s *nodeStore) Add(n *api.Node, expireFunc func()) *registeredNode { s.mu.Lock() defer s.mu.Unlock() if existRn, ok := s.nodes[n.ID]; ok { existRn.Heartbeat.Stop() delete(s.nodes, n.ID) } rn := ®isteredNode{ SessionID: identity.NewID(), // session ID is local to the dispatcher. Node: n, Disconnect: make(chan struct{}), } s.nodes[n.ID] = rn rn.Heartbeat = heartbeat.New(s.periodChooser.Choose()*s.gracePeriodMultiplier, expireFunc) return rn }