| 43 | static struct io_plan *read_init(struct io_conn *conn, struct early_peer *peer); |
| 44 | |
| 45 | static struct io_plan *peer_init_received(struct io_conn *conn, |
| 46 | struct early_peer *peer) |
| 47 | { |
| 48 | u8 *msg = cryptomsg_decrypt_body(tmpctx, &peer->cs, peer->msg); |
| 49 | u8 *globalfeatures, *features; |
| 50 | struct tlv_init_tlvs *tlvs; |
| 51 | struct wireaddr *remote_addr; |
| 52 | |
| 53 | if (!msg) |
| 54 | return io_close(conn); |
| 55 | |
| 56 | status_peer_io(LOG_IO_IN, &peer->id, msg); |
| 57 | |
| 58 | /* BOLT #1: |
| 59 | * |
| 60 | * A receiving node: |
| 61 | * - upon receiving a message of _odd_, unknown type: |
| 62 | * - MUST ignore the received message. |
| 63 | */ |
| 64 | if (unlikely(is_unknown_msg_discardable(msg))) |
| 65 | return read_init(conn, peer); |
| 66 | |
| 67 | if (!fromwire_init(tmpctx, msg, &globalfeatures, &features, &tlvs)) { |
| 68 | status_peer_debug(&peer->id, |
| 69 | "bad fromwire_init '%s', closing", |
| 70 | tal_hex(tmpctx, msg)); |
| 71 | return io_close(conn); |
| 72 | } |
| 73 | |
| 74 | /* BOLT #1: |
| 75 | * The receiving node: |
| 76 | * ... |
| 77 | * - upon receiving `networks` containing no common chains |
| 78 | * - MAY close the connection. |
| 79 | */ |
| 80 | if (tlvs->networks) { |
| 81 | if (!contains_common_chain(tlvs->networks)) { |
| 82 | status_peer_debug(&peer->id, |
| 83 | "No common chain with this peer '%s', closing", |
| 84 | tal_hex(tmpctx, msg)); |
| 85 | msg = towire_warningfmt(NULL, NULL, "No common network"); |
| 86 | msg = cryptomsg_encrypt_msg(NULL, &peer->cs, take(msg)); |
| 87 | return io_write(conn, msg, tal_count(msg), io_close_cb, NULL); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /* fetch optional tlv `remote_addr` */ |
| 92 | remote_addr = NULL; |
| 93 | |
| 94 | /* BOLT #1: |
| 95 | * The receiving node: |
| 96 | * ... |
| 97 | * - MAY use the `remote_addr` to update its `node_announcement` |
| 98 | */ |
| 99 | if (tlvs->remote_addr) { |
| 100 | const u8 *cursor = tlvs->remote_addr; |
| 101 | size_t len = tal_bytelen(tlvs->remote_addr); |
| 102 |
nothing calls this directly
no test coverage detected