MCPcopy Create free account
hub / github.com/ElementsProject/lightning / try_connect

Function try_connect

lightningd/connect_control.c:281–324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

279}
280
281static void try_connect(const tal_t *ctx,
282 struct lightningd *ld,
283 const struct node_id *id,
284 u32 seconds_delay,
285 const struct wireaddr_internal *addrhint)
286{
287 struct delayed_reconnect *d;
288 struct peer *peer;
289
290 d = tal(ctx, struct delayed_reconnect);
291 d->ld = ld;
292 d->id = *id;
293 d->addrhint = tal_dup_or_null(d, struct wireaddr_internal, addrhint);
294
295 if (!seconds_delay) {
296 do_connect(d);
297 return;
298 }
299
300 log_peer_debug(ld->log, id, "Will try reconnect in %u seconds",
301 seconds_delay);
302 /* Update any channel billboards */
303 peer = peer_by_id(ld, id);
304 if (peer) {
305 struct channel *channel;
306 list_for_each(&peer->channels, channel, list) {
307 if (!channel_active(channel))
308 continue;
309 channel_set_billboard(channel, false,
310 tal_fmt(tmpctx,
311 "Will attempt reconnect "
312 "in %u seconds",
313 seconds_delay));
314 }
315 peer->last_connect_attempt = time_now();
316 }
317
318 /* We fuzz the timer by up to 1 second, to avoid getting into
319 * simultanous-reconnect deadlocks with peer. */
320 notleak(new_reltimer(ld->timers, d,
321 timerel_add(time_from_sec(seconds_delay),
322 time_from_usec(pseudorand(1000000))),
323 do_connect, d));
324}
325
326/*~ In C convention, constants are UPPERCASE macros. Not everything needs to
327 * be a constant, but it soothes the programmer's conscience to encapsulate

Callers 2

json_connectFunction · 0.85
try_reconnectFunction · 0.85

Calls 9

peer_by_idFunction · 0.85
channel_activeFunction · 0.85
channel_set_billboardFunction · 0.85
time_nowFunction · 0.85
timerel_addFunction · 0.85
time_from_secFunction · 0.85
time_from_usecFunction · 0.85
do_connectFunction · 0.70
pseudorandFunction · 0.50

Tested by

no test coverage detected