| 1412 | static struct io_plan *read_hdr_from_peer(struct io_conn *peer_conn, |
| 1413 | struct peer *peer); |
| 1414 | static struct io_plan *read_body_from_peer_done(struct io_conn *peer_conn, |
| 1415 | struct peer *peer) |
| 1416 | { |
| 1417 | u8 *decrypted; |
| 1418 | struct channel_id channel_id; |
| 1419 | struct subd *subd; |
| 1420 | enum peer_wire type; |
| 1421 | struct io_plan *(*next_read)(struct io_conn *peer_conn, |
| 1422 | struct peer *peer) = read_hdr_from_peer; |
| 1423 | |
| 1424 | decrypted = cryptomsg_decrypt_body(tmpctx, &peer->cs, |
| 1425 | peer->peer_in); |
| 1426 | if (!decrypted) { |
| 1427 | status_peer_debug(&peer->id, "Bad encrypted packet len %zu", |
| 1428 | tal_bytelen(peer->peer_in)); |
| 1429 | return io_close(peer_conn); |
| 1430 | } |
| 1431 | |
| 1432 | peer->bytes_rcvd_this_second += tal_bytelen(peer->peer_in); |
| 1433 | tal_free(peer->peer_in); |
| 1434 | |
| 1435 | type = fromwire_peektype(decrypted); |
| 1436 | |
| 1437 | /* dev_disconnect can disable read */ |
| 1438 | if (!peer->dev_read_enabled) |
| 1439 | return read_hdr_from_peer(peer_conn, peer); |
| 1440 | |
| 1441 | switch (dev_disconnect_in(&peer->id, type)) { |
| 1442 | case DEV_DISCONNECT_IN_NORMAL: |
| 1443 | break; |
| 1444 | case DEV_DISCONNECT_IN_AFTER_RECV: |
| 1445 | next_read = close_peer_dev_disconnect; |
| 1446 | break; |
| 1447 | } |
| 1448 | |
| 1449 | /* We got something! */ |
| 1450 | peer->last_recv_time = time_mono(); |
| 1451 | |
| 1452 | /* Don't process packets while we're closing */ |
| 1453 | if (peer->draining_state != NOT_DRAINING) |
| 1454 | return next_read(peer_conn, peer); |
| 1455 | |
| 1456 | /* If we swallow this, just try again. */ |
| 1457 | if (handle_message_locally(peer, decrypted)) { |
| 1458 | /* Make sure to update peer->peer_in_lastmsg so we blame correct msg! */ |
| 1459 | goto out; |
| 1460 | } |
| 1461 | |
| 1462 | /* After this we should be able to match to subd by channel_id */ |
| 1463 | if (!extract_channel_id(decrypted, &channel_id)) { |
| 1464 | /* We won't log this anywhere else, so do it here. */ |
| 1465 | status_peer_io(LOG_IO_IN, &peer->id, decrypted); |
| 1466 | |
| 1467 | /* Could be a all-channel error or warning? Log it |
| 1468 | * more verbose: hang up on error. */ |
| 1469 | if (type == WIRE_ERROR || type == WIRE_WARNING) { |
| 1470 | char *desc = sanitize_error(tmpctx, decrypted, NULL); |
| 1471 | /* FIXME: We should check old gossip, since we get many of |
nothing calls this directly
no test coverage detected