Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/boothd.8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ See below for details about booth specific environment variables
and the distributed 'service-runnable' script.


*'exclude_site'*::
The specified 'site' doesn't grant this ticket.


A more verbose example of a configuration file might be

-----------------------
Expand Down
64 changes: 64 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,31 @@ static int ticket_realloc(void)
}


static int exclude_site_realloc(struct ticket_config *tk)
{
const int added = 2;
int had, want;
void *p;

had = tk->exclude_site_allocated;
want = had + added;

p = realloc(tk->exclude_site,
sizeof(struct exclude_site_config) * want);
if (!p) {
log_error("can't alloc more exclude sites");
return -ENOMEM;
}

tk->exclude_site = p;
memset(tk->exclude_site + had, 0,
sizeof(struct exclude_site_config) * added);
tk->exclude_site_allocated = want;

return 0;
}


int add_site(char *address, int type);
int add_site(char *addr_string, int type)
{
Expand Down Expand Up @@ -289,6 +314,30 @@ static int parse_weights(const char *input, int weights[MAX_NODES])
}


static int set_exclude_siteid(void)
{
int i, j, k;
struct ticket_config *t;
struct exclude_site_config *e;
struct booth_site *s;

for (i = 0; i < booth_conf->ticket_count; i++) {
t = &booth_conf->ticket[i];
for (j = 0; j < t->exclude_site_count; j++) {
e = &t->exclude_site[j];
for (k = 0; k < booth_conf->site_count; k++) {
s = &booth_conf->site[k];
if (strcmp(e->addr, s->addr_string) == 0) {
e->id = s->site_id;
break;
}
}
}
}
return 0;
}


int read_config(const char *path, int type)
{
char line[1024];
Expand Down Expand Up @@ -580,6 +629,18 @@ int read_config(const char *path, int type)
continue;
}

if (strcmp(key, "exclude_site") == 0 && last_ticket) {
i = last_ticket->exclude_site_count;
if (i == last_ticket->exclude_site_allocated) {
if (exclude_site_realloc(last_ticket) < 0)
goto out;
}
last_ticket->exclude_site[i].id = -1;
strcpy(last_ticket->exclude_site[i].addr, val);
last_ticket->exclude_site_count++;
continue;
}


error = "Unknown item";
goto out;
Expand All @@ -605,6 +666,9 @@ int read_config(const char *path, int type)
strcpy(booth_conf->name, "booth");
}

if (set_exclude_siteid() < 0)
goto out;

return 0;


Expand Down
14 changes: 14 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
#define TICKET_ALLOC 16


struct exclude_site_config {
/** site ID (maps site_id of struct booth_site). */
int id;

/** IP address of site. */
char addr[BOOTH_NAME_LEN];
};


struct ticket_config {
/** \name Configuration items.
Expand Down Expand Up @@ -180,6 +188,12 @@ struct ticket_config {
* Starts at 0, counts up. */
int retry_number;
/** @} */

int exclude_site_count;
int exclude_site_allocated;

/** Sites which don't grant this ticket. */
struct exclude_site_config *exclude_site;
};


Expand Down
10 changes: 10 additions & 0 deletions src/raft.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,17 @@ int new_election(struct ticket_config *tk,
{
struct booth_site *new_leader;
time_t now;
int i;


for (i = 0; i < tk->exclude_site_count; i++) {
if (local->site_id == tk->exclude_site[i].id) {
tk_log_info("cannot grant here because it's "
"an excepted ticket on the own site");
ticket_next_cron_in(tk, 3600);
return 0;
}
}

time(&now);
tk_log_debug("start new election?, now=%" PRIi64 ", end %" PRIi64,
Expand Down