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

Function maybe_gossip_msg

connectd/multiplex.c:622–701  ·  view source on GitHub ↗

Gossip response or something from gossip store */

Source from the content-addressed store, hash-verified

620
621/* Gossip response or something from gossip store */
622static const u8 *maybe_gossip_msg(const tal_t *ctx, struct peer *peer)
623{
624 const u8 *msg;
625 struct timemono now;
626 struct gossmap *gossmap;
627 u32 timestamp;
628 const u8 **msgs;
629
630 /* If it's been over a second, make a fresh start. */
631 now = time_mono();
632 if (time_to_sec(timemono_between(now, peer->gs.bytes_start_time)) > 0) {
633 peer->gs.bytes_start_time = now;
634 peer->gs.bytes_this_second = 0;
635 }
636
637 /* Sent too much this second? */
638 if (peer->gs.bytes_this_second > peer->daemon->gossip_stream_limit) {
639 /* Replace normal timer with a timer after throttle. */
640 peer->gs.active = false;
641 tal_free(peer->gs.gossip_timer);
642 peer->gs.gossip_timer
643 = new_abstimer(&peer->daemon->timers,
644 peer,
645 timemono_add(peer->gs.bytes_start_time,
646 time_from_sec(1)),
647 wake_gossip, peer);
648 return NULL;
649 }
650
651 gossmap = get_gossmap(peer->daemon);
652
653 /* This can return more than one. */
654 msgs = maybe_create_query_responses(tmpctx, peer, gossmap);
655 if (tal_count(msgs) > 0) {
656 /* We return the first one for immediate sending, and queue
657 * others for future. We add all the lengths now though! */
658 for (size_t i = 0; i < tal_count(msgs); i++) {
659 peer->gs.bytes_this_second += tal_bytelen(msgs[i]);
660 status_peer_io(LOG_IO_OUT, &peer->id, msgs[i]);
661 if (i > 0)
662 msg_to_peer_outq(peer, take(msgs[i]));
663 }
664 return msgs[0];
665 }
666
667 /* dev-mode can suppress all gossip */
668 if (peer->daemon->dev_suppress_gossip)
669 return NULL;
670
671 /* Not streaming right now? */
672 if (!peer->gs.active)
673 return NULL;
674
675 /* This should be around to kick us every 60 seconds */
676 assert(peer->gs.gossip_timer);
677
678again:
679 msg = gossmap_stream_next(ctx, gossmap, peer->gs.iter, &timestamp);

Callers 1

next_msg_for_peerFunction · 0.85

Calls 13

time_monoFunction · 0.85
time_to_secFunction · 0.85
timemono_betweenFunction · 0.85
tal_freeFunction · 0.85
timemono_addFunction · 0.85
time_from_secFunction · 0.85
tal_bytelenFunction · 0.85
msg_to_peer_outqFunction · 0.85
gossmap_stream_nextFunction · 0.85
gossip_rcvd_filter_delFunction · 0.85
get_gossmapFunction · 0.70

Tested by

no test coverage detected