Use localfeatures and globalfeatures consistently.

That's what BOLT #1 calls them; make it easier for people to grep.

Reported-by: @niftynei
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2018-09-28 12:54:24 +09:30
parent 15e8801285
commit 41b0872f58
14 changed files with 111 additions and 103 deletions

View File

@ -3,13 +3,13 @@
#include <ccan/array_size/array_size.h>
#include <wire/peer_wire.h>
static const u32 local_features[] = {
static const u32 our_localfeatures[] = {
LOCAL_DATA_LOSS_PROTECT,
LOCAL_INITIAL_ROUTING_SYNC,
LOCAL_GOSSIP_QUERIES
};
static const u32 global_features[] = {
static const u32 our_globalfeatures[] = {
};
/* BOLT #1:
@ -46,14 +46,16 @@ static u8 *mkfeatures(const tal_t *ctx, const u32 *arr, size_t n)
return f;
}
u8 *get_offered_global_features(const tal_t *ctx)
u8 *get_offered_globalfeatures(const tal_t *ctx)
{
return mkfeatures(ctx, global_features, ARRAY_SIZE(global_features));
return mkfeatures(ctx,
our_globalfeatures, ARRAY_SIZE(our_globalfeatures));
}
u8 *get_offered_local_features(const tal_t *ctx)
u8 *get_offered_localfeatures(const tal_t *ctx)
{
return mkfeatures(ctx, local_features, ARRAY_SIZE(local_features));
return mkfeatures(ctx,
our_localfeatures, ARRAY_SIZE(our_localfeatures));
}
static bool feature_set(const u8 *features, size_t bit)
@ -115,19 +117,19 @@ static bool all_supported_features(const u8 *bitmap,
return true;
}
bool features_supported(const u8 *gfeatures, const u8 *lfeatures)
bool features_supported(const u8 *globalfeatures, const u8 *localfeatures)
{
/* BIT 2 would logically be "compulsory initial_routing_sync", but
* that does not exist, so we special case it. */
if (feature_set(lfeatures,
if (feature_set(localfeatures,
COMPULSORY_FEATURE(LOCAL_INITIAL_ROUTING_SYNC)))
return false;
return all_supported_features(gfeatures,
global_features,
ARRAY_SIZE(global_features))
&& all_supported_features(lfeatures,
local_features,
ARRAY_SIZE(local_features));
return all_supported_features(globalfeatures,
our_globalfeatures,
ARRAY_SIZE(our_globalfeatures))
&& all_supported_features(localfeatures,
our_localfeatures,
ARRAY_SIZE(our_localfeatures));
}

View File

@ -7,9 +7,9 @@
/* Returns true if we're OK with all these offered features. */
bool features_supported(const u8 *gfeatures, const u8 *lfeatures);
/* For sending our features: tal_len() returns length. */
u8 *get_offered_global_features(const tal_t *ctx);
u8 *get_offered_local_features(const tal_t *ctx);
/* For sending our features: tal_count() returns length. */
u8 *get_offered_globalfeatures(const tal_t *ctx);
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);

View File

@ -64,8 +64,8 @@ int main(void)
assert(features_supported(bits, bits));
/* We must support our own features. */
lf = get_offered_global_features(tmpctx);
gf = get_offered_global_features(tmpctx);
lf = get_offered_globalfeatures(tmpctx);
gf = get_offered_globalfeatures(tmpctx);
assert(features_supported(gf, lf));
/* We can add random odd features, no problem. */
@ -89,15 +89,15 @@ int main(void)
assert(!features_supported(gf, bits));
} else {
assert(features_supported(gf, bits)
== feature_supported(i, local_features,
ARRAY_SIZE(local_features)));
== feature_supported(i, our_localfeatures,
ARRAY_SIZE(our_localfeatures)));
}
bits = tal_dup_arr(tmpctx, u8, gf, tal_count(gf), 0);
set_bit(&bits, i);
assert(features_supported(bits, lf)
== feature_supported(i, global_features,
ARRAY_SIZE(global_features)));
== feature_supported(i, our_globalfeatures,
ARRAY_SIZE(our_globalfeatures)));
}
wally_cleanup(0);

