From 5e078a81676deeb8fc860e321a3618ae372c3311 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 7 Oct 2016 17:39:55 +1030 Subject: [PATCH] pkt_init: check feature bits. Signed-off-by: Rusty Russell --- daemon/peer.c | 23 ++++++++++++++++++++++- lightning.pb-c.c | 19 ++++++++++++++++--- lightning.pb-c.h | 7 ++++++- lightning.proto | 2 ++ 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/daemon/peer.c b/daemon/peer.c index aed157824..d2530c8a0 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -2104,7 +2104,28 @@ static struct io_plan *init_pkt_in(struct io_conn *conn, struct peer *peer) state_name(peer->state))); return pkt_out(conn, peer); } - + + if (peer->inpkt->init->has_features) { + size_t i; + + for (i = 0; i < peer->inpkt->init->features.len*CHAR_BIT; i++) { + size_t byte = i / CHAR_BIT, bit = i % CHAR_BIT; + if (peer->inpkt->init->features.data[byte] & (1<log, + "They offered feature %zu", i); + continue; + } + queue_pkt_err(peer, + pkt_err(peer, + "Unsupported feature %zu", + i)); + return pkt_out(conn, peer); + } + } + } + /* Send any packets they missed. */ retransmit_pkts(peer, peer->inpkt->init->ack); diff --git a/lightning.pb-c.c b/lightning.pb-c.c index ec4bd9b4d..5f09d85b6 100644 --- a/lightning.pb-c.c +++ b/lightning.pb-c.c @@ -1644,7 +1644,7 @@ const ProtobufCMessageDescriptor authenticate__descriptor = (ProtobufCMessageInit) authenticate__init, NULL,NULL,NULL /* reserved[123] */ }; -static const ProtobufCFieldDescriptor init__field_descriptors[1] = +static const ProtobufCFieldDescriptor init__field_descriptors[2] = { { "ack", @@ -1658,14 +1658,27 @@ static const ProtobufCFieldDescriptor init__field_descriptors[1] = 0, /* flags */ 0,NULL,NULL /* reserved1,reserved2, etc */ }, + { + "features", + 2, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_BYTES, + offsetof(Init, has_features), + offsetof(Init, features), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, }; static const unsigned init__field_indices_by_name[] = { 0, /* field[0] = ack */ + 1, /* field[1] = features */ }; static const ProtobufCIntRange init__number_ranges[1 + 1] = { { 1, 0 }, - { 0, 1 } + { 0, 2 } }; const ProtobufCMessageDescriptor init__descriptor = { @@ -1675,7 +1688,7 @@ const ProtobufCMessageDescriptor init__descriptor = "Init", "", sizeof(Init), - 1, + 2, init__field_descriptors, init__field_indices_by_name, 1, init__number_ranges, diff --git a/lightning.pb-c.h b/lightning.pb-c.h index 514d2ce46..107bd14ed 100644 --- a/lightning.pb-c.h +++ b/lightning.pb-c.h @@ -194,10 +194,15 @@ struct _Init * How many update_commit and update_revocation messages already received */ uint64_t ack; + /* + * What features do we support (odd) and require (even) + */ + protobuf_c_boolean has_features; + ProtobufCBinaryData features; }; #define INIT__INIT \ { PROTOBUF_C_MESSAGE_INIT (&init__descriptor) \ - , 0 } + , 0, 0,{0,NULL} } /* diff --git a/lightning.proto b/lightning.proto index f03706984..f3aee1f6f 100644 --- a/lightning.proto +++ b/lightning.proto @@ -70,6 +70,8 @@ message authenticate { message init { // How many update_commit and update_revocation messages already received required uint64 ack = 1; + // What features do we support (odd) and require (even) + optional bytes features = 2; }; // Set channel params.