Initial commit

- Rough sync.proto sketch
- Mock script
This commit is contained in:
Oskar Thoren 2018-12-18 11:47:59 +08:00
commit 444ccce864
6 changed files with 515 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
sync_pb2.pyc

10
Makefile Normal file
View File

@ -0,0 +1,10 @@
all: protoc_python
clean:
rm -rf sync_pb2.py*
protoc_python: sync.proto
protoc -I=. --python_out=. ./sync.proto
run:
python -i test.py

10
README.md Normal file
View File

@ -0,0 +1,10 @@
# BSP-spec
Goal: a Protobuf spec of https://code.briarproject.org/briar/briar-spec/blob/master/protocols/BSP.md
As well as some PoC around it
```
make
make run # see test.py
```

63
sync.proto Normal file
View File

@ -0,0 +1,63 @@
syntax = "proto3";
package sync;
// Wire format
message Record {
Header header = 1;
// XXX: How listen to thing?
Payload payload = 2;
// four-byte header - fixed-length encoding?
message Header {
// XXX: These fields should be 1, 1, 2 bytes respectively
int32 version = 1;
Type type = 2;
int32 length = 3;
}
enum Type {
// XXX: 0 is default version for enums
ACK = 0;
MESSAGE = 1;
OFFER = 2;
REQUEST = 3;
}
message Payload {
oneof payload {
Ack ack = 1;
Message message = 2;
Offer offer = 3;
Request request = 4;
}
}
// XXX: This only applies for version 1 - how would this extend?
message Ack {
repeated string id = 1;
}
message Message {
string group_id = 1;
int64 timestamp = 2;
bytes body = 3;
}
message Offer {
repeated string id = 1;
}
message Request {
repeated string id = 1;
}
}
// XXX: How do you know who the sender is?
// **2: OFFER** - The payload consists of one or more message identifiers. This record informs the recipient that the sender holds the listed messages, is sharing them with the recipient, and does not know whether the recipient holds them.

413
sync_pb2.py Normal file
View File