View File

@ -5,9 +5,9 @@
connectctl_init,2000
connectctl_init,,id,struct pubkey
connectctl_init,,gflen,u16
connectctl_init,,gfeatures,gflen*u8
connectctl_init,,globalfeatures,gflen*u8
connectctl_init,,lflen,u16
connectctl_init,,lfeatures,lflen*u8
connectctl_init,,localfeatures,lflen*u8
connectctl_init,,num_wireaddrs,u16
connectctl_init,,wireaddrs,num_wireaddrs*struct wireaddr_internal
connectctl_init,,listen_announce,num_wireaddrs*enum addr_listen_announce
@ -55,9 +55,9 @@ connect_peer_connected,,id,struct pubkey
connect_peer_connected,,addr,struct wireaddr_internal
connect_peer_connected,,crypto_state,struct crypto_state
connect_peer_connected,,gflen,u16
connect_peer_connected,,gfeatures,gflen*u8
connect_peer_connected,,globalfeatures,gflen*u8
connect_peer_connected,,lflen,u16
connect_peer_connected,,lfeatures,lflen*u8
connect_peer_connected,,localfeatures,lflen*u8
# master -> connectd: peer has disconnected.
connectctl_peer_disconnected,2015

1 #include <common/cryptomsg.h>
5 connectctl_init,,id,struct pubkey
6 connectctl_init,,gflen,u16
7 connectctl_init,,gfeatures,gflen*u8 connectctl_init,,globalfeatures,gflen*u8
8 connectctl_init,,lflen,u16
9 connectctl_init,,lfeatures,lflen*u8 connectctl_init,,localfeatures,lflen*u8
10 connectctl_init,,num_wireaddrs,u16
11 connectctl_init,,wireaddrs,num_wireaddrs*struct wireaddr_internal
12 connectctl_init,,listen_announce,num_wireaddrs*enum addr_listen_announce
13 connectctl_init,,tor_proxyaddr,?struct wireaddr
55 connectctl_peer_disconnected,,id,struct pubkey
56
57
58
59
60
61
62
63

View File

