| 52 | static struct io_plan *read_init(struct io_conn *conn, struct early_peer *peer); |
| 53 | |
| 54 | static struct io_plan *peer_init_received(struct io_conn *conn, |
| 55 | struct early_peer *peer) |
| 56 | { |
| 57 | u8 *msg = cryptomsg_decrypt_body(tmpctx, &peer->cs, peer->msg); |
| 58 | u8 *globalfeatures, *features; |
| 59 | struct tlv_init_tlvs *tlvs; |
| 60 | struct wireaddr *remote_addr; |
| 61 | |
| 62 | if (!msg) |
| 63 | return io_close(conn); |
| 64 | |
| 65 | status_peer_io(LOG_IO_IN, &peer->id, msg); |
| 66 | |
| 67 | switch (dev_disconnect_in(&peer->id, fromwire_peektype(msg))) { |
| 68 | case DEV_DISCONNECT_IN_NORMAL: |
| 69 | break; |
| 70 | case DEV_DISCONNECT_IN_AFTER_RECV: |
| 71 | return io_close(conn); |
| 72 | } |
| 73 | |
| 74 | /* BOLT #1: |
| 75 | * |
| 76 | * A receiving node: |
| 77 | * - upon receiving a message of _odd_, unknown type: |
| 78 | * - MUST ignore the received message. |
| 79 | */ |
| 80 | if (unlikely(is_unknown_msg_discardable(msg))) |
| 81 | return read_init(conn, peer); |
| 82 | |
| 83 | if (!fromwire_init(tmpctx, msg, &globalfeatures, &features, &tlvs)) { |
| 84 | status_peer_debug(&peer->id, |
| 85 | "bad fromwire_init '%s', closing", |
| 86 | tal_hex(tmpctx, msg)); |
| 87 | return io_close(conn); |
| 88 | } |
| 89 | |
| 90 | /* BOLT #1: |
| 91 | * The receiving node: |
| 92 | * ... |
| 93 | * - upon receiving `networks` containing no common chains |
| 94 | * - MAY close the connection. |
| 95 | */ |
| 96 | if (tlvs->networks) { |
| 97 | if (!contains_common_chain(tlvs->networks)) { |
| 98 | status_peer_debug(&peer->id, |
| 99 | "No common chain with this peer '%s', closing", |
| 100 | tal_hex(tmpctx, msg)); |
| 101 | msg = towire_warningfmt(NULL, NULL, "No common network"); |
| 102 | msg = cryptomsg_encrypt_msg(NULL, &peer->cs, take(msg)); |
| 103 | return io_write(conn, msg, tal_count(msg), io_close_cb, NULL); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | /* fetch optional tlv `remote_addr` */ |
| 108 | remote_addr = NULL; |
| 109 | |
| 110 | /* BOLT #1: |
| 111 | * The receiving node: |
no test coverage detected