mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 01:43:36 +01:00
531845971c
This was removed from the spec on Apr 25, 2022. We stopped ever sending them in 0.12.0 (2022-08-23). Now we remove receive support. Changelog-Protocol: Removed support for zlib-compressed short-channel-ids in query responses. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
113 lines
3.0 KiB
C
113 lines
3.0 KiB
C
#include "config.h"
|
|
#include <ccan/cast/cast.h>
|
|
#include <common/decode_array.h>
|
|
#include <wire/peer_wire.h>
|
|
|
|
struct short_channel_id *decode_short_ids(const tal_t *ctx, const u8 *encoded)
|
|
{
|
|
struct short_channel_id *scids;
|
|
size_t max = tal_count(encoded);
|
|
enum arr_encode_types type;
|
|
|
|
/* BOLT #7:
|
|
*
|
|
* The receiver:
|
|
* - if the first byte of `encoded_short_ids` is not a known encoding
|
|
* type:
|
|
* - MAY send a `warning`.
|
|
* - MAY close the connection.
|
|
* - if `encoded_short_ids` does not decode into a whole number of
|
|
* `short_channel_id`:
|
|
* - MAY send a `warning`.
|
|
* - MAY close the connection.
|
|
*/
|
|
type = fromwire_u8(&encoded, &max);
|
|
switch (type) {
|
|
case ARR_ZLIB_DEPRECATED:
|
|
return NULL;
|
|
case ARR_UNCOMPRESSED:
|
|
scids = tal_arr(ctx, struct short_channel_id, 0);
|
|
while (max) {
|
|
struct short_channel_id scid;
|
|
scid = fromwire_short_channel_id(&encoded, &max);
|
|
tal_arr_expand(&scids, scid);
|
|
}
|
|
|
|
/* encoded is set to NULL if we ran over */
|
|
if (!encoded)
|
|
return tal_free(scids);
|
|
return scids;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
bigsize_t *decode_scid_query_flags(const tal_t *ctx,
|
|
const struct tlv_query_short_channel_ids_tlvs_query_flags *qf)
|
|
{
|
|
u8 *encoded = qf->encoded_query_flags;
|
|
size_t max = tal_count(encoded);
|
|
bigsize_t *flags;
|
|
|
|
/* BOLT #7:
|
|
*
|
|
* The receiver:
|
|
*...
|
|
* - if the incoming message includes `query_short_channel_ids_tlvs`:
|
|
* - if `encoding_type` is not a known encoding type:
|
|
* - MAY send a `warning`.
|
|
* - MAY close the connection.
|
|
* - if `encoded_query_flags` does not decode to exactly one flag per
|
|
* `short_channel_id`:
|
|
* - MAY send a `warning`.
|
|
* - MAY close the connection.
|
|
*/
|
|
switch (qf->encoding_type) {
|
|
case ARR_ZLIB_DEPRECATED:
|
|
return NULL;
|
|
case ARR_UNCOMPRESSED:
|
|
flags = tal_arr(ctx, bigsize_t, 0);
|
|
while (max)
|
|
tal_arr_expand(&flags,
|
|
fromwire_bigsize(cast_const2(const u8 **,
|
|
&encoded),
|
|
&max));
|
|
|
|
/* encoded is set to NULL if we ran over */
|
|
if (!encoded)
|
|
return tal_free(flags);
|
|
return flags;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
struct channel_update_timestamps *
|
|
decode_channel_update_timestamps(const tal_t *ctx,
|
|
const struct tlv_reply_channel_range_tlvs_timestamps_tlv *timestamps_tlv)
|
|
{
|
|
/* Note that our parser will set this to NULL if there are no elements */
|
|
u8 *encoded = timestamps_tlv->encoded_timestamps;
|
|
size_t max = tal_count(encoded);
|
|
struct channel_update_timestamps *ts;
|
|
|
|
/* FIXME: BOLT #7 should have a requirements like it does for
|
|
* query_short_channel_ids_tlvs! */
|
|
switch (timestamps_tlv->encoding_type) {
|
|
case ARR_ZLIB_DEPRECATED:
|
|
return NULL;
|
|
case ARR_UNCOMPRESSED:
|
|
ts = tal_arr(ctx, struct channel_update_timestamps, 0);
|
|
while (max) {
|
|
struct channel_update_timestamps t;
|
|
fromwire_channel_update_timestamps
|
|
(cast_const2(const u8 **, &encoded),
|
|
&max, &t);
|
|
/* Sets this to NULL if it fails */
|
|
if (!encoded)
|
|
return tal_free(ts);
|
|
tal_arr_expand(&ts, t);
|
|
}
|
|
return ts;
|
|
}
|
|
return NULL;
|
|
}
|