Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented protocol id for headers. #55

Merged
merged 1 commit into from
Oct 21, 2018
Merged

Implemented protocol id for headers. #55

merged 1 commit into from
Oct 21, 2018

Conversation

TimonPost
Copy link
Owner

@TimonPost TimonPost commented Oct 20, 2018

Implemented protocol id see #4 for more information.

Please during review check these out:

  • laminar-0.1.0
    From this value or crc32 will be generated do we agree on this notation for protocol version.
  • I use unsafe in on place see /src/protocol_version.rs, I can change this to lazy_static but like the current way, it could also be done. What should I do with this?
  • I use CRC32 for encoding of protocol version. Maybe an option to have CRC16? I don't know if there is some major difference between the who other than the size.

O shit. I see that I have to comment some things from ProtocolVersion I'll update it later.

Copy link
Contributor

@LucioFranco LucioFranco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking really really awesome! Excited to have this in. If you have any questions ping me on discord.

Cargo.toml Outdated Show resolved Hide resolved
src/error/network_error.rs Outdated Show resolved Hide resolved
src/error/network_error.rs Outdated Show resolved Hide resolved
/// - Generating crc32 for the packet header.
/// - Validating if arriving packets have the same protocol version.
pub const PROTOCOL_VERSION: &'static str = "laminar-0.1.0";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to think if there is a better way to do this. 🤔 . This is fine for now but if we do merge this, lets open an issue to follow up on.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is it that you don't like about it. You want somehow identify the current protocol I have seen this in a couple of libraries done like this. But if it is an issue lets discuss it in an issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its hard coded and I'd prefer to find a better place maybe to write this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the idea would be that it gets bumped here if the protocol changes? I'm not sure where else you could put it, unless you wanted to break it up into multiple variables and assemble a String, but not sure how that would help.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use a file called VERSION that is at the root and use include_bytes!()

src/packet/packet_processor.rs Outdated Show resolved Hide resolved
/// 3. then assert that the Packet we've gotten contains the right data.
#[test]
fn packets_ignored_with_different_protocol_id() {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets add a test here please

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops forgotten.

src/packet/packet_processor.rs Outdated Show resolved Hide resolved
/// This will return the crc32 from the current protocol version.
pub fn get_crc32() -> u32 {
CALCULATE_CRC32.call_once(|| {
unsafe { VERSION_CRC32 = crc32::checksum_ieee(PROTOCOL_VERSION.as_bytes()); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So as I have learned if we call unsafe code and wrap it, we need to have some invariants that we check that guarantee that this is actually safe.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we check if this is safe? We can use lazy_static if it is needed.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am using lazy_static instead now. Think this is more cleaner.


/// This will return the crc32 from the current protocol version.
pub fn valid_version(protocol_version_crc32: u32) -> bool {
protocol_version_crc32 == unsafe { VERSION_CRC32 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Contributor

@LucioFranco LucioFranco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great

Copy link
Collaborator

@fhaynes fhaynes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!

Repository owner deleted a comment from bors bot Oct 21, 2018
@TimonPost
Copy link
Owner Author

bors r=fhaynes,LucioFranco

bors bot added a commit that referenced this pull request Oct 21, 2018
55: Implemented protocol id for headers. r=fhaynes,LucioFranco a=TimonPost

Implemented protocol id see #4  for more information.

Please during review check these out:
- laminar-0.1.0 
From this value or crc32 will be generated do we agree on this notation for protocol version.
- I use unsafe in on place see /src/protocol_version.rs, I can change this to `lazy_static` but like the current way, it could also be done. What should I do with this? 
- I use CRC32 for encoding of protocol version. Maybe an option to have CRC16? I don't know if there is some major difference between the who other than the size.

O shit. I see that I have to comment some things from `ProtocolVersion` I'll update it later.

Co-authored-by: Timon Post <timonpost@hotmail.nl>
Repository owner deleted a comment from LucioFranco Oct 21, 2018
@bors
Copy link
Contributor

bors bot commented Oct 21, 2018

Build succeeded

@bors bors bot merged commit b831856 into TimonPost:master Oct 21, 2018
@TimonPost TimonPost mentioned this pull request Oct 22, 2018
18 tasks
@TimonPost TimonPost deleted the protocol_id branch November 26, 2018 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants