Skip to content

Commit

Permalink
irc: get much less chatty.
Browse files Browse the repository at this point in the history
We're going to wean off IRC, but as a quick fix, only announce 0-60 seconds
after we see a join, or every 6 hours.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Oct 21, 2016
1 parent 6da448b commit 144c40a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
23 changes: 21 additions & 2 deletions daemon/irc_announce.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,18 @@ static void announce(struct ircstate *state)
}
tal_free(ctx);

new_reltimer(state->dstate, state, time_from_sec(60), announce, state);
/* By default we announce every 6 hours, otherwise when someone joins */
log_debug(state->log, "Setting long announce time: 6 hours");
state->dstate->announce = new_reltimer(state->dstate, state,
time_from_sec(3600 * 6),
announce, state);
}

/* Reconnect to IRC server upon disconnection. */
static void handle_irc_disconnect(struct ircstate *state)
{
/* Stop announcing. */
state->dstate->announce = tal_free(state->dstate->announce);
new_reltimer(state->dstate, state, state->reconnect_timeout, irc_connect, state);
}

Expand Down Expand Up @@ -221,6 +227,19 @@ static void handle_irc_command(struct ircstate *istate, const struct irccommand
// Add our node to the node_map for completeness
add_node(istate->dstate, &dstate->id,
dstate->external_ip, dstate->portnum);
} else if (streq(cmd->command, "JOIN")) {
unsigned int delay;

/* Throw away any existing announce timer, and announce within
* 60 seconds. */
dstate->announce = tal_free(dstate->announce);

delay = pseudorand(60000000);
log_debug(istate->log, "Setting new announce time %u sec",
delay / 1000000);
dstate->announce = new_reltimer(dstate, istate,
time_from_usec(delay),
announce, istate);
}
}

Expand Down Expand Up @@ -251,6 +270,6 @@ void setup_irc_connection(struct lightningd_state *dstate)
"N%.12s",
pubkey_to_hexstr(state, dstate->secpctx, &dstate->id) + 1);

/* We will see our own JOIN message, which will trigger announce */
irc_connect(state);
announce(state);
}
2 changes: 2 additions & 0 deletions daemon/lightningd.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ static struct lightningd_state *lightningd_state(void)
dstate->bitcoin_req_running = false;
dstate->nodes = empty_node_map(dstate);
dstate->reexec = NULL;
dstate->external_ip = NULL;
dstate->announce = NULL;
return dstate;
}

Expand Down
3 changes: 3 additions & 0 deletions daemon/lightningd.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,8 @@ struct lightningd_state {

/* IP/hostname to be announced for incoming connections */
char *external_ip;

/* Announce timer. */
struct oneshot *announce;
};
#endif /* LIGHTNING_DAEMON_LIGHTNING_H */

0 comments on commit 144c40a

Please sign in to comment.