From 5a78671d9f5feedb05d0fb04ea3dc46f07218e5f Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Mon, 25 Nov 2019 23:30:10 +0100 Subject: [PATCH] wire: Remove unused fromwire_tlvs We are now using the typesafe variant everywhere. --- tools/gen/impl_template | 2 +- wire/tlvstream.c | 131 ---------------------------------------- wire/tlvstream.h | 7 --- 3 files changed, 1 insertion(+), 139 deletions(-) diff --git a/tools/gen/impl_template b/tools/gen/impl_template index 197692e7c..6c6496008 100644 --- a/tools/gen/impl_template +++ b/tools/gen/impl_template @@ -425,7 +425,7 @@ bool fromwire_${msg.name}(${'const tal_t *ctx, ' if msg.needs_context() else ''} % if f.len_field_of: ${f.name} = fromwire_${type_}(&cursor, &plen); % elif f.type_obj.is_tlv(): - fromwire_tlvs(&cursor, &plen, tlvs_${f.type_obj.tlv.name}, ARRAY_SIZE(tlvs_${f.type_obj.tlv.name}), ${f.name}); + fromwire_${f.type_obj.tlv.name}(&cursor, &plen, ${f.name}); % elif f.is_array() or f.is_varlen(): % if f.type_obj.has_array_helper(): fromwire_${type_}_array(&cursor, &plen, ${'*' if f.is_varlen() else ''}${f.name}, ${f.size('plen')}); diff --git a/wire/tlvstream.c b/wire/tlvstream.c index f5519a0d1..97af4c921 100644 --- a/wire/tlvstream.c +++ b/wire/tlvstream.c @@ -6,137 +6,6 @@ #define SUPERVERBOSE(...) #endif -static const struct tlv_record_type * -find_record_type(u64 type, - const struct tlv_record_type types[], - size_t num_types) -{ - for (size_t i = 0; i < num_types; i++) - if (types[i].type == type) - return types + i; - return NULL; -} - -/* Pull all tlvs from a stream. Return false and calls fromwire_fail() on - * error. */ -bool fromwire_tlvs(const u8 **cursor, size_t *max, - const struct tlv_record_type types[], - size_t num_types, - void *record) -{ - /* prev_type points to prev_type_store after first iter. */ - u64 prev_type_store, *prev_type = NULL; - - /* BOLT #1: - * - * The receiving node: - * - if zero bytes remain before parsing a `type`: - * - MUST stop parsing the `tlv_stream`. - */ - while (*max > 0) { - u64 type, length; - const struct tlv_record_type *rtype; - - /* BOLT #1: - * - * A `varint` is a variable-length, unsigned integer encoding - * using the [BigSize](#appendix-a-bigsize-test-vectors) - * format - */ - type = fromwire_bigsize(cursor, max); - - /* BOLT #1: - * - if a `type` or `length` is not minimally encoded: - * - MUST fail to parse the `tlv_stream`. - */ - if (!*cursor) { - SUPERVERBOSE("type"); - goto fail; - } - length = fromwire_bigsize(cursor, max); - - /* BOLT #1: - * - if a `type` or `length` is not minimally encoded: - * - MUST fail to parse the `tlv_stream`. - */ - if (!*cursor) { - SUPERVERBOSE("length"); - goto fail; - } - - /* BOLT #1: - * - if `length` exceeds the number of bytes remaining in the - * message: - * - MUST fail to parse the `tlv_stream`. - */ - if (length > *max) { - SUPERVERBOSE("value"); - goto fail; - } - - /* BOLT #1: - * - if decoded `type`s are not monotonically-increasing: - * - MUST fail to parse the `tlv_stream`. - */ - if (prev_type && type <= *prev_type) { - if (type == *prev_type) - SUPERVERBOSE("duplicate tlv type"); - else - SUPERVERBOSE("invalid ordering"); - goto fail; - } - - /* BOLT #1: - * - if `type` is known: - * - MUST decode the next `length` bytes using the known - * encoding for `type`. - */ - rtype = find_record_type(type, types, num_types); - if (rtype) { - /* Length of message can't exceed 16 bits anyway. */ - size_t tlvlen = length; - rtype->fromwire(cursor, &tlvlen, record); - - if (!*cursor) - goto fail; - - /* BOLT #1: - * - if `length` is not exactly equal to that required - * for the known encoding for `type`: - * - MUST fail to parse the `tlv_stream`. - */ - if (tlvlen != 0) { - SUPERVERBOSE("greater than encoding length"); - goto fail; - } - - /* We've read bytes in ->fromwire, so update max */ - *max -= length; - } else { - /* BOLT #1: - * - otherwise, if `type` is unknown: - * - if `type` is even: - * - MUST fail to parse the `tlv_stream`. - * - otherwise, if `type` is odd: - * - MUST discard the next `length` bytes. - */ - if (type & 1) - fromwire(cursor, max, NULL, length); - else { - SUPERVERBOSE("unknown even"); - goto fail; - } - } - prev_type = &prev_type_store; - *prev_type = type; - } - return true; - -fail: - fromwire_fail(cursor, max); - return false; -} - /* Append a stream of tlvs. */ void towire_tlvs(u8 **pptr, const struct tlv_record_type types[], diff --git a/wire/tlvstream.h b/wire/tlvstream.h index f36d42c23..256feb5e8 100644 --- a/wire/tlvstream.h +++ b/wire/tlvstream.h @@ -28,13 +28,6 @@ struct tlv_field { u8 *value; }; -/* Pull all tlvs from a stream. Return false and calls fromwire_fail() on - * error. */ -bool fromwire_tlvs(const u8 **cursor, size_t *max, - const struct tlv_record_type types[], - size_t num_types, - void *record); - /* Append a stream of tlvs: types[] must be in increasing type order! */ void towire_tlvs(u8 **pptr, const struct tlv_record_type types[],