| 476 | } |
| 477 | |
| 478 | static 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 | } |
no test coverage detected