Merge pull request #506 from libp2p/marco/proto3

Recommend proto3
This commit is contained in:
Marco Munizaga
2023-01-23 10:24:22 -08:00
committed by GitHub
13 changed files with 33 additions and 3 deletions

View File

@@ -70,7 +70,14 @@ and are used throughout the system.
These specs define wire protocols that are used by libp2p for connectivity, These specs define wire protocols that are used by libp2p for connectivity,
security, multiplexing, and other purposes. security, multiplexing, and other purposes.
The protocols described below all use [protocol buffers](https://developers.google.com/protocol-buffers/docs/proto?hl=en) (aka protobuf) to define message schemas. Version `proto2` is used unless stated otherwise. The protocols described below all use [protocol
buffers](https://developers.google.com/protocol-buffers/docs/proto?hl=en) (aka
protobuf) to define message schemas.
Existing protocols may use `proto2`, and continue to use them. `proto3` is
recommended for new protocols. `proto3` is a simplification of `proto2` and
removes some footguns. For context and a discussion around `proto3` vs `proto2`,
see [#465](https://github.com/libp2p/specs/issues/465).
- [ping][spec_ping] - Ping protocol - [ping][spec_ping] - Ping protocol
- [autonat][spec_autonat] - NAT detection - [autonat][spec_autonat] - NAT detection

View File

@@ -88,6 +88,8 @@ The libp2p protocol ID for this protocol is `/libp2p/fetch/0.0.1`
The messages in the Fetch protocol use on of the following protobufs (proto3 syntax): The messages in the Fetch protocol use on of the following protobufs (proto3 syntax):
``` ```
syntax = "proto2";
message FetchRequest { message FetchRequest {
string identifier = 1; string identifier = 1;
} }

View File

@@ -73,6 +73,7 @@ whose values have changed.
## The Identify Message ## The Identify Message
```protobuf ```protobuf
syntax = "proto2";
message Identify { message Identify {
optional string protocolVersion = 5; optional string protocolVersion = 5;
optional string agentVersion = 6; optional string agentVersion = 6;

View File

@@ -401,6 +401,8 @@ bytes, encoded as an unsigned variable length integer as defined by the
All RPC messages conform to the following protobuf: All RPC messages conform to the following protobuf:
```protobuf ```protobuf
syntax = "proto2";
// Record represents a dht record that contains a value // Record represents a dht record that contains a value
// for a key value pair // for a key value pair
message Record { message Record {

View File

@@ -84,6 +84,8 @@ The `PublicKey` message uses the same definition [specified in the peer id
spec][peer-id-spec-pubkey-message]. For reference, it is defined as follows: spec][peer-id-spec-pubkey-message]. For reference, it is defined as follows:
``` protobuf ``` protobuf
syntax = "proto2";
enum KeyType { enum KeyType {
RSA = 0; RSA = 0;
Ed25519 = 1; Ed25519 = 1;

View File

@@ -90,6 +90,7 @@ messages between participating peers.
The `RPC` protobuf is as follows: The `RPC` protobuf is as follows:
```protobuf ```protobuf
syntax = "proto2";
message RPC { message RPC {
repeated SubOpts subscriptions = 1; repeated SubOpts subscriptions = 1;
repeated Message publish = 2; repeated Message publish = 2;
@@ -112,6 +113,7 @@ false signifies 'unsubscribe'.
The RPC message can contain zero or more messages of type 'Message'. The Message protobuf looks like this: The RPC message can contain zero or more messages of type 'Message'. The Message protobuf looks like this:
```protobuf ```protobuf
syntax = "proto2";
message Message { message Message {
optional string from = 1; optional string from = 1;
optional bytes data = 2; optional bytes data = 2;
@@ -341,6 +343,7 @@ and may be removed once used.
The `TopicDescriptor` protobuf is as follows: The `TopicDescriptor` protobuf is as follows:
```protobuf ```protobuf
syntax = "proto2";
message TopicDescriptor { message TopicDescriptor {
optional string name = 1; optional string name = 1;
// AuthOpts and EncOpts are unused as of Oct 2018, but // AuthOpts and EncOpts are unused as of Oct 2018, but

View File

@@ -375,6 +375,8 @@ control messages. The four control messages are `ControlIHave` for `IHAVE` messa
The protobuf is as follows: The protobuf is as follows:
```protobuf ```protobuf
syntax = "proto2";
message RPC { message RPC {
// ... // ...
optional ControlMessage control = 3; optional ControlMessage control = 3;

View File

@@ -506,6 +506,8 @@ The four control messages are `ControlIHave` for [`IHAVE`](#ihave) messages,
The protobuf is as follows: The protobuf is as follows:
```protobuf ```protobuf
syntax = "proto2";
message RPC { message RPC {
// ... see definition in pubsub interface spec // ... see definition in pubsub interface spec
optional ControlMessage control = 3; optional ControlMessage control = 3;

View File

@@ -129,6 +129,7 @@ In this case, the pruned peer will have to rely on the ambient peer discovery se
The `ControlPrune` message is extended with a `peers` field as follows. The `ControlPrune` message is extended with a `peers` field as follows.
```protobuf ```protobuf
syntax = "proto2";
message ControlPrune { message ControlPrune {
optional string topicID = 1; optional string topicID = 1;
repeated PeerInfo peers = 2; // gossipsub v1.1 PX repeated PeerInfo peers = 2; // gossipsub v1.1 PX

View File

@@ -140,6 +140,8 @@ We start the description of the Wire format by illustrating a possible flow scen
Every message in the relay protocol uses the following protobuf: Every message in the relay protocol uses the following protobuf:
``` ```
syntax = "proto2";
message CircuitRelay { message CircuitRelay {
enum Status { enum Status {

View File

@@ -347,7 +347,8 @@ The voucher itself is a [Signed Envelope](../RFC/0002-signed-envelopes.md).
The envelope domain is `libp2p-relay-rsvp` and uses the multicodec code `0x0302`. The envelope domain is `libp2p-relay-rsvp` and uses the multicodec code `0x0302`.
The payload of the envelope has the following form, in canonicalized protobuf format: The payload of the envelope has the following form, in canonicalized protobuf format:
``` ```protobuf
syntax = "proto2";
message Voucher { message Voucher {
required bytes relay = 1; required bytes relay = 1;
required bytes peer = 2; required bytes peer = 2;
@@ -363,7 +364,8 @@ The wire representation is canonicalized, where elements of the message are writ
## Protobuf ## Protobuf
``` ```protobuf
syntax = "proto2";
message HopMessage { message HopMessage {
enum Type { enum Type {
RESERVE = 0; RESERVE = 0;

View File

@@ -198,6 +198,8 @@ topic.
### Protobuf ### Protobuf
```protobuf ```protobuf
syntax = "proto2";
message Message { message Message {
enum MessageType { enum MessageType {
REGISTER = 0; REGISTER = 0;

View File

@@ -104,6 +104,8 @@ SignedKey ::= SEQUENCE {
The publicKey field of `SignedKey` contains the public host key of the endpoint, encoded using the following protobuf: The publicKey field of `SignedKey` contains the public host key of the endpoint, encoded using the following protobuf:
```protobuf ```protobuf
syntax = "proto2";
enum KeyType { enum KeyType {
RSA = 0; RSA = 0;
Ed25519 = 1; Ed25519 = 1;