~ Handle random messages we might get during opening negotiation, (eg. gossip) * returning the first non-handled one, or NULL if we aborted negotiation. */
| 180 | /*~ Handle random messages we might get during opening negotiation, (eg. gossip) |
| 181 | * returning the first non-handled one, or NULL if we aborted negotiation. */ |
| 182 | static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state, |
| 183 | const struct channel_id *alternate) |
| 184 | { |
| 185 | /* This is an event loop of its own. That's generally considered poor |
| 186 | * form, but we use it in a very limited way. */ |
| 187 | for (;;) { |
| 188 | u8 *msg; |
| 189 | char *err; |
| 190 | bool warning; |
| 191 | struct channel_id actual; |
| 192 | |
| 193 | /* The event loop is responsible for freeing tmpctx, so our |
| 194 | * temporary allocations don't grow unbounded. */ |
| 195 | clean_tmpctx(); |
| 196 | |
| 197 | /* This helper routine polls both the peer and gossipd. */ |
| 198 | msg = peer_read(ctx, state->pps); |
| 199 | |
| 200 | /* BOLT #1: |
| 201 | * |
| 202 | * A receiving node: |
| 203 | * - upon receiving a message of _odd_, unknown type: |
| 204 | * - MUST ignore the received message. |
| 205 | */ |
| 206 | if (is_unknown_msg_discardable(msg)) |
| 207 | continue; |
| 208 | |
| 209 | /* A helper which decodes an error. */ |
| 210 | if (is_peer_error(tmpctx, msg, &state->channel_id, |
| 211 | &err, &warning)) { |
| 212 | /* BOLT #1: |
| 213 | * |
| 214 | * - if no existing channel is referred to by `channel_id`: |
| 215 | * - MUST ignore the message. |
| 216 | */ |
| 217 | /* In this case, is_peer_error returns true, but sets |
| 218 | * err to NULL */ |
| 219 | if (!err) { |
| 220 | tal_free(msg); |
| 221 | continue; |
| 222 | } |
| 223 | negotiation_aborted(state, |
| 224 | tal_fmt(tmpctx, "They sent %s", |
| 225 | err)); |
| 226 | /* Return NULL so caller knows to stop negotiating. */ |
| 227 | return NULL; |
| 228 | } |
| 229 | |
| 230 | /*~ We do not support multiple "live" channels, though the |
| 231 | * protocol has a "channel_id" field in all non-gossip messages |
| 232 | * so it's possible. Our one-process-one-channel mechanism |
| 233 | * keeps things simple: if we wanted to change this, we would |
| 234 | * probably be best with another daemon to de-multiplex them; |
| 235 | * this could be connectd itself, in fact. */ |
| 236 | if (is_wrong_channel(msg, &state->channel_id, &actual) |
| 237 | && is_wrong_channel(msg, alternate, &actual)) { |
| 238 | status_debug("Rejecting %s for unknown channel_id %s", |
| 239 | peer_wire_name(fromwire_peektype(msg)), |
no test coverage detected