Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Simplify messages #508

Merged
merged 3 commits into from
Aug 31, 2020
Merged

Simplify messages #508

merged 3 commits into from
Aug 31, 2020

Conversation

little-dude
Copy link
Contributor

@little-dude little-dude commented Aug 27, 2020

This PR simplifies the message types in preparation of the upcoming changes needed to support multipart messages:

  • remove non-Owned message types since they are not used
  • remove the certificate from the message header since it's currently not used, and it's unclear whether it will actually be needed
  • remove the coordinator public key from the message header since it's unused

It turns out that we only use the owned version of the various message
types, so let's simplify them by removing the generic parameters.
There is no reason to send it to the coodinator, since it already has
it.
@little-dude little-dude changed the title remove non-"Owned" message Simplify messages Aug 27, 2020
@codecov
Copy link

codecov bot commented Aug 27, 2020

Codecov Report

Merging #508 into master will decrease coverage by 0.30%.
The diff coverage is 43.05%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #508      +/-   ##
==========================================
- Coverage   57.33%   57.02%   -0.31%     
==========================================
  Files          68       67       -1     
  Lines        3117     3048      -69     
==========================================
- Hits         1787     1738      -49     
+ Misses       1330     1310      -20     
Impacted Files Coverage Δ
rust/xaynet-client/src/lib.rs 13.72% <0.00%> (+0.26%) ⬆️
rust/xaynet-client/src/mobile_client/client.rs 0.00% <0.00%> (ø)
...t-client/src/mobile_client/participant/awaiting.rs 76.47% <ø> (ø)
...xaynet-client/src/mobile_client/participant/mod.rs 0.00% <0.00%> (ø)
...xaynet-client/src/mobile_client/participant/sum.rs 25.00% <0.00%> (ø)
...aynet-client/src/mobile_client/participant/sum2.rs 17.85% <0.00%> (ø)
...net-client/src/mobile_client/participant/update.rs 38.46% <0.00%> (ø)
rust/xaynet-core/src/message/payload/mod.rs 60.00% <ø> (ø)
rust/xaynet-core/src/message/payload/sum.rs 92.10% <ø> (ø)
rust/xaynet-core/src/message/traits.rs 83.78% <ø> (+5.30%) ⬆️
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6884b12...63fd745. Read the comment docs.

@Robert-Steiner
Copy link
Contributor

For me it looks good👍
It makes reading the code easier. However I'm not sure if we better wait for @janpetschexain opinion because I was not so involved in that part of the code.

@little-dude
Copy link
Contributor Author

I just started with the multipart support so no need to merge right now. If too many changes queue up, I'll merge, but otherwise I'll wait for Monday.

@little-dude little-dude merged commit 6cef60f into master Aug 31, 2020
@little-dude little-dude deleted the simplify-messages branch August 31, 2020 14:12
@little-dude
Copy link
Contributor Author

Merging because I'm about to open a new PR based on this one.

little-dude added a commit that referenced this pull request Aug 31, 2020
This commit contains several major changes.

# Re-work the message header

```
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                           signature                           +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|      tag      |     flags     |            reserved           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                         participant_pk                        +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
```

The problem is that:

- When reading from a byte stream, we don't know where the message
  finishes because there is no length field. So far this has not been
  a problem because we would only receive messages via HTTP. However,
  if we decide to do encryption in the TLS layer, we might support
  reading messages from a TLS connection directly. Then, we'll have an
  encrypted byte stream in input and un-encrypted byte stream as
  output, and we'll need to be able to find the message boundaries to
  parse the messages.
- The participant public key is used to verify the signature, which is
  the first thing we do. It's not convenient to have to read this far
  in the header to get it. Instead it should follow the signature.
- The flags field is currently un-used (we removed the certificate
  field in #508

Therefore we changed the header of the messages as follow:

```
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                           signature                           +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                         participant_pk                        +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                             length                            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|      tag      |                    reserved                   |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
```

# Remove the `Header` type

To simplify the code, we also removed the `Header` type. Instead, the
`Header` is not part of the `Message` itself:

```rust
// The length field is omitted because it's compupted
// automatically when serializing the message.
//
// The tag field is omitted because it's encoded in the `Payload`
// enum type
pub struct Message {
    pub signature: Option<Signature>,
    pub participant_pk: PublicSigningKey,
    pub payload: Payload,
}
```

Note that the `Message` type cannot implement the `ToBytes` trait,
because the insertion of the signature requires passing a secret
signing key as an argument. Instead, `Message` has a `to_bytes`
method. We could implement `FromBytes` but to make things consistent,
we also implemented it directly as a `from_bytes` methods.

# Remove the `Message::new_{sum,update,sum2}` constructors

The `Message` type has been greatly simplified. There is no need for
these constructors.

# Introduce a new `Chunk` message type

We introduced a new message type that represents a part, or chunk, of
a bigger message: `Chunk`. The message structure is:

```
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|            chunk_id           |           message_id          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|     flags     |             reserved                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                            payload                            |
```

We currently only support one flag that indicates whether this is the
last chunk of the message or not. The `chunk_id` identifies a chunk,
and the `message_id` identifies the biggier message it is part of.
little-dude added a commit that referenced this pull request Aug 31, 2020
This commit contains several major changes.

# Re-work the message header

```
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                           signature                           +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|      tag      |     flags     |            reserved           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                         participant_pk                        +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
```

The problem is that:

- When reading from a byte stream, we don't know where the message
  finishes because there is no length field. So far this has not been
  a problem because we would only receive messages via HTTP. However,
  if we decide to do encryption in the TLS layer, we might support
  reading messages from a TLS connection directly. Then, we'll have an
  encrypted byte stream in input and un-encrypted byte stream as
  output, and we'll need to be able to find the message boundaries to
  parse the messages.
- The participant public key is used to verify the signature, which is
  the first thing we do. It's not convenient to have to read this far
  in the header to get it. Instead it should follow the signature.
- The flags field is currently un-used (we removed the certificate
  field in #508

Therefore we changed the header of the messages as follow:

```
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                           signature                           +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                         participant_pk                        +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                             length                            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|      tag      |                    reserved                   |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
```

# Remove the `Header` type

To simplify the code, we also removed the `Header` type. Instead, the
`Header` is not part of the `Message` itself:

```rust
// The length field is omitted because it's compupted
// automatically when serializing the message.
//
// The tag field is omitted because it's encoded in the `Payload`
// enum type
pub struct Message {
    pub signature: Option<Signature>,
    pub participant_pk: PublicSigningKey,
    pub payload: Payload,
}
```

Note that the `Message` type cannot implement the `ToBytes` trait,
because the insertion of the signature requires passing a secret
signing key as an argument. Instead, `Message` has a `to_bytes`
method. We could implement `FromBytes` but to make things consistent,
we also implemented it directly as a `from_bytes` methods.

# Remove the `Message::new_{sum,update,sum2}` constructors

The `Message` type has been greatly simplified. There is no need for
these constructors.

# Introduce a new `Chunk` message type

We introduced a new message type that represents a part, or chunk, of
a bigger message: `Chunk`. The message structure is:

```
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|            chunk_id           |           message_id          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|     flags     |             reserved                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                            payload                            |
```

We currently only support one flag that indicates whether this is the
last chunk of the message or not. The `chunk_id` identifies a chunk,
and the `message_id` identifies the biggier message it is part of.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants