mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 22:45:27 +01:00
pkt_init: check feature bits.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
ec64e7756e
commit
5e078a8167
4 changed files with 46 additions and 5 deletions
|
@ -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<<bit)) {
|
||||
/* Can't handle even features. */
|
||||
if (i % 2 != 0) {
|
||||
log_debug(peer->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);
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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} }
|
||||
|
||||
|
||||
/*
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Reference in a new issue