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

Function read_body_from_peer_done

connectd/multiplex.c:1077–1155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1075static struct io_plan *read_hdr_from_peer(struct io_conn *peer_conn,
1076 struct peer *peer);
1077static struct io_plan *read_body_from_peer_done(struct io_conn *peer_conn,
1078 struct peer *peer)
1079{
1080 u8 *decrypted;
1081 struct channel_id channel_id;
1082 struct subd *subd;
1083
1084 decrypted = cryptomsg_decrypt_body(tmpctx, &peer->cs,
1085 peer->peer_in);
1086 if (!decrypted) {
1087 status_peer_debug(&peer->id, "Bad encrypted packet len %zu",
1088 tal_bytelen(peer->peer_in));
1089 return io_close(peer_conn);
1090 }
1091 tal_free(peer->peer_in);
1092
1093 /* dev_disconnect can disable read */
1094 if (!IFDEV(peer->dev_read_enabled, true))
1095 return read_hdr_from_peer(peer_conn, peer);
1096
1097 /* We got something! */
1098 peer->last_recv_time = time_now();
1099
1100 /* Don't process packets while we're closing */
1101 if (peer->draining)
1102 return read_hdr_from_peer(peer_conn, peer);
1103
1104 /* If we swallow this, just try again. */
1105 if (handle_message_locally(peer, decrypted))
1106 return read_hdr_from_peer(peer_conn, peer);
1107
1108 /* After this we should be able to match to subd by channel_id */
1109 if (!extract_channel_id(decrypted, &channel_id)) {
1110 enum peer_wire type = fromwire_peektype(decrypted);
1111
1112 /* We won't log this anywhere else, so do it here. */
1113 status_peer_io(LOG_IO_IN, &peer->id, decrypted);
1114
1115 /* Could be a all-channel error or warning? Log it
1116 * more verbose, and hang up. */
1117 if (type == WIRE_ERROR || type == WIRE_WARNING) {
1118 char *desc = sanitize_error(tmpctx, decrypted, NULL);
1119 status_peer_info(&peer->id,
1120 "Received %s: %s",
1121 peer_wire_name(type), desc);
1122 return io_close(peer_conn);
1123 }
1124
1125 /* This sets final_msg: will close after sending warning */
1126 send_warning(peer, "Unexpected message %s: %s",
1127 peer_wire_name(type),
1128 tal_hex(tmpctx, decrypted));
1129 return read_hdr_from_peer(peer_conn, peer);
1130 }
1131
1132 /* If we don't find a subdaemon for this, create a new one. */
1133 subd = find_subd(peer, &channel_id);
1134 if (!subd) {

Callers

nothing calls this directly

Calls 15

cryptomsg_decrypt_bodyFunction · 0.85
tal_bytelenFunction · 0.85
io_closeFunction · 0.85
tal_freeFunction · 0.85
read_hdr_from_peerFunction · 0.85
time_nowFunction · 0.85
handle_message_locallyFunction · 0.85
extract_channel_idFunction · 0.85
send_warningFunction · 0.85
tal_hexFunction · 0.85
find_subdFunction · 0.85
maybe_update_channelidFunction · 0.85

Tested by

no test coverage detected