2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#ifndef DIRECTOR_HOST_H
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#define DIRECTOR_HOST_H
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
bdd36cfdba3ff66d25570a9ff568d69e1eb543cfTimo Sirainen#include "net.h"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstruct director;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstruct director_host {
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainen struct director *dir;
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainen int refcount;
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen struct ip_addr ip;
b7650f081ff781c39fe00a3b93375e5f2dd14236Timo Sirainen char *ip_str;
009217abb57a24a4076092e8e4e165545747839eStephan Bosch in_port_t port;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* name contains "ip:port" */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen char *name;
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainen /* change commands each have originating host and originating sequence.
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainen we'll keep track of the highest sequence we've seen from the host.
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainen if we find a lower sequence, we've already handled the command and
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainen it can be ignored (or: it must be ignored to avoid potential command
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainen loops) */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen unsigned int last_seq;
468c28dfb03613ab8d487b5aebc985a969193aceTimo Sirainen /* use these to avoid infinitely sending SYNCs for directors that
468c28dfb03613ab8d487b5aebc985a969193aceTimo Sirainen aren't connected in the ring. */
468c28dfb03613ab8d487b5aebc985a969193aceTimo Sirainen unsigned int last_sync_seq, last_sync_seq_counter, last_sync_timestamp;
abe29107f5dce932d28a00912d2d75a01021bef1Timo Sirainen /* whenever we receive a SYNC with stale hosts_hash, set this. if it's
abe29107f5dce932d28a00912d2d75a01021bef1Timo Sirainen already set and equals the current hosts_hash, re-send our hosts to
abe29107f5dce932d28a00912d2d75a01021bef1Timo Sirainen everybody in case they somehow got out of sync. */
abe29107f5dce932d28a00912d2d75a01021bef1Timo Sirainen unsigned int desynced_hosts_hash;
8c2b4a45f17a5cb13bb01058ca37798cf48d91baTimo Sirainen /* Last time host was detected to be down */
8c2b4a45f17a5cb13bb01058ca37798cf48d91baTimo Sirainen time_t last_network_failure;
8c2b4a45f17a5cb13bb01058ca37798cf48d91baTimo Sirainen time_t last_protocol_failure;
67cb14c7fb54a031818228522dc7255d5cd00f0aTimo Sirainen
67cb14c7fb54a031818228522dc7255d5cd00f0aTimo Sirainen /* When we finish getting a right connection, send a SYNC with these
67cb14c7fb54a031818228522dc7255d5cd00f0aTimo Sirainen parameters (if delayed_sync_seq != 0) */
67cb14c7fb54a031818228522dc7255d5cd00f0aTimo Sirainen uint32_t delayed_sync_seq;
67cb14c7fb54a031818228522dc7255d5cd00f0aTimo Sirainen unsigned int delayed_sync_minor_version;
67cb14c7fb54a031818228522dc7255d5cd00f0aTimo Sirainen unsigned int delayed_sync_timestamp;
67cb14c7fb54a031818228522dc7255d5cd00f0aTimo Sirainen unsigned int delayed_sync_hosts_hash;
67cb14c7fb54a031818228522dc7255d5cd00f0aTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* we are this director */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool self:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool removed:1;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen};
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstruct director_host *
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainendirector_host_add(struct director *dir, const struct ip_addr *ip,
009217abb57a24a4076092e8e4e165545747839eStephan Bosch in_port_t port);
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainenvoid director_host_free(struct director_host **host);
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainen
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainenvoid director_host_ref(struct director_host *host);
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainenvoid director_host_unref(struct director_host *host);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
ce28adabf2c47d3af9ef197787cdb5139424c69cTimo Sirainenvoid director_host_restarted(struct director_host *host);
ce28adabf2c47d3af9ef197787cdb5139424c69cTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstruct director_host *
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainendirector_host_get(struct director *dir, const struct ip_addr *ip,
009217abb57a24a4076092e8e4e165545747839eStephan Bosch in_port_t port);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstruct director_host *
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainendirector_host_lookup(struct director *dir, const struct ip_addr *ip,
009217abb57a24a4076092e8e4e165545747839eStephan Bosch in_port_t port);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstruct director_host *
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainendirector_host_lookup_ip(struct director *dir, const struct ip_addr *ip);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
1055d8038122c4f4190d37d98fdff6791d1306f8Timo Sirainen/* Returns 0 if b1 equals b2.
1055d8038122c4f4190d37d98fdff6791d1306f8Timo Sirainen -1 if b1 is closer to our left side than b2 or
1055d8038122c4f4190d37d98fdff6791d1306f8Timo Sirainen -1 if b2 is closer to our right side than b1
1055d8038122c4f4190d37d98fdff6791d1306f8Timo Sirainen 1 vice versa */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenint director_host_cmp_to_self(const struct director_host *b1,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen const struct director_host *b2,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen const struct director_host *self);
6e54fd2bedbbc0c6316eae8fb569eb9a96aa29abTimo Sirainen/* Compare directors by IP/port. */
6e54fd2bedbbc0c6316eae8fb569eb9a96aa29abTimo Sirainenint director_host_cmp_p(struct director_host *const *host1,
6e54fd2bedbbc0c6316eae8fb569eb9a96aa29abTimo Sirainen struct director_host *const *host2);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen/* Parse hosts list (e.g. "host1:port host2 host3:port") and them as
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen directors */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenvoid director_host_add_from_string(struct director *dir, const char *hosts);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#endif