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 <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2018-12-03 09:35:06 +10:30 committed by Christian Decker
parent fab5027d64
commit be6322a2d3
2 changed files with 19 additions and 0 deletions

View file

@ -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));
}

View file

@ -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)