Return first non-handled message or NULL if connection is aborted */
| 87 | |
| 88 | /* Return first non-handled message or NULL if connection is aborted */ |
| 89 | static u8 *read_next_msg(const tal_t *ctx, |
| 90 | struct interactivetx_context *state, |
| 91 | char **error) |
| 92 | { |
| 93 | u8 *msg = NULL; |
| 94 | |
| 95 | for (;;) { |
| 96 | const char *desc; |
| 97 | enum peer_wire t; |
| 98 | |
| 99 | /* Prevent runaway memory usage from many messages */ |
| 100 | if (msg) |
| 101 | tal_free(msg); |
| 102 | |
| 103 | /* This helper routine polls the peer. */ |
| 104 | msg = peer_read(ctx, state->pps); |
| 105 | |
| 106 | /* BOLT #1: |
| 107 | * |
| 108 | * A receiving node: |
| 109 | * - upon receiving a message of _odd_, unknown type: |
| 110 | * - MUST ignore the received message. |
| 111 | */ |
| 112 | if (is_unknown_msg_discardable(msg)) |
| 113 | continue; |
| 114 | |
| 115 | /* A helper which decodes an error. */ |
| 116 | desc = is_peer_error(msg, msg); |
| 117 | if (desc) { |
| 118 | *error = tal_fmt(ctx, "They sent an error: %s", desc); |
| 119 | |
| 120 | /* Return NULL so caller knows to stop negotiating. */ |
| 121 | return tal_free(msg); |
| 122 | } |
| 123 | |
| 124 | desc = is_peer_warning(msg, msg); |
| 125 | if (desc) { |
| 126 | status_info("They sent %s", desc); |
| 127 | return tal_free(msg); |
| 128 | } |
| 129 | |
| 130 | /* In theory, we're in the middle of an open/RBF/splice, but |
| 131 | * it's possible we can get some different messages in |
| 132 | * the meantime! */ |
| 133 | t = fromwire_peektype(msg); |
| 134 | switch (t) { |
| 135 | case WIRE_TX_ADD_INPUT: |
| 136 | case WIRE_TX_REMOVE_INPUT: |
| 137 | case WIRE_TX_ADD_OUTPUT: |
| 138 | case WIRE_TX_REMOVE_OUTPUT: |
| 139 | case WIRE_TX_COMPLETE: |
| 140 | case WIRE_TX_ABORT: |
| 141 | return msg; |
| 142 | case WIRE_TX_SIGNATURES: |
| 143 | case WIRE_CHANNEL_READY: |
| 144 | case WIRE_TX_INIT_RBF: |
| 145 | case WIRE_OPEN_CHANNEL2: |
| 146 | case WIRE_INIT: |
no test coverage detected