MCPcopy Create free account
hub / github.com/ElementsProject/lightning / sanitize_error

Function sanitize_error

common/wire_error.c:118–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116}
117
118char *sanitize_error(const tal_t *ctx, const u8 *errmsg,
119 struct channel_id *channel_id)
120{
121 struct channel_id dummy;
122 u8 *data;
123 size_t i;
124 const char *tag;
125
126 if (!channel_id)
127 channel_id = &dummy;
128
129 if (fromwire_error(ctx, errmsg, channel_id, &data))
130 tag = "ERROR";
131 else if (fromwire_warning(ctx, errmsg, channel_id, &data))
132 tag = "WARNING";
133 else if (fromwire_tx_abort(ctx, errmsg, channel_id, &data))
134 tag = "ABORT";
135 else
136 return tal_fmt(ctx, "Invalid ERROR message '%s'",
137 tal_hex(ctx, errmsg));
138
139 /* BOLT #1:
140 *
141 * The receiving node:
142 *...
143 * - if `data` is not composed solely of printable ASCII characters
144 * (For reference: the printable character set includes byte values 32
145 * through 126, inclusive):
146 * - SHOULD NOT print out `data` verbatim.
147 */
148 for (i = 0; i < tal_count(data); i++) {
149 if (data[i] < 32 || data[i] > 127) {
150 /* Convert to hex, minus NUL term */
151 data = (u8 *)tal_hex(ctx, data);
152 tal_resize(&data, strlen((const char *)data));
153 break;
154 }
155 }
156
157 return tal_fmt(ctx, "%s%s%s: %.*s",
158 tag,
159 channel_id_is_all(channel_id) ? "": " channel ",
160 channel_id_is_all(channel_id) ? ""
161 : fmt_channel_id(tmpctx, channel_id),
162 (int)tal_count(data), (char *)data);
163}
164
165const char *is_peer_warning(const tal_t *ctx, const u8 *msg)
166{

Callers 6

read_body_from_peer_doneFunction · 0.85
check_tx_abortFunction · 0.85
peer_expect_msg_fourFunction · 0.85
is_peer_warningFunction · 0.85
is_peer_errorFunction · 0.85
handle_tx_abortFunction · 0.85

Calls 3

tal_hexFunction · 0.85
channel_id_is_allFunction · 0.85
fmt_channel_idFunction · 0.70

Tested by

no test coverage detected