Gossip response or something from gossip store */
| 696 | |
| 697 | /* Gossip response or something from gossip store */ |
| 698 | static const u8 *maybe_gossip_msg(const tal_t *ctx, struct peer *peer) |
| 699 | { |
| 700 | const u8 *msg; |
| 701 | struct timemono query_start; |
| 702 | struct gossmap *gossmap; |
| 703 | u32 timestamp; |
| 704 | const u8 **msgs; |
| 705 | u64 cpu_budget, wait_usec; |
| 706 | bool answering; |
| 707 | |
| 708 | maybe_reset_usage_window(peer); |
| 709 | |
| 710 | cpu_budget = peer_cpu_budget(peer); |
| 711 | |
| 712 | wait_usec = maybe_throttle_usec(peer, &peer->gs.throttle_warned, "outgoing", |
| 713 | peer->gs.bytes_this_second, peer->daemon->gossip_stream_limit, |
| 714 | peer->gs.cpu_usec_this_second, cpu_budget); |
| 715 | if (wait_usec) { |
| 716 | /* Replace normal timer with a timer after throttle. */ |
| 717 | peer->gs.active = false; |
| 718 | tal_free(peer->gs.gossip_timer); |
| 719 | peer->gs.gossip_timer |
| 720 | = new_abstimer(&peer->daemon->timers, |
| 721 | peer, |
| 722 | timemono_add(time_mono(), time_from_usec(wait_usec)), |
| 723 | wake_gossip, peer); |
| 724 | return NULL; |
| 725 | } |
| 726 | |
| 727 | gossmap = get_gossmap(peer->daemon); |
| 728 | |
| 729 | /* This can return more than one: it's the expensive part (gossmap |
| 730 | * walks, checksum/timestamp lookups), so it's what we charge for |
| 731 | * cpu_usec_this_second above. But only while we're answering a |
| 732 | * query: we're called every time the output queue drains, and the |
| 733 | * rest of the time it's a no-op. */ |
| 734 | answering = peer->scid_queries || peer->range_scids; |
| 735 | query_start = time_mono(); |
| 736 | msgs = maybe_create_query_responses(tmpctx, peer, gossmap); |
| 737 | if (answering) |
| 738 | peer->gs.cpu_usec_this_second |
| 739 | += time_to_usec(timemono_between(time_mono(), |
| 740 | query_start)); |
| 741 | if (tal_count(msgs) > 0) { |
| 742 | /* We return the first one for immediate sending, and queue |
| 743 | * others for future. We add all the lengths now though! */ |
| 744 | for (size_t i = 0; i < tal_count(msgs); i++) { |
| 745 | peer->gs.bytes_this_second += tal_bytelen(msgs[i]); |
| 746 | status_peer_io(LOG_IO_OUT, &peer->id, msgs[i]); |
| 747 | if (i > 0) |
| 748 | msg_to_peer_outq(peer, take(msgs[i])); |
| 749 | } |
| 750 | return msgs[0]; |
| 751 | } |
| 752 | |
| 753 | /* dev-mode can suppress all gossip */ |
| 754 | if (peer->daemon->dev_suppress_gossip) |
| 755 | return NULL; |
no test coverage detected