Extract channel_id from various packets, return true if possible. */
| 116 | |
| 117 | /* Extract channel_id from various packets, return true if possible. */ |
| 118 | bool extract_channel_id(const u8 *in_pkt, struct channel_id *channel_id) |
| 119 | { |
| 120 | const u8 *cursor = in_pkt; |
| 121 | size_t max = tal_bytelen(in_pkt); |
| 122 | enum peer_wire t; |
| 123 | |
| 124 | t = fromwire_u16(&cursor, &max); |
| 125 | |
| 126 | /* We carefully quote bolts here, in case anything changes! */ |
| 127 | switch (t) { |
| 128 | /* These ones don't have a channel_id */ |
| 129 | case WIRE_INIT: |
| 130 | case WIRE_PING: |
| 131 | case WIRE_PONG: |
| 132 | case WIRE_CHANNEL_ANNOUNCEMENT: |
| 133 | case WIRE_NODE_ANNOUNCEMENT: |
| 134 | case WIRE_CHANNEL_UPDATE: |
| 135 | case WIRE_QUERY_SHORT_CHANNEL_IDS: |
| 136 | case WIRE_REPLY_SHORT_CHANNEL_IDS_END: |
| 137 | case WIRE_QUERY_CHANNEL_RANGE: |
| 138 | case WIRE_REPLY_CHANNEL_RANGE: |
| 139 | case WIRE_GOSSIP_TIMESTAMP_FILTER: |
| 140 | case WIRE_ONION_MESSAGE: |
| 141 | return false; |
| 142 | |
| 143 | /* Special cases: */ |
| 144 | case WIRE_ERROR: |
| 145 | /* BOLT #1: |
| 146 | * 1. type: 17 (`error`) |
| 147 | * 2. data: |
| 148 | * * [`channel_id`:`channel_id`] |
| 149 | *... |
| 150 | * The channel is referred to by `channel_id`, unless |
| 151 | * `channel_id` is 0 |
| 152 | */ |
| 153 | /* fall thru */ |
| 154 | case WIRE_WARNING: |
| 155 | /* BOLT-warning #1: |
| 156 | * 1. type: 1 (`warning`) |
| 157 | * 2. data: |
| 158 | * * [`channel_id`:`channel_id`] |
| 159 | *... |
| 160 | * The channel is referred to by `channel_id`, unless |
| 161 | * `channel_id` is 0 |
| 162 | */ |
| 163 | if (!fromwire_channel_id(&cursor, &max, channel_id)) |
| 164 | return false; |
| 165 | if (memeqzero(channel_id->id, sizeof(channel_id->id))) |
| 166 | return false; |
| 167 | return true; |
| 168 | |
| 169 | case WIRE_OPEN_CHANNEL: |
| 170 | /* BOLT #2: |
| 171 | * 1. type: 32 (`open_channel`) |
| 172 | * 2. data: |
| 173 | * * [`chain_hash`:`chain_hash`] |
| 174 | * * [`32*byte`:`temporary_channel_id`] |
| 175 | */ |
no test coverage detected