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

Function sd_msg_read

lightningd/subd.c:478–587  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

476}
477
478static struct io_plan *sd_msg_read(struct io_conn *conn, struct subd *sd)
479{
480 int type = fromwire_peektype(sd->msg_in);
481 struct subd_req *sr;
482 struct db *db = sd->ld->wallet->db;
483 struct io_plan *plan;
484 unsigned int i;
485 bool freed = false;
486
487 /* Everything we do, we wrap in a database transaction */
488 db_begin_transaction(db);
489
490 if (type == -1)
491 goto malformed;
492
493 /* First, check for replies. */
494 sr = get_req(sd, type);
495 if (sr) {
496 if (sr->num_reply_fds && sd->fds_in == NULL) {
497 plan = sd_collect_fds(conn, sd, sr->num_reply_fds);
498 goto out;
499 }
500
501 assert(sr->num_reply_fds == tal_count(sd->fds_in));
502 plan = sd_msg_reply(conn, sd, sr);
503 goto out;
504 }
505
506 /* If not stolen, we'll free this later. */
507 tal_steal(tmpctx, sd->msg_in);
508
509 /* We handle status messages ourselves. */
510 switch ((enum status_wire)type) {
511 case WIRE_STATUS_LOG:
512 case WIRE_STATUS_IO:
513 if (!log_status_msg(sd->log, sd->node_id, sd->msg_in))
514 goto malformed;
515 goto next;
516 case WIRE_STATUS_FAIL:
517 if (!log_status_fail(sd, sd->msg_in))
518 goto malformed;
519 goto close;
520 case WIRE_STATUS_PEER_CONNECTION_LOST:
521 if (!sd->channel)
522 goto malformed;
523 log_info(sd->log, "Peer connection lost");
524 goto close;
525 case WIRE_STATUS_PEER_BILLBOARD:
526 if (!sd->channel)
527 goto malformed;
528 if (!handle_set_billboard(sd, sd->msg_in))
529 goto malformed;
530 goto next;
531 case WIRE_STATUS_VERSION:
532 if (!handle_version(sd, sd->msg_in))
533 goto close;
534 goto next;
535 }

Callers 1

read_fdsFunction · 0.85

Calls 14

get_reqFunction · 0.85
sd_collect_fdsFunction · 0.85
sd_msg_replyFunction · 0.85
log_status_failFunction · 0.85
log_infoClass · 0.85
handle_set_billboardFunction · 0.85
handle_versionFunction · 0.85
tal_freeFunction · 0.85
subdaemon_malformed_msgFunction · 0.85
io_closeFunction · 0.85
log_status_msgFunction · 0.70
handle_peer_errorFunction · 0.70

Tested by

no test coverage detected