proto: Added nested_pkt

This is mainly used to transport the new, standardized protocol, over
the old legacy transport. Allows us to replace the serialization and
transport gradually instead of all at once.
This commit is contained in:
Christian Decker 2016-11-14 16:00:47 +01:00 committed by Rusty Russell
parent 811fab4850
commit 1c4d4f8c91
3 changed files with 165 additions and 5 deletions

View File

@ -1125,6 +1125,49 @@ void error__free_unpacked
assert(message->base.descriptor == &error__descriptor);
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void nested_pkt__init
(NestedPkt *message)
{
static NestedPkt init_value = NESTED_PKT__INIT;
*message = init_value;
}
size_t nested_pkt__get_packed_size
(const NestedPkt *message)
{
assert(message->base.descriptor == &nested_pkt__descriptor);
return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t nested_pkt__pack
(const NestedPkt *message,
uint8_t *out)
{
assert(message->base.descriptor == &nested_pkt__descriptor);
return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t nested_pkt__pack_to_buffer
(const NestedPkt *message,
ProtobufCBuffer *buffer)
{
assert(message->base.descriptor == &nested_pkt__descriptor);
return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
NestedPkt *
nested_pkt__unpack
(ProtobufCAllocator *allocator,
size_t len,
const uint8_t *data)
{
return (NestedPkt *)
protobuf_c_message_unpack (&nested_pkt__descriptor,
allocator, len, data);
}
void nested_pkt__free_unpacked
(NestedPkt *message,
ProtobufCAllocator *allocator)
{
assert(message->base.descriptor == &nested_pkt__descriptor);
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void pkt__init
(Pkt *message)
{
@ -2682,7 +2725,58 @@ const ProtobufCMessageDescriptor error__descriptor =
(ProtobufCMessageInit) error__init,
NULL,NULL,NULL /* reserved[123] */
};
static const ProtobufCFieldDescriptor pkt__field_descriptors[15] =
static const ProtobufCFieldDescriptor nested_pkt__field_descriptors[2] =
{
{
"type",
1,
PROTOBUF_C_LABEL_REQUIRED,
PROTOBUF_C_TYPE_UINT32,
0, /* quantifier_offset */
offsetof(NestedPkt, type),
NULL,
NULL,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"inner_pkt",
2,
PROTOBUF_C_LABEL_REQUIRED,
PROTOBUF_C_TYPE_BYTES,
0, /* quantifier_offset */
offsetof(NestedPkt, inner_pkt),
NULL,
NULL,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
};
static const unsigned nested_pkt__field_indices_by_name[] = {
1, /* field[1] = inner_pkt */
0, /* field[0] = type */
};
static const ProtobufCIntRange nested_pkt__number_ranges[1 + 1] =
{
{ 1, 0 },
{ 0, 2 }
};
const ProtobufCMessageDescriptor nested_pkt__descriptor =
{
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
"nested_pkt",
"NestedPkt",
"NestedPkt",
"",
sizeof(NestedPkt),
2,
nested_pkt__field_descriptors,
nested_pkt__field_indices_by_name,
1, nested_pkt__number_ranges,
(ProtobufCMessageInit) nested_pkt__init,
NULL,NULL,NULL /* reserved[123] */
};
static const ProtobufCFieldDescriptor pkt__field_descriptors[16] =
{
{
"update_add_htlc",
@ -2864,6 +2958,18 @@ static const ProtobufCFieldDescriptor pkt__field_descriptors[15] =
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"nested",
128,
PROTOBUF_C_LABEL_OPTIONAL,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(Pkt, pkt_case),
offsetof(Pkt, nested),
&nested_pkt__descriptor,
NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
};
static const unsigned pkt__field_indices_by_name[] = {
13, /* field[13] = auth */
@ -2871,6 +2977,7 @@ static const unsigned pkt__field_indices_by_name[] = {
11, /* field[11] = close_signature */
12, /* field[12] = error */
14, /* field[14] = init */
15, /* field[15] = nested */
6, /* field[6] = open */
7, /* field[7] = open_anchor */
8, /* field[8] = open_commit_sig */
@ -2882,14 +2989,15 @@ static const unsigned pkt__field_indices_by_name[] = {
1, /* field[1] = update_fulfill_htlc */
5, /* field[5] = update_revocation */
};
static const ProtobufCIntRange pkt__number_ranges[5 + 1] =
static const ProtobufCIntRange pkt__number_ranges[6 + 1] =
{
{ 2, 0 },
{ 20, 6 },
{ 30, 10 },
{ 40, 12 },
{ 50, 13 },
{ 0, 15 }
{ 128, 15 },
{ 0, 16 }
};
const ProtobufCMessageDescriptor pkt__descriptor =
{
@ -2899,10 +3007,10 @@ const ProtobufCMessageDescriptor pkt__descriptor =
"Pkt",
"",
sizeof(Pkt),
15,
16,
pkt__field_descriptors,
pkt__field_indices_by_name,
5, pkt__number_ranges,
6, pkt__number_ranges,
(ProtobufCMessageInit) pkt__init,
NULL,NULL,NULL /* reserved[123] */
};

View File

@ -41,6 +41,7 @@ typedef struct _UpdateRevocation UpdateRevocation;
typedef struct _CloseShutdown CloseShutdown;
typedef struct _CloseSignature CloseSignature;
typedef struct _Error Error;
typedef struct _NestedPkt NestedPkt;
typedef struct _Pkt Pkt;
@ -546,6 +547,20 @@ struct _Error
, NULL }
/*
* Nested message to transport standard protocol messages through the legacy transport
*/
struct _NestedPkt
{
ProtobufCMessage base;
uint32_t type;
ProtobufCBinaryData inner_pkt;
};
#define NESTED_PKT__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&nested_pkt__descriptor) \
, 0, {0,NULL} }
typedef enum {
PKT__PKT__NOT_SET = 0,
PKT__PKT_AUTH = 50,
@ -563,6 +578,7 @@ typedef enum {
PKT__PKT_CLOSE_SHUTDOWN = 30,
PKT__PKT_CLOSE_SIGNATURE = 31,
PKT__PKT_ERROR = 40,
PKT__PKT_NESTED = 128,
} Pkt__PktCase;
/*
@ -603,6 +619,10 @@ struct _Pkt
* Unexpected issue.
*/
Error *error;
/*
* Shim to upgrade to new packet format
*/
NestedPkt *nested;
};
};
#define PKT__INIT \
@ -1104,6 +1124,25 @@ Error *
void error__free_unpacked
(Error *message,
ProtobufCAllocator *allocator);
/* NestedPkt methods */
void nested_pkt__init
(NestedPkt *message);
size_t nested_pkt__get_packed_size
(const NestedPkt *message);
size_t nested_pkt__pack
(const NestedPkt *message,
uint8_t *out);
size_t nested_pkt__pack_to_buffer
(const NestedPkt *message,
ProtobufCBuffer *buffer);
NestedPkt *
nested_pkt__unpack
(ProtobufCAllocator *allocator,
size_t len,
const uint8_t *data);
void nested_pkt__free_unpacked
(NestedPkt *message,
ProtobufCAllocator *allocator);
/* Pkt methods */
void pkt__init
(Pkt *message);
@ -1203,6 +1242,9 @@ typedef void (*CloseSignature_Closure)
typedef void (*Error_Closure)
(const Error *message,
void *closure_data);
typedef void (*NestedPkt_Closure)
(const NestedPkt *message,
void *closure_data);
typedef void (*Pkt_Closure)
(const Pkt *message,
void *closure_data);
@ -1239,6 +1281,7 @@ extern const ProtobufCMessageDescriptor update_revocation__descriptor;
extern const ProtobufCMessageDescriptor close_shutdown__descriptor;
extern const ProtobufCMessageDescriptor close_signature__descriptor;
extern const ProtobufCMessageDescriptor error__descriptor;
extern const ProtobufCMessageDescriptor nested_pkt__descriptor;
extern const ProtobufCMessageDescriptor pkt__descriptor;
PROTOBUF_C__END_DECLS

View File

@ -223,6 +223,12 @@ message error {
optional string problem = 1;
}
// Nested message to transport standard protocol messages through the legacy transport
message nested_pkt {
required uint32 type = 1;
required bytes inner_pkt = 2;
}
// This is the union which defines all of them
message pkt {
oneof pkt {
@ -249,5 +255,8 @@ message pkt {
// Unexpected issue.
error error = 40;
// Shim to upgrade to new packet format
nested_pkt nested = 128;
}
}