entities.go 633 B

123456789101112131415161718192021222324252627282930313233343536
  1. package cluster
  2. import (
  3. "fmt"
  4. "time"
  5. )
  6. type address struct {
  7. Ip string `json:"ip"`
  8. Port uint16 `json:"port"`
  9. Votes []vote `json:"vote"`
  10. }
  11. func (a *address) fullAddress() string {
  12. return fmt.Sprintf("%s:%d", a.Ip, a.Port)
  13. }
  14. type vote struct {
  15. NodeID string `json:"node_id"`
  16. VotedAt int64 `json:"voted_at"`
  17. Failed bool `json:"failed"`
  18. }
  19. type node struct {
  20. Addresses []address `json:"ips"`
  21. LastPingAt int64 `json:"last_ping_at"`
  22. }
  23. func (c *node) available() bool {
  24. return time.Since(time.Unix(c.LastPingAt, 0)) < NODE_DISCONNECTED_TIMEOUT
  25. }
  26. type newNodeEvent struct {
  27. NodeID string `json:"node_id"`
  28. }