mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 15:44:21 +01:00
common: rename decode_short_channel_ids.{c,h} to decode_array.{c.h}
This encoding scheme is no longer just used for short_channel_ids, so make the names more generic. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -15,7 +15,7 @@ COMMON_SRC_NOGEN := \
|
|||||||
common/cryptomsg.c \
|
common/cryptomsg.c \
|
||||||
common/daemon.c \
|
common/daemon.c \
|
||||||
common/daemon_conn.c \
|
common/daemon_conn.c \
|
||||||
common/decode_short_channel_ids.c \
|
common/decode_array.c \
|
||||||
common/derive_basepoints.c \
|
common/derive_basepoints.c \
|
||||||
common/dev_disconnect.c \
|
common/dev_disconnect.c \
|
||||||
common/features.c \
|
common/features.c \
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include <ccan/cast/cast.h>
|
#include <ccan/cast/cast.h>
|
||||||
#include <common/decode_short_channel_ids.h>
|
#include <common/decode_array.h>
|
||||||
#include <common/utils.h>
|
#include <common/utils.h>
|
||||||
#include <wire/gen_peer_wire.h>
|
#include <wire/gen_peer_wire.h>
|
||||||
#include <wire/wire.h>
|
#include <wire/wire.h>
|
||||||
@@ -27,7 +27,7 @@ struct short_channel_id *decode_short_ids(const tal_t *ctx, const u8 *encoded)
|
|||||||
{
|
{
|
||||||
struct short_channel_id *scids;
|
struct short_channel_id *scids;
|
||||||
size_t max = tal_count(encoded);
|
size_t max = tal_count(encoded);
|
||||||
enum scid_encode_types type;
|
enum arr_encode_types type;
|
||||||
|
|
||||||
/* BOLT #7:
|
/* BOLT #7:
|
||||||
*
|
*
|
||||||
@@ -41,13 +41,13 @@ struct short_channel_id *decode_short_ids(const tal_t *ctx, const u8 *encoded)
|
|||||||
*/
|
*/
|
||||||
type = fromwire_u8(&encoded, &max);
|
type = fromwire_u8(&encoded, &max);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SHORTIDS_ZLIB:
|
case ARR_ZLIB:
|
||||||
encoded = unzlib(tmpctx, encoded, max);
|
encoded = unzlib(tmpctx, encoded, max);
|
||||||
if (!encoded)
|
if (!encoded)
|
||||||
return NULL;
|
return NULL;
|
||||||
max = tal_count(encoded);
|
max = tal_count(encoded);
|
||||||
/* fall thru */
|
/* fall thru */
|
||||||
case SHORTIDS_UNCOMPRESSED:
|
case ARR_UNCOMPRESSED:
|
||||||
scids = tal_arr(ctx, struct short_channel_id, 0);
|
scids = tal_arr(ctx, struct short_channel_id, 0);
|
||||||
while (max) {
|
while (max) {
|
||||||
struct short_channel_id scid;
|
struct short_channel_id scid;
|
||||||
@@ -82,13 +82,13 @@ bigsize_t *decode_scid_query_flags(const tal_t *ctx,
|
|||||||
* - MAY fail the connection.
|
* - MAY fail the connection.
|
||||||
*/
|
*/
|
||||||
switch (qf->encoding_type) {
|
switch (qf->encoding_type) {
|
||||||
case SHORTIDS_ZLIB:
|
case ARR_ZLIB:
|
||||||
encoded = unzlib(tmpctx, encoded, max);
|
encoded = unzlib(tmpctx, encoded, max);
|
||||||
if (!encoded)
|
if (!encoded)
|
||||||
return NULL;
|
return NULL;
|
||||||
max = tal_count(encoded);
|
max = tal_count(encoded);
|
||||||
/* fall thru */
|
/* fall thru */
|
||||||
case SHORTIDS_UNCOMPRESSED:
|
case ARR_UNCOMPRESSED:
|
||||||
flags = tal_arr(ctx, bigsize_t, 0);
|
flags = tal_arr(ctx, bigsize_t, 0);
|
||||||
while (max)
|
while (max)
|
||||||
tal_arr_expand(&flags,
|
tal_arr_expand(&flags,
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef LIGHTNING_COMMON_DECODE_SHORT_CHANNEL_IDS_H
|
#ifndef LIGHTNING_COMMON_DECODE_ARRAY_H
|
||||||
#define LIGHTNING_COMMON_DECODE_SHORT_CHANNEL_IDS_H
|
#define LIGHTNING_COMMON_DECODE_ARRAY_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <ccan/short_types/short_types.h>
|
#include <ccan/short_types/short_types.h>
|
||||||
#include <ccan/tal/tal.h>
|
#include <ccan/tal/tal.h>
|
||||||
@@ -13,9 +13,9 @@ struct tlv_query_short_channel_ids_tlvs_query_flags;
|
|||||||
* * `0`: uncompressed array of `short_channel_id` types, in ascending order.
|
* * `0`: uncompressed array of `short_channel_id` types, in ascending order.
|
||||||
* * `1`: array of `short_channel_id` types, in ascending order, compressed with zlib deflate<sup>[1](#reference-1)</sup>
|
* * `1`: array of `short_channel_id` types, in ascending order, compressed with zlib deflate<sup>[1](#reference-1)</sup>
|
||||||
*/
|
*/
|
||||||
enum scid_encode_types {
|
enum arr_encode_types {
|
||||||
SHORTIDS_UNCOMPRESSED = 0,
|
ARR_UNCOMPRESSED = 0,
|
||||||
SHORTIDS_ZLIB = 1
|
ARR_ZLIB = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
struct short_channel_id *decode_short_ids(const tal_t *ctx, const u8 *encoded);
|
struct short_channel_id *decode_short_ids(const tal_t *ctx, const u8 *encoded);
|
||||||
@@ -44,4 +44,4 @@ enum scid_query_flag {
|
|||||||
bigsize_t *decode_scid_query_flags(const tal_t *ctx,
|
bigsize_t *decode_scid_query_flags(const tal_t *ctx,
|
||||||
const struct tlv_query_short_channel_ids_tlvs_query_flags *qf);
|
const struct tlv_query_short_channel_ids_tlvs_query_flags *qf);
|
||||||
|
|
||||||
#endif /* LIGHTNING_COMMON_DECODE_SHORT_CHANNEL_IDS_H */
|
#endif /* LIGHTNING_COMMON_DECODE_ARRAY_H */
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
#include <common/bech32_util.h>
|
#include <common/bech32_util.h>
|
||||||
#include <common/cryptomsg.h>
|
#include <common/cryptomsg.h>
|
||||||
#include <common/daemon_conn.h>
|
#include <common/daemon_conn.h>
|
||||||
#include <common/decode_short_channel_ids.h>
|
#include <common/decode_array.h>
|
||||||
#include <common/features.h>
|
#include <common/features.h>
|
||||||
#include <common/memleak.h>
|
#include <common/memleak.h>
|
||||||
#include <common/ping.h>
|
#include <common/ping.h>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ DEVTOOLS_COMMON_OBJS := \
|
|||||||
common/bigsize.o \
|
common/bigsize.o \
|
||||||
common/bolt11.o \
|
common/bolt11.o \
|
||||||
common/crypto_state.o \
|
common/crypto_state.o \
|
||||||
common/decode_short_channel_ids.o \
|
common/decode_array.o \
|
||||||
common/features.o \
|
common/features.o \
|
||||||
common/gossip_rcvd_filter.o \
|
common/gossip_rcvd_filter.o \
|
||||||
common/hash_u5.o \
|
common/hash_u5.o \
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include <ccan/err/err.h>
|
#include <ccan/err/err.h>
|
||||||
#include <ccan/opt/opt.h>
|
#include <ccan/opt/opt.h>
|
||||||
#include <ccan/tal/grab_file/grab_file.h>
|
#include <ccan/tal/grab_file/grab_file.h>
|
||||||
#include <common/decode_short_channel_ids.h>
|
#include <common/decode_array.h>
|
||||||
#include <common/utils.h>
|
#include <common/utils.h>
|
||||||
#include <devtools/gen_print_onion_wire.h>
|
#include <devtools/gen_print_onion_wire.h>
|
||||||
#include <devtools/gen_print_wire.h>
|
#include <devtools/gen_print_wire.h>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include <bitcoin/short_channel_id.h>
|
#include <bitcoin/short_channel_id.h>
|
||||||
#include <ccan/err/err.h>
|
#include <ccan/err/err.h>
|
||||||
#include <ccan/str/hex/hex.h>
|
#include <ccan/str/hex/hex.h>
|
||||||
#include <common/decode_short_channel_ids.h>
|
#include <common/decode_array.h>
|
||||||
#include <common/utils.h>
|
#include <common/utils.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <wire/wire.h>
|
#include <wire/wire.h>
|
||||||
@@ -41,9 +41,9 @@ int main(int argc, char *argv[])
|
|||||||
if (!hex_decode(argv[1], strlen(argv[1]), &encoding, sizeof(encoding)))
|
if (!hex_decode(argv[1], strlen(argv[1]), &encoding, sizeof(encoding)))
|
||||||
errx(1, "Expected single hex byte not %s", argv[1]);
|
errx(1, "Expected single hex byte not %s", argv[1]);
|
||||||
|
|
||||||
if (encoding == SHORTIDS_UNCOMPRESSED)
|
if (encoding == ARR_UNCOMPRESSED)
|
||||||
printf("%02x%s\n", encoding, tal_hex(NULL, data));
|
printf("%02x%s\n", encoding, tal_hex(NULL, data));
|
||||||
else if (encoding == SHORTIDS_ZLIB) {
|
else if (encoding == ARR_ZLIB) {
|
||||||
/* https://www.zlib.net/zlib_tech.html:
|
/* https://www.zlib.net/zlib_tech.html:
|
||||||
* the only expansion is an overhead of five bytes per 16 KB
|
* the only expansion is an overhead of five bytes per 16 KB
|
||||||
* block (about 0.03%), plus a one-time overhead of six bytes
|
* block (about 0.03%), plus a one-time overhead of six bytes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include <ccan/mem/mem.h>
|
#include <ccan/mem/mem.h>
|
||||||
#include <ccan/utf8/utf8.h>
|
#include <ccan/utf8/utf8.h>
|
||||||
#include <common/decode_short_channel_ids.h>
|
#include <common/decode_array.h>
|
||||||
#include <common/type_to_string.h>
|
#include <common/type_to_string.h>
|
||||||
#include <devtools/print_wire.h>
|
#include <devtools/print_wire.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -114,10 +114,10 @@ static void printwire_encoded_short_ids(const u8 **cursor, size_t *plen, size_t
|
|||||||
scids = decode_short_ids(tmpctx, arr);
|
scids = decode_short_ids(tmpctx, arr);
|
||||||
if (scids) {
|
if (scids) {
|
||||||
switch (arr[0]) {
|
switch (arr[0]) {
|
||||||
case SHORTIDS_UNCOMPRESSED:
|
case ARR_UNCOMPRESSED:
|
||||||
printf(" (UNCOMPRESSED)");
|
printf(" (UNCOMPRESSED)");
|
||||||
break;
|
break;
|
||||||
case SHORTIDS_ZLIB:
|
case ARR_ZLIB:
|
||||||
printf(" (ZLIB)");
|
printf(" (ZLIB)");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -129,8 +129,8 @@ static void printwire_encoded_short_ids(const u8 **cursor, size_t *plen, size_t
|
|||||||
} else {
|
} else {
|
||||||
/* If it was unknown, that's different from corrupt */
|
/* If it was unknown, that's different from corrupt */
|
||||||
if (len == 0
|
if (len == 0
|
||||||
|| arr[0] == SHORTIDS_UNCOMPRESSED
|
|| arr[0] == ARR_UNCOMPRESSED
|
||||||
|| arr[0] == SHORTIDS_ZLIB) {
|
|| arr[0] == ARR_ZLIB) {
|
||||||
printf(" **CORRUPT**");
|
printf(" **CORRUPT**");
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ GOSSIPD_COMMON_OBJS := \
|
|||||||
common/cryptomsg.o \
|
common/cryptomsg.o \
|
||||||
common/daemon.o \
|
common/daemon.o \
|
||||||
common/daemon_conn.o \
|
common/daemon_conn.o \
|
||||||
common/decode_short_channel_ids.o \
|
common/decode_array.o \
|
||||||
common/derive_basepoints.o \
|
common/derive_basepoints.o \
|
||||||
common/dev_disconnect.o \
|
common/dev_disconnect.o \
|
||||||
common/features.o \
|
common/features.o \
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <ccan/crc32c/crc32c.h>
|
#include <ccan/crc32c/crc32c.h>
|
||||||
#include <ccan/tal/tal.h>
|
#include <ccan/tal/tal.h>
|
||||||
#include <common/daemon_conn.h>
|
#include <common/daemon_conn.h>
|
||||||
#include <common/decode_short_channel_ids.h>
|
#include <common/decode_array.h>
|
||||||
#include <common/status.h>
|
#include <common/status.h>
|
||||||
#include <common/type_to_string.h>
|
#include <common/type_to_string.h>
|
||||||
#include <common/wire_error.h>
|
#include <common/wire_error.h>
|
||||||
@@ -116,10 +116,10 @@ static void encoding_end_no_compress(u8 **encoded, size_t off)
|
|||||||
static bool encoding_end_prepend_type(u8 **encoded, size_t max_bytes)
|
static bool encoding_end_prepend_type(u8 **encoded, size_t max_bytes)
|
||||||
{
|
{
|
||||||
if (encoding_end_zlib(encoded, 1))
|
if (encoding_end_zlib(encoded, 1))
|
||||||
**encoded = SHORTIDS_ZLIB;
|
**encoded = ARR_ZLIB;
|
||||||
else {
|
else {
|
||||||
encoding_end_no_compress(encoded, 1);
|
encoding_end_no_compress(encoded, 1);
|
||||||
**encoded = SHORTIDS_UNCOMPRESSED;
|
**encoded = ARR_UNCOMPRESSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEVELOPER
|
#if DEVELOPER
|
||||||
@@ -133,10 +133,10 @@ static bool encoding_end_prepend_type(u8 **encoded, size_t max_bytes)
|
|||||||
static UNNEEDED bool encoding_end_external_type(u8 **encoded, u8 *type, size_t max_bytes)
|
static UNNEEDED bool encoding_end_external_type(u8 **encoded, u8 *type, size_t max_bytes)
|
||||||
{
|
{
|
||||||
if (encoding_end_zlib(encoded, 0))
|
if (encoding_end_zlib(encoded, 0))
|
||||||
*type = SHORTIDS_ZLIB;
|
*type = ARR_ZLIB;
|
||||||
else {
|
else {
|
||||||
encoding_end_no_compress(encoded, 0);
|
encoding_end_no_compress(encoded, 0);
|
||||||
*type = SHORTIDS_UNCOMPRESSED;
|
*type = ARR_UNCOMPRESSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tal_count(*encoded) <= max_bytes;
|
return tal_count(*encoded) <= max_bytes;
|
||||||
|
|||||||
@@ -297,11 +297,11 @@ static u8 *get_scid_array(const tal_t *ctx,
|
|||||||
}
|
}
|
||||||
if (json_tok_streq(test_vector, encoding, "UNCOMPRESSED")) {
|
if (json_tok_streq(test_vector, encoding, "UNCOMPRESSED")) {
|
||||||
encoding_end_no_compress(&encoded, 1);
|
encoding_end_no_compress(&encoded, 1);
|
||||||
encoded[0] = SHORTIDS_UNCOMPRESSED;
|
encoded[0] = ARR_UNCOMPRESSED;
|
||||||
} else {
|
} else {
|
||||||
assert(json_tok_streq(test_vector, encoding, "COMPRESSED_ZLIB"));
|
assert(json_tok_streq(test_vector, encoding, "COMPRESSED_ZLIB"));
|
||||||
assert(encoding_end_zlib(&encoded, 1));
|
assert(encoding_end_zlib(&encoded, 1));
|
||||||
encoded[0] = SHORTIDS_ZLIB;
|
encoded[0] = ARR_ZLIB;
|
||||||
}
|
}
|
||||||
|
|
||||||
return encoded;
|
return encoded;
|
||||||
@@ -380,13 +380,13 @@ static u8 *test_reply_channel_range(const char *test_vector, const jsmntok_t *ob
|
|||||||
if (json_tok_streq(test_vector, encodingtok, "UNCOMPRESSED")) {
|
if (json_tok_streq(test_vector, encodingtok, "UNCOMPRESSED")) {
|
||||||
encoding_end_no_compress(&tlvs->timestamps_tlv->encoded_timestamps,
|
encoding_end_no_compress(&tlvs->timestamps_tlv->encoded_timestamps,
|
||||||
0);
|
0);
|
||||||
tlvs->timestamps_tlv->encoding_type = SHORTIDS_UNCOMPRESSED;
|
tlvs->timestamps_tlv->encoding_type = ARR_UNCOMPRESSED;
|
||||||
} else {
|
} else {
|
||||||
assert(json_tok_streq(test_vector, encodingtok,
|
assert(json_tok_streq(test_vector, encodingtok,
|
||||||
"COMPRESSED_ZLIB"));
|
"COMPRESSED_ZLIB"));
|
||||||
assert(encoding_end_zlib(&tlvs->timestamps_tlv->encoded_timestamps,
|
assert(encoding_end_zlib(&tlvs->timestamps_tlv->encoded_timestamps,
|
||||||
0));
|
0));
|
||||||
tlvs->timestamps_tlv->encoding_type = SHORTIDS_ZLIB;
|
tlvs->timestamps_tlv->encoding_type = ARR_ZLIB;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -443,11 +443,11 @@ get_query_flags_array(const tal_t *ctx,
|
|||||||
}
|
}
|
||||||
if (json_tok_streq(test_vector, encoding, "UNCOMPRESSED")) {
|
if (json_tok_streq(test_vector, encoding, "UNCOMPRESSED")) {
|
||||||
encoding_end_no_compress(&tlv->encoded_query_flags, 0);
|
encoding_end_no_compress(&tlv->encoded_query_flags, 0);
|
||||||
tlv->encoding_type = SHORTIDS_UNCOMPRESSED;
|
tlv->encoding_type = ARR_UNCOMPRESSED;
|
||||||
} else {
|
} else {
|
||||||
assert(json_tok_streq(test_vector, encoding, "COMPRESSED_ZLIB"));
|
assert(json_tok_streq(test_vector, encoding, "COMPRESSED_ZLIB"));
|
||||||
assert(encoding_end_zlib(&tlv->encoded_query_flags, 0));
|
assert(encoding_end_zlib(&tlv->encoded_query_flags, 0));
|
||||||
tlv->encoding_type = SHORTIDS_ZLIB;
|
tlv->encoding_type = ARR_ZLIB;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tlv;
|
return tlv;
|
||||||
|
|||||||
Reference in New Issue
Block a user