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

Function peer_connected

connectd/connectd.c:268–363  ·  view source on GitHub ↗

~ Note the lack of static: this is called by peer_exchange_initmsg.c once the * INIT messages are exchanged, and also by the retry code above. */

Source from the content-addressed store, hash-verified

266/*~ Note the lack of static: this is called by peer_exchange_initmsg.c once the
267 * INIT messages are exchanged, and also by the retry code above. */
268struct io_plan *peer_connected(struct io_conn *conn,
269 struct daemon *daemon,
270 const struct node_id *id,
271 const struct wireaddr_internal *addr,
272 const struct wireaddr *remote_addr,
273 struct crypto_state *cs,
274 const u8 *their_features TAKES,
275 bool incoming)
276{
277 u8 *msg;
278 struct peer *peer;
279 int unsup;
280 size_t depender, missing;
281 int subd_fd;
282 bool option_gossip_queries;
283
284 /* We remove any previous connection immediately, on the assumption it's dead */
285 peer = peer_htable_get(&daemon->peers, id);
286 if (peer)
287 tal_free(peer);
288
289 /* We promised we'd take it by marking it TAKEN above; prepare to free it. */
290 if (taken(their_features))
291 tal_steal(tmpctx, their_features);
292
293 /* BOLT #1:
294 *
295 * The receiving node:
296 * ...
297 * - upon receiving unknown _odd_ feature bits that are non-zero:
298 * - MUST ignore the bit.
299 * - upon receiving unknown _even_ feature bits that are non-zero:
300 * - MUST close the connection.
301 */
302 unsup = features_unsupported(daemon->our_features, their_features,
303 INIT_FEATURE);
304 if (unsup != -1) {
305 status_peer_unusual(id, "Unsupported feature %u", unsup);
306 msg = towire_warningfmt(NULL, NULL, "Unsupported feature %u",
307 unsup);
308 msg = cryptomsg_encrypt_msg(tmpctx, cs, take(msg));
309 return io_write(conn, msg, tal_count(msg), io_close_cb, NULL);
310 }
311
312 if (!feature_check_depends(their_features, &depender, &missing)) {
313 status_peer_unusual(id, "Feature %zu requires feature %zu",
314 depender, missing);
315 msg = towire_warningfmt(NULL, NULL,
316 "Feature %zu requires feature %zu",
317 depender, missing);
318 msg = cryptomsg_encrypt_msg(tmpctx, cs, take(msg));
319 return io_write(conn, msg, tal_count(msg), io_close_cb, NULL);
320 }
321
322 /* We've successfully connected. */
323 if (incoming)
324 peer_connected_in(daemon, conn, id);
325 else

Callers 1

peer_init_receivedFunction · 0.70

Calls 15

tal_freeFunction · 0.85
takenFunction · 0.85
cryptomsg_encrypt_msgFunction · 0.85
feature_check_dependsFunction · 0.85
peer_connected_inFunction · 0.85
connected_out_to_peerFunction · 0.85
find_connectingFunction · 0.85
io_closeFunction · 0.85
setup_peer_gossip_storeFunction · 0.85
multiplex_peer_setupFunction · 0.85
new_peerFunction · 0.70
features_unsupportedFunction · 0.50

Tested by

no test coverage detected