@ -0,0 +1,413 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: sync.proto
import sys
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection
from google.protobuf import symbol_database as _symbol_database
from google.protobuf import descriptor_pb2
# @@protoc_insertion_point(imports)
_sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor.FileDescriptor(
name='sync.proto',
package='sync',
syntax='proto3',
serialized_pb=_b('\n\nsync.proto\x12\x04sync\"\x82\x04\n\x06Record\x12#\n\x06header\x18\x01 \x01(\x0b\x32\x13.sync.Record.Header\x12%\n\x07payload\x18\x02 \x01(\x0b\x32\x14.sync.Record.Payload\x1aJ\n\x06Header\x12\x0f\n\x07version\x18\x01 \x01(\x05\x12\x1f\n\x04type\x18\x02 \x01(\x0e\x32\x11.sync.Record.Type\x12\x0e\n\x06length\x18\x03 \x01(\x05\x1a\xac\x01\n\x07Payload\x12\x1f\n\x03\x61\x63k\x18\x01 \x01(\x0b\x32\x10.sync.Record.AckH\x00\x12\'\n\x07message\x18\x02 \x01(\x0b\x32\x14.sync.Record.MessageH\x00\x12#\n\x05offer\x18\x03 \x01(\x0b\x32\x12.sync.Record.OfferH\x00\x12\'\n\x07request\x18\x04 \x01(\x0b\x32\x14.sync.Record.RequestH\x00\x42\t\n\x07payload\x1a\x11\n\x03\x41\x63k\x12\n\n\x02id\x18\x01 \x03(\t\x1a<\n\x07Message\x12\x10\n\x08group_id\x18\x01 \x01(\t\x12\x11\n\ttimestamp\x18\x02 \x01(\x03\x12\x0c\n\x04\x62ody\x18\x03 \x01(\x0c\x1a\x13\n\x05Offer\x12\n\n\x02id\x18\x01 \x03(\t\x1a\x15\n\x07Request\x12\n\n\x02id\x18\x01 \x03(\t\"4\n\x04Type\x12\x07\n\x03\x41\x43K\x10\x00\x12\x0b\n\x07MESSAGE\x10\x01\x12\t\n\x05OFFER\x10\x02\x12\x0b\n\x07REQUEST\x10\x03\x62\x06proto3')
)
_RECORD_TYPE = _descriptor.EnumDescriptor(
name='Type',
full_name='sync.Record.Type',
filename=None,
file=DESCRIPTOR,
values=[
_descriptor.EnumValueDescriptor(
name='ACK', index=0, number=0,
options=None,
type=None),
_descriptor.EnumValueDescriptor(
name='MESSAGE', index=1, number=1,
options=None,
type=None),
_descriptor.EnumValueDescriptor(
name='OFFER', index=2, number=2,
options=None,
type=None),
_descriptor.EnumValueDescriptor(
name='REQUEST', index=3, number=3,
options=None,
type=None),
],
containing_type=None,
options=None,
serialized_start=483,
serialized_end=535,
)
_sym_db.RegisterEnumDescriptor(_RECORD_TYPE)
_RECORD_HEADER = _descriptor.Descriptor(
name='Header',
full_name='sync.Record.Header',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='version', full_name='sync.Record.Header.version', index=0,
number=1, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='type', full_name='sync.Record.Header.type', index=1,
number=2, type=14, cpp_type=8, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='length', full_name='sync.Record.Header.length', index=2,
number=3, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=107,
serialized_end=181,
)
_RECORD_PAYLOAD = _descriptor.Descriptor(
name='Payload',
full_name='sync.Record.Payload',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='ack', full_name='sync.Record.Payload.ack', index=0,
number=1, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='message', full_name='sync.Record.Payload.message', index=1,
number=2, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='offer', full_name='sync.Record.Payload.offer', index=2,
number=3, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='request', full_name='sync.Record.Payload.request', index=3,
number=4, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
_descriptor.OneofDescriptor(
name='payload', full_name='sync.Record.Payload.payload',
index=0, containing_type=None, fields=[]),
],
serialized_start=184,
serialized_end=356,
)
_RECORD_ACK = _descriptor.Descriptor(
name='Ack',
full_name='sync.Record.Ack',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='id', full_name='sync.Record.Ack.id', index=0,
number=1, type=9, cpp_type=9, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=358,
serialized_end=375,
)
_RECORD_MESSAGE = _descriptor.Descriptor(
name='Message',
full_name='sync.Record.Message',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='group_id', full_name='sync.Record.Message.group_id', index=0,
number=1, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='timestamp', full_name='sync.Record.Message.timestamp', index=1,
number=2, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='body', full_name='sync.Record.Message.body', index=2,
number=3, type=12, cpp_type=9, label=1,
has_default_value=False, default_value=_b(""),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=377,
serialized_end=437,
)
_RECORD_OFFER = _descriptor.Descriptor(
name='Offer',
full_name='sync.Record.Offer',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='id', full_name='sync.Record.Offer.id', index=0,
number=1, type=9, cpp_type=9, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=439,
serialized_end=458,
)
_RECORD_REQUEST = _descriptor.Descriptor(
name='Request',
full_name='sync.Record.Request',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='id', full_name='sync.Record.Request.id', index=0,
number=1, type=9, cpp_type=9, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=460,
serialized_end=481,
)
_RECORD = _descriptor.Descriptor(
name='Record',
full_name='sync.Record',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='header', full_name='sync.Record.header', index=0,
number=1, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='payload', full_name='sync.Record.payload', index=1,
number=2, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[_RECORD_HEADER, _RECORD_PAYLOAD, _RECORD_ACK, _RECORD_MESSAGE, _RECORD_OFFER, _RECORD_REQUEST, ],
enum_types=[
_RECORD_TYPE,
],
options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=21,
serialized_end=535,
)
_RECORD_HEADER.fields_by_name['type'].enum_type = _RECORD_TYPE
_RECORD_HEADER.containing_type = _RECORD
_RECORD_PAYLOAD.fields_by_name['ack'].message_type = _RECORD_ACK
_RECORD_PAYLOAD.fields_by_name['message'].message_type = _RECORD_MESSAGE
_RECORD_PAYLOAD.fields_by_name['offer'].message_type = _RECORD_OFFER
_RECORD_PAYLOAD.fields_by_name['request'].message_type = _RECORD_REQUEST
_RECORD_PAYLOAD.containing_type = _RECORD
_RECORD_PAYLOAD.oneofs_by_name['payload'].fields.append(
_RECORD_PAYLOAD.fields_by_name['ack'])
_RECORD_PAYLOAD.fields_by_name['ack'].containing_oneof = _RECORD_PAYLOAD.oneofs_by_name['payload']
_RECORD_PAYLOAD.oneofs_by_name['payload'].fields.append(
_RECORD_PAYLOAD.fields_by_name['message'])
_RECORD_PAYLOAD.fields_by_name['message'].containing_oneof = _RECORD_PAYLOAD.oneofs_by_name['payload']
_RECORD_PAYLOAD.oneofs_by_name['payload'].fields.append(
_RECORD_PAYLOAD.fields_by_name['offer'])
_RECORD_PAYLOAD.fields_by_name['offer'].containing_oneof = _RECORD_PAYLOAD.oneofs_by_name['payload']
_RECORD_PAYLOAD.oneofs_by_name['payload'].fields.append(
_RECORD_PAYLOAD.fields_by_name['request'])
_RECORD_PAYLOAD.fields_by_name['request'].containing_oneof = _RECORD_PAYLOAD.oneofs_by_name['payload']
_RECORD_ACK.containing_type = _RECORD
_RECORD_MESSAGE.containing_type = _RECORD
_RECORD_OFFER.containing_type = _RECORD
_RECORD_REQUEST.containing_type = _RECORD
_RECORD.fields_by_name['header'].message_type = _RECORD_HEADER
_RECORD.fields_by_name['payload'].message_type = _RECORD_PAYLOAD
_RECORD_TYPE.containing_type = _RECORD
DESCRIPTOR.message_types_by_name['Record'] = _RECORD
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
Record = _reflection.GeneratedProtocolMessageType('Record', (_message.Message,), dict(
Header = _reflection.GeneratedProtocolMessageType('Header', (_message.Message,), dict(
DESCRIPTOR = _RECORD_HEADER,
__module__ = 'sync_pb2'
# @@protoc_insertion_point(class_scope:sync.Record.Header)
))
,
Payload = _reflection.GeneratedProtocolMessageType('Payload', (_message.Message,), dict(
DESCRIPTOR = _RECORD_PAYLOAD,
__module__ = 'sync_pb2'
# @@protoc_insertion_point(class_scope:sync.Record.Payload)
))
,
Ack = _reflection.GeneratedProtocolMessageType('Ack', (_message.Message,), dict(
DESCRIPTOR = _RECORD_ACK,
__module__ = 'sync_pb2'
# @@protoc_insertion_point(class_scope:sync.Record.Ack)
))
,
Message = _reflection.GeneratedProtocolMessageType('Message', (_message.Message,), dict(
DESCRIPTOR = _RECORD_MESSAGE,
__module__ = 'sync_pb2'
# @@protoc_insertion_point(class_scope:sync.Record.Message)
))
,
Offer = _reflection.GeneratedProtocolMessageType('Offer', (_message.Message,), dict(
DESCRIPTOR = _RECORD_OFFER,
__module__ = 'sync_pb2'
# @@protoc_insertion_point(class_scope:sync.Record.Offer)
))
,
Request = _reflection.GeneratedProtocolMessageType('Request', (_message.Message,), dict(
DESCRIPTOR = _RECORD_REQUEST,
__module__ = 'sync_pb2'
# @@protoc_insertion_point(class_scope:sync.Record.Request)
))
,
DESCRIPTOR = _RECORD,
__module__ = 'sync_pb2'
# @@protoc_insertion_point(class_scope:sync.Record)
))
_sym_db.RegisterMessage(Record)
_sym_db.RegisterMessage(Record.Header)
_sym_db.RegisterMessage(Record.Payload)
_sym_db.RegisterMessage(Record.Ack)
_sym_db.RegisterMessage(Record.Message)
_sym_db.RegisterMessage(Record.Offer)
_sym_db.RegisterMessage(Record.Request)
# @@protoc_insertion_point(module_scope)

18
test.py Normal file
View File

@ -0,0 +1,18 @@
# XXX: Shouldn't it be pb3?
import sync_pb2
msg = sync_pb2.Record()
msg.header.version = 1
# assert based on type and length
msg.header.type = 1
msg.header.length = 10
msg.payload.message.group_id = "foo"
msg.payload.message.timestamp = 10
msg.payload.message.body = "hello"
# need to be bytes
acks = sync_pb2.Record()
acks.header.version = 1
# XXX: not showing up if version is 0
acks.header.type = 0
acks.header.length = 10
acks.payload.ack.id.extend(["a", "b"])