1 #ifndef DIRECTOR_HOST_H 2 #define DIRECTOR_HOST_H 3 4 #include "net.h" 5 6 struct director; 7 8 struct director_host { 9 struct director *dir; 10 int refcount; 11 12 struct ip_addr ip; 13 char *ip_str; 14 in_port_t port; 15 16 /* name contains "ip:port" */ 17 char *name; 18 /* change commands each have originating host and originating sequence. 19 we'll keep track of the highest sequence we've seen from the host. 20 if we find a lower sequence, we've already handled the command and 21 it can be ignored (or: it must be ignored to avoid potential command 22 loops) */ 23 unsigned int last_seq; 24 /* use these to avoid infinitely sending SYNCs for directors that 25 aren't connected in the ring. */ 26 unsigned int last_sync_seq, last_sync_seq_counter, last_sync_timestamp; 27 /* whenever we receive a SYNC with stale hosts_hash, set this. if it's 28 already set and equals the current hosts_hash, re-send our hosts to 29 everybody in case they somehow got out of sync. */ 30 unsigned int desynced_hosts_hash; 31 /* Last time host was detected to be down */ 32 time_t last_network_failure; 33 time_t last_protocol_failure; 34 35 /* When we finish getting a right connection, send a SYNC with these 36 parameters (if delayed_sync_seq != 0) */ 37 uint32_t delayed_sync_seq; 38 unsigned int delayed_sync_minor_version; 39 unsigned int delayed_sync_timestamp; 40 unsigned int delayed_sync_hosts_hash; 41 42 /* we are this director */ 43 bool self:1; 44 bool removed:1; 45 }; 46 47 struct director_host * 48 director_host_add(struct director *dir, const struct ip_addr *ip, 49 in_port_t port); 50 void director_host_free(struct director_host **host); 51 52 void director_host_ref(struct director_host *host); 53 void director_host_unref(struct director_host *host); 54 55 void director_host_restarted(struct director_host *host); 56 57 struct director_host * 58 director_host_get(struct director *dir, const struct ip_addr *ip, 59 in_port_t port); 60 struct director_host * 61 director_host_lookup(struct director *dir, const struct ip_addr *ip, 62 in_port_t port); 63 struct director_host * 64 director_host_lookup_ip(struct director *dir, const struct ip_addr *ip); 65 66 /* Returns 0 if b1 equals b2. 67 -1 if b1 is closer to our left side than b2 or 68 -1 if b2 is closer to our right side than b1 69 1 vice versa */ 70 int director_host_cmp_to_self(const struct director_host *b1, 71 const struct director_host *b2, 72 const struct director_host *self); 73 /* Compare directors by IP/port. */ 74 int director_host_cmp_p(struct director_host *const *host1, 75 struct director_host *const *host2); 76 77 /* Parse hosts list (e.g. "host1:port host2 host3:port") and them as 78 directors */ 79 void director_host_add_from_string(struct director *dir, const char *hosts); 80 81 #endif 82