// fetch, if succeeded updates or sets current server
// to the last received server
fetch, if succeeded updates or sets current server
to the last received server
// fetch if succeeded updates or sets current server // to the last received server
func (h *Heartbeat) fetch() error {
	server, err := h.GetServerInfo()
	if err != nil {
		h.reset(HeartbeatStateInit)
		return trace.Wrap(err)
	}
	switch h.state {
	case HeartbeatStateInit:
		h.current = server
		h.reset(HeartbeatStateAnnounce)
		return nil
	case HeartbeatStateAnnounce:
		return nil
	case HeartbeatStateAnnounceWait:
		if h.Clock.Now().UTC().After(h.nextAnnounce) {
			h.current = server
			h.reset(HeartbeatStateAnnounce)
			return nil
		}
		result := services.Compare(h.current, server)
		if result == services.Different {
			h.current = server
			h.reset(HeartbeatStateAnnounce)
		}
		return nil
	case HeartbeatStateKeepAlive:
		return nil
	case HeartbeatStateKeepAliveWait:
		if h.Clock.Now().UTC().After(h.nextKeepAlive) {
			h.setState(HeartbeatStateKeepAlive)
			return nil
		}
		result := services.Compare(h.current, server)
		if result == services.Different {
			h.current = server
			h.reset(HeartbeatStateAnnounce)
		}
		return nil
	default:
		return trace.BadParameter("unsupported state: %v", h.state)
	}
}
func ( h * Heartbeat ) fetch ( ) error { server , err := h . GetServerInfo ( ) if err != nil { h . reset ( HeartbeatStateInit ) return trace . Wrap ( err ) } switch h . state { case HeartbeatStateInit : h . current = server h . reset ( HeartbeatStateAnnounce ) return nil case HeartbeatStateAnnounce : return nil case HeartbeatStateAnnounceWait : if h . Clock . Now ( ) . UTC ( ) . After ( h . nextAnnounce ) { h . current = server h . reset ( HeartbeatStateAnnounce ) return nil } result := services . Compare ( h . current , server ) if result == services . Different { h . current = server h . reset ( HeartbeatStateAnnounce ) } return nil case HeartbeatStateKeepAlive : return nil case HeartbeatStateKeepAliveWait : if h . Clock . Now ( ) . UTC ( ) . After ( h . nextKeepAlive ) { h . setState ( HeartbeatStateKeepAlive ) return nil } result := services . Compare ( h . current , server ) if result == services . Different { h . current = server h . reset ( HeartbeatStateAnnounce ) } return nil default : return trace . BadParameter ( " " , h . state ) } }
fetch, if succeeded updates or sets current server
to the last received server
fetch if succeeded updates or sets current server to the last received server
// failed to fetch server info? // reset to init state regardless of the current state // in case of successful state fetch, move to announce from init // nothing to do in announce state // time to announce // server update happened, time to announce // nothing to do in keep alive state // Stay in keep alive state in case // if there are no changes // time to send a new keep alive // server update happened, move to announce