From be6322a2d32da44002501caa0f521bbb69eda2de Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 3 Dec 2018 09:35:06 +1030 Subject: [PATCH] features: add local_feature_negotiated / global_feature_negotiated helpers. We currently generally assume the features we offer are fixed; this makes the code clearer and handles where we offer features iff EXPERIMENTAL_FEATURES=1 Signed-off-by: Rusty Russell --- common/features.c | 15 +++++++++++++++ common/features.h | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/common/features.c b/common/features.c index 3a52ebf94..426cf8157 100644 --- a/common/features.c +++ b/common/features.c @@ -133,3 +133,18 @@ bool features_supported(const u8 *globalfeatures, const u8 *localfeatures) ARRAY_SIZE(our_localfeatures)); } +bool local_feature_negotiated(const u8 *lfeatures, size_t f) +{ + if (!feature_offered(lfeatures, f)) + return false; + return feature_supported(f, our_localfeatures, + ARRAY_SIZE(our_localfeatures)); +} + +bool global_feature_negotiated(const u8 *gfeatures, size_t f) +{ + if (!feature_offered(gfeatures, f)) + return false; + return feature_supported(f, our_globalfeatures, + ARRAY_SIZE(our_globalfeatures)); +} diff --git a/common/features.h b/common/features.h index 1cda1d168..5ef524f66 100644 --- a/common/features.h +++ b/common/features.h @@ -14,6 +14,10 @@ u8 *get_offered_localfeatures(const tal_t *ctx); /* Is this feature bit requested? (Either compulsory or optional) */ bool feature_offered(const u8 *features, size_t f); +/* Was this feature bit offered by them and us? */ +bool local_feature_negotiated(const u8 *lfeatures, size_t f); +bool global_feature_negotiated(const u8 *gfeatures, size_t f); + #define COMPULSORY_FEATURE(x) (x) #define OPTIONAL_FEATURE(x) ((x)+1)