@ -274,12 +274,12 @@ static void connected_to_peer(struct daemon *daemon,
* it to forward gossip to/from the peer. The gossip daemon needs to know a
* few of the features of the peer and its id (for reporting).
*
* The 'lfeatures' refers to 'local features', which indicate the properties
* when you're connected to it like we are: there are also 'global features'
* The 'localfeatures' is a field in the `init` message, indicating properties
* when you're connected to it like we are: there are also 'globalfeatures'
* which specify requirements to route a payment through a node. */
static int get_gossipfd(struct daemon *daemon,
const struct pubkey *id,
const u8 *lfeatures)
const u8 *localfeatures)
{
bool gossip_queries_feature, initial_routing_sync, success;
u8 *msg;
@ -287,7 +287,7 @@ static int get_gossipfd(struct daemon *daemon,
/*~ The way features generally work is that both sides need to offer it;
* we always offer `gossip_queries`, but this check is explicit. */
gossip_queries_feature
= feature_offered(lfeatures, LOCAL_GOSSIP_QUERIES)
= feature_offered(localfeatures, LOCAL_GOSSIP_QUERIES)
&& feature_offered(daemon->localfeatures,
LOCAL_GOSSIP_QUERIES);
@ -295,7 +295,7 @@ static int get_gossipfd(struct daemon *daemon,
* the initial lightning specification: it means the peer wants the
* backlog of existing gossip. */
initial_routing_sync
= feature_offered(lfeatures, LOCAL_INITIAL_ROUTING_SYNC);
= feature_offered(localfeatures, LOCAL_INITIAL_ROUTING_SYNC);
/*~ We do this communication sync, since gossipd is our friend and
* it's easier. If gossipd fails, we fail. */
@ -331,7 +331,7 @@ struct peer_reconnected {
struct daemon *daemon;
struct pubkey id;
const u8 *peer_connected_msg;
const u8 *lfeatures;
const u8 *localfeatures;
};
/*~ For simplicity, lightningd only ever deals with a single connection per
@ -350,7 +350,7 @@ static struct io_plan *retry_peer_connected(struct io_conn *conn,
* our temporary structure. */
plan = peer_connected(conn, pr->daemon, &pr->id,
take(pr->peer_connected_msg),
take(pr->lfeatures));
take(pr->localfeatures));
tal_free(pr);
return plan;
}
@ -361,7 +361,7 @@ static struct io_plan *peer_reconnected(struct io_conn *conn,
struct daemon *daemon,
const struct pubkey *id,
const u8 *peer_connected_msg TAKES,
const u8 *lfeatures TAKES)
const u8 *localfeatures TAKES)
{
u8 *msg;
struct peer_reconnected *r;
@ -379,13 +379,13 @@ static struct io_plan *peer_reconnected(struct io_conn *conn,
r->id = *id;
/*~ Note that tal_dup_arr() will do handle the take() of
* peer_connected_msg and lfeatures (turning it into a simply
* peer_connected_msg and localfeatures (turning it into a simply
* tal_steal() in those cases). */
r->peer_connected_msg
= tal_dup_arr(r, u8, peer_connected_msg,
tal_count(peer_connected_msg), 0);
r->lfeatures
= tal_dup_arr(r, u8, lfeatures, tal_count(lfeatures), 0);
r->localfeatures
= tal_dup_arr(r, u8, localfeatures, tal_count(localfeatures), 0);
/*~ ccan/io supports waiting on an address: in this case, the key in
* the peer set. When someone calls `io_wake()` on that address, it
@ -400,22 +400,22 @@ struct io_plan *peer_connected(struct io_conn *conn,
struct daemon *daemon,
const struct pubkey *id,
const u8 *peer_connected_msg TAKES,
const u8 *lfeatures TAKES)
const u8 *localfeatures TAKES)
{
int gossip_fd;
if (pubkey_set_get(&daemon->peers, id))
return peer_reconnected(conn, daemon, id, peer_connected_msg,
lfeatures);
localfeatures);
/* We've successfully connected. */
connected_to_peer(daemon, conn, id);
gossip_fd = get_gossipfd(daemon, id, lfeatures);
gossip_fd = get_gossipfd(daemon, id, localfeatures);
/* We promised we'd take it by marking it TAKEN above; simply free it. */
if (taken(lfeatures))
tal_free(lfeatures);
if (taken(localfeatures))
tal_free(localfeatures);
/* If gossipd can't give us a file descriptor, we give up connecting. */
if (gossip_fd < 0)

View File

@ -33,7 +33,7 @@ static struct io_plan *peer_init_received(struct io_conn *conn,
struct peer *peer)
{
u8 *msg = cryptomsg_decrypt_body(peer, &peer->cs, peer->msg);
u8 *gfeatures, *lfeatures;
u8 *globalfeatures, *localfeatures;
if (!msg)
return io_close(conn);
@ -49,7 +49,7 @@ static struct io_plan *peer_init_received(struct io_conn *conn,
if (unlikely(is_unknown_msg_discardable(msg)))
return read_init(conn, peer);
if (!fromwire_init(peer, msg, &gfeatures, &lfeatures)) {
if (!fromwire_init(peer, msg, &globalfeatures, &localfeatures)) {
status_trace("peer %s bad fromwire_init '%s', closing",
type_to_string(tmpctx, struct pubkey, &peer->id),
tal_hex(tmpctx, msg));
@ -65,28 +65,29 @@ static struct io_plan *peer_init_received(struct io_conn *conn,
* - upon receiving unknown _even_ feature bits that are non-zero:
* - MUST fail the connection.
*/
if (!features_supported(gfeatures, lfeatures)) {
const u8 *global_features = get_offered_global_features(msg);
const u8 *local_features = get_offered_local_features(msg);
if (!features_supported(globalfeatures, localfeatures)) {
const u8 *our_globalfeatures = get_offered_globalfeatures(msg);
const u8 *our_localfeatures = get_offered_localfeatures(msg);
msg = towire_errorfmt(NULL, NULL, "Unsupported features %s/%s:"
" we only offer globalfeatures %s"
" and localfeatures %s",
tal_hex(msg, gfeatures),
tal_hex(msg, lfeatures),
tal_hex(msg, global_features),
tal_hex(msg, local_features));
tal_hex(msg, globalfeatures),
tal_hex(msg, localfeatures),
tal_hex(msg, our_globalfeatures),
tal_hex(msg, our_localfeatures));
msg = cryptomsg_encrypt_msg(NULL, &peer->cs, take(msg));
return io_write(conn, msg, tal_count(msg), io_close_cb, NULL);
}
/* Create message to tell master peer has connected. */
msg = towire_connect_peer_connected(NULL, &peer->id, &peer->addr,
&peer->cs, gfeatures, lfeatures);
&peer->cs,
globalfeatures, localfeatures);
/* Usually return io_close_taken_fd, but may wait for old peer to
* be disconnected if it's a reconnect. */
return peer_connected(conn, peer->daemon, &peer->id,
take(msg), take(lfeatures));
take(msg), take(localfeatures));
}
static struct io_plan *peer_init_hdr_received(struct io_conn *conn,
@ -149,8 +150,8 @@ struct io_plan *peer_exchange_initmsg(struct io_conn *conn,
* connection.
*/
peer->msg = towire_init(NULL,
get_offered_global_features(tmpctx),
get_offered_local_features(tmpctx));
get_offered_globalfeatures(tmpctx),
get_offered_localfeatures(tmpctx));
status_peer_io(LOG_IO_OUT, peer->msg);
peer->msg = cryptomsg_encrypt_msg(peer, &peer->cs, take(peer->msg));

View File

@ -108,15 +108,15 @@ static struct io_plan *handshake_success(struct io_conn *conn,
{
u8 *msg;
struct crypto_state cs = *orig_cs;
u8 *local_features;
u8 *localfeatures;
if (initial_sync) {
local_features = tal(conn, u8);
local_features[0] = (1 << 3);
localfeatures = tal(conn, u8);
localfeatures[0] = (1 << 3);
} else
local_features = NULL;
localfeatures = NULL;
msg = towire_init(NULL, NULL, local_features);
msg = towire_init(NULL, NULL, localfeatures);
sync_crypto_write(&cs, conn->fd, take(msg));
/* Ignore their init message. */

View File

@ -1393,7 +1393,7 @@ static struct io_plan *getchannels_req(struct io_conn *conn, struct daemon *daem
static void append_node(const struct gossip_getnodes_entry ***nodes,
const struct pubkey *nodeid,
const u8 *gfeatures,
const u8 *globalfeatures,
/* If non-NULL, contains more information */
const struct node *n)
{
@ -1401,8 +1401,8 @@ static void append_node(const struct gossip_getnodes_entry ***nodes,
new = tal(*nodes, struct gossip_getnodes_entry);
new->nodeid = *nodeid;
new->global_features = tal_dup_arr(*nodes, u8, gfeatures,
tal_count(gfeatures), 0);
new->globalfeatures = tal_dup_arr(*nodes, u8, globalfeatures,
tal_count(globalfeatures), 0);
if (!n || n->last_timestamp < 0) {
new->last_timestamp = -1;
new->addresses = NULL;

View File

@ -364,8 +364,8 @@ int connectd_init(struct lightningd *ld)
msg = towire_connectctl_init(
tmpctx, &ld->id,
get_offered_global_features(tmpctx),
get_offered_local_features(tmpctx), wireaddrs,
get_offered_globalfeatures(tmpctx),
get_offered_localfeatures(tmpctx), wireaddrs,
listen_announce,
ld->proxyaddr, ld->use_proxy_always || ld->pure_tor_setup,
allow_localhost, ld->config.use_dns,

View File

@ -161,7 +161,7 @@ void gossip_init(struct lightningd *ld, int connectd_fd)
msg = towire_gossipctl_init(
tmpctx, ld->config.broadcast_interval,
&get_chainparams(ld)->genesis_blockhash, &ld->id,
get_offered_global_features(tmpctx),
get_offered_globalfeatures(tmpctx),
ld->rgb,
ld->alias, ld->config.channel_update_interval,
ld->announcable);
@ -207,7 +207,7 @@ static void json_getnodes_reply(struct subd *gossip UNUSED, const u8 *reply,
json_add_u64(response, "last_timestamp",
nodes[i]->last_timestamp);
json_add_hex_talarr(response, "global_features",
nodes[i]->global_features);
nodes[i]->globalfeatures);
json_array_start(response, "addresses");
for (j=0; j<tal_count(nodes[i]->addresses); j++) {
json_add_address(response, NULL, &nodes[i]->addresses[j]);

View File

@ -13,8 +13,8 @@ struct gossip_getnodes_entry *fromwire_gossip_getnodes_entry(const tal_t *ctx,
fromwire_pubkey(pptr, max, &entry->nodeid);
flen = fromwire_u16(pptr, max);
entry->global_features = tal_arr(entry, u8, flen);
fromwire_u8_array(pptr, max, entry->global_features, flen);
entry->globalfeatures = tal_arr(entry, u8, flen);
fromwire_u8_array(pptr, max, entry->globalfeatures, flen);
entry->last_timestamp = fromwire_u64(pptr, max);
if (entry->last_timestamp < 0) {
@ -45,9 +45,9 @@ void towire_gossip_getnodes_entry(u8 **pptr,
{
u8 i, numaddresses = tal_count(entry->addresses);
towire_pubkey(pptr, &entry->nodeid);
towire_u16(pptr, tal_count(entry->global_features));
towire_u8_array(pptr, entry->global_features,
tal_count(entry->global_features));
towire_u16(pptr, tal_count(entry->globalfeatures));
towire_u8_array(pptr, entry->globalfeatures,
tal_count(entry->globalfeatures));
towire_u64(pptr, entry->last_timestamp);
if (entry->last_timestamp < 0)
@ -118,19 +118,19 @@ fromwire_peer_features(const tal_t *ctx, const u8 **pptr, size_t *max)
size_t len;
len = fromwire_u16(pptr, max);
pf->local_features = tal_arr(pf, u8, len);
fromwire_u8_array(pptr, max, pf->local_features, len);
pf->localfeatures = tal_arr(pf, u8, len);
fromwire_u8_array(pptr, max, pf->localfeatures, len);
len = fromwire_u16(pptr, max);
pf->global_features = tal_arr(pf, u8, len);
fromwire_u8_array(pptr, max, pf->global_features, len);
pf->globalfeatures = tal_arr(pf, u8, len);
fromwire_u8_array(pptr, max, pf->globalfeatures, len);
return pf;
}
void towire_peer_features(u8 **pptr, const struct peer_features *pf)
{
towire_u16(pptr, tal_count(pf->local_features));
towire_u8_array(pptr, pf->local_features, tal_count(pf->local_features));
towire_u16(pptr, tal_count(pf->global_features));
towire_u8_array(pptr, pf->global_features, tal_count(pf->global_features));
towire_u16(pptr, tal_count(pf->localfeatures));
towire_u8_array(pptr, pf->localfeatures, tal_count(pf->localfeatures));
towire_u16(pptr, tal_count(pf->globalfeatures));
towire_u8_array(pptr, pf->globalfeatures, tal_count(pf->globalfeatures));
}

View File

@ -5,13 +5,13 @@
#include <gossipd/routing.h>
struct peer_features {
u8 *local_features;
u8 *global_features;
u8 *localfeatures;
u8 *globalfeatures;
};
struct gossip_getnodes_entry {
struct pubkey nodeid;
u8 *global_features;
u8 *globalfeatures;
s64 last_timestamp; /* -1 means never: following fields ignored */
struct wireaddr *addresses;
u8 *alias;

View File

@ -79,21 +79,24 @@ static void copy_to_parent_log(const char *prefix,
}
static void peer_update_features(struct peer *peer,
const u8 *gfeatures TAKES,
const u8 *lfeatures TAKES)
const u8 *globalfeatures TAKES,
const u8 *localfeatures TAKES)
{
tal_free(peer->global_features);
tal_free(peer->local_features);
peer->global_features = tal_dup_arr(peer, u8,
gfeatures, tal_count(gfeatures), 0);
peer->local_features = tal_dup_arr(peer, u8,
lfeatures, tal_count(lfeatures), 0);
tal_free(peer->globalfeatures);
tal_free(peer->localfeatures);
peer->globalfeatures = tal_dup_arr(peer, u8,
globalfeatures,
tal_count(globalfeatures), 0);
peer->localfeatures = tal_dup_arr(peer, u8,
localfeatures,
tal_count(localfeatures), 0);
}
struct peer *new_peer(struct lightningd *ld, u64 dbid,
const struct pubkey *id,
const struct wireaddr_internal *addr,
const u8 *gfeatures TAKES, const u8 *lfeatures TAKES)
const u8 *globalfeatures TAKES,
const u8 *localfeatures TAKES)
{
/* We are owned by our channels, and freed manually by destroy_channel */
struct peer *peer = tal(NULL, struct peer);
@ -109,8 +112,8 @@ struct peer *new_peer(struct lightningd *ld, u64 dbid,
peer->addr.itype = ADDR_INTERNAL_WIREADDR;
peer->addr.u.wireaddr.type = ADDR_TYPE_PADDING;
}
peer->global_features = peer->local_features = NULL;
peer_update_features(peer, gfeatures, lfeatures);
peer->globalfeatures = peer->localfeatures = NULL;
peer_update_features(peer, globalfeatures, localfeatures);
list_head_init(&peer->channels);
peer->direction = get_channel_direction(&peer->ld->id, &peer->id);
@ -419,7 +422,7 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
{
struct pubkey id;
struct crypto_state cs;
u8 *gfeatures, *lfeatures;
u8 *globalfeatures, *localfeatures;
u8 *error;
struct channel *channel;
struct wireaddr_internal addr;
@ -427,7 +430,7 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
if (!fromwire_connect_peer_connected(msg, msg,
&id, &addr, &cs,
&gfeatures, &lfeatures))
&globalfeatures, &localfeatures))
fatal("Connectd gave bad CONNECT_PEER_CONNECTED message %s",
tal_hex(msg, msg));
@ -438,9 +441,10 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
* subdaemon. Otherwise, we'll hand to openingd to wait there. */
peer = peer_by_id(ld, &id);
if (!peer)
peer = new_peer(ld, 0, &id, &addr, gfeatures, lfeatures);
peer = new_peer(ld, 0, &id, &addr,
globalfeatures, localfeatures);
else
peer_update_features(peer, gfeatures, lfeatures);
peer_update_features(peer, globalfeatures, localfeatures);
/* Can't be opening, since we wouldn't have sent peer_disconnected. */
assert(!peer->uncommitted_channel);
@ -676,10 +680,10 @@ static void json_add_peer(struct lightningd *ld,
&p->addr));
json_array_end(response);
json_add_hex_talarr(response, "global_features",
p->global_features);
p->globalfeatures);
json_add_hex_talarr(response, "local_features",
p->local_features);
p->localfeatures);
}
json_array_start(response, "channels");

View File

@ -42,7 +42,7 @@ struct peer {
struct wireaddr_internal addr;
/* We keep a copy of their feature bits */
const u8 *local_features, *global_features;
const u8 *localfeatures, *globalfeatures;
/* If we open a channel our direction will be this */
u8 direction;
@ -58,7 +58,8 @@ struct peer *find_peer_by_dbid(struct lightningd *ld, u64 dbid);
struct peer *new_peer(struct lightningd *ld, u64 dbid,
const struct pubkey *id,
const struct wireaddr_internal *addr,
const u8 *gfeatures TAKES, const u8 *lfeatures TAKES);
const u8 *globalfeatures TAKES,
const u8 *localfeatures TAKES);
/* Last one out deletes peer. Also removes from db. */
void maybe_delete_peer(struct peer *peer);