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

Function spam_new_peer

connectd/multiplex.c:234–279  ·  view source on GitHub ↗

BOLT #7: * A node: * - MUST NOT relay any gossip messages it did not generate itself, * unless explicitly requested. */ i.e. the strong implication is that we spam our own gossip aggressively! * "Look at me!" "Look at me!!!!". */

Source from the content-addressed store, hash-verified

232 * "Look at me!" "Look at me!!!!".
233 */
234static void spam_new_peer(struct peer *peer, struct gossmap *gossmap)
235{
236 struct gossmap_node *me;
237 const u8 *msg;
238 u64 send_threshold;
239
240 /* Find ourselves; if no channels, nothing to send */
241 me = gossmap_find_node(gossmap, &peer->daemon->id);
242 if (!me)
243 return;
244
245 send_threshold = -1ULL;
246
247 /* Just in case we have many peers and not all are connecting or
248 * some other corner case, send everything to first few. */
249 if (peer_htable_count(peer->daemon->peers) > GOSSIP_SPAM_REDUNDANCY
250 && me->num_chans > GOSSIP_SPAM_REDUNDANCY) {
251 send_threshold = -1ULL / me->num_chans * GOSSIP_SPAM_REDUNDANCY;
252 }
253
254 for (size_t i = 0; i < me->num_chans; i++) {
255 struct gossmap_chan *chan = gossmap_nth_chan(gossmap, me, i, NULL);
256
257 /* We set this so we'll send a fraction of all our channels */
258 if (pseudorand_u64() > send_threshold)
259 continue;
260
261 /* Send channel_announce */
262 msg = gossmap_chan_get_announce(NULL, gossmap, chan);
263 inject_peer_msg(peer, take(msg));
264
265 /* Send both channel_updates (if they exist): both help people
266 * use our channel, so we care! */
267 for (int dir = 0; dir < 2; dir++) {
268 if (!gossmap_chan_set(chan, dir))
269 continue;
270 msg = gossmap_chan_get_update(NULL, gossmap, chan, dir);
271 inject_peer_msg(peer, take(msg));
272 }
273 }
274
275 /* If we have one, we should send our own node_announcement */
276 msg = gossmap_node_get_announce(NULL, gossmap, me);
277 if (msg)
278 inject_peer_msg(peer, take(msg));
279}
280
281void setup_peer_gossip_store(struct peer *peer,
282 const struct feature_set *our_features,

Callers 1

setup_peer_gossip_storeFunction · 0.85

Calls 7

gossmap_find_nodeFunction · 0.85
gossmap_nth_chanFunction · 0.85
gossmap_chan_setFunction · 0.85
gossmap_chan_get_updateFunction · 0.85
inject_peer_msgFunction · 0.70

Tested by

no test coverage detected