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

Add packet fragmentation #1

Merged
merged 13 commits into from
Oct 7, 2018
Merged

Add packet fragmentation #1

merged 13 commits into from
Oct 7, 2018

Conversation

TimonPost
Copy link
Owner

@TimonPost TimonPost commented Oct 2, 2018

This is an implementation of fragmentation (issue). Looks like it is working, but need to test it more still. So work in progress...

Note that I have looked at this libary which had some basic implementation of fragmentation. It is from the author of gafferongames blogs:

Things I changed:

  1. There are two headers:
  • PacketHeader
    This will contain all the header stuff we first had in RawPacket. This will be used for every packet.

  • Fragment Header
    Fragment header the information of the fragments a packet is divided into. The first fragment packet will have two headers. The standard PacketHeader and the Fragment header the following fragments only have the fragment header.

  1. Also, I have changed to using byteorder so that I can control more better how a header gets serialized an deserialized.
  2. I have a FragmentBuffer which will be used to store fragments temporarily
  3. Added a config ty[e for network settings.

Still, need to do:

  1. Tests
  2. Config file needs to be given by the user (for now the default is used).
  3. I want to make the preproccess_packet function smaller it is pritty big now.

@LucioFranco LucioFranco changed the title implemented fragmentation Add packet fragmentation Oct 4, 2018
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 great! Just a few comments. Let me know when its ready for another round.

src/lib.rs Outdated Show resolved Hide resolved
src/net/socket_state.rs Outdated Show resolved Hide resolved
src/net/socket_state.rs Outdated Show resolved Hide resolved
src/net/socket_state.rs Show resolved Hide resolved
src/net/socket_state.rs Outdated Show resolved Hide resolved
src/net/udp.rs Outdated Show resolved Hide resolved
wtr.write(&header.parse()?)?;
},
None => {
return Err(Error::new(ErrorKind::Other, "Invalid fragment header"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Should have an error type for this

Copy link
Owner Author

@TimonPost TimonPost Oct 5, 2018

Choose a reason for hiding this comment

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

There is one problem of doing that you have to see the context of the whole function.

Every 'write' in that function returns an io::Result. So we could paste this line .map_err(|| NetworkError::InvalidPacketHeader.into()?); behind each write function or we could simply return io::Result and let the caller map the error of that function to failiure error.

I think that is better otherwise this function will look horrible.

Copy link
Contributor

Choose a reason for hiding this comment

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

In reality we should have a Error::from implemented for io::Result

src/packet/header/packet.rs Outdated Show resolved Hide resolved
src/packet/packet_processor.rs Outdated Show resolved Hide resolved
src/packet/packet_processor.rs Outdated Show resolved Hide resolved
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.

Looking really good! Minor stuff from me

src/error.rs Show resolved Hide resolved
src/error.rs Show resolved Hide resolved
src/error.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/net/network_config.rs Outdated Show resolved Hide resolved
src/net/socket_state.rs Outdated Show resolved Hide resolved
src/net/udp.rs Show resolved Hide resolved
src/net/udp.rs Outdated
let mut bytes_send = 0;

for payload in packet_data.parts() {
bytes_send += self.socket.send_to(&payload, addr).map_err(|_| NetworkError::SendFailed)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Bubble up the error here?

src/packet/fragment_buffer.rs Show resolved Hide resolved
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.

This looks great. The one comment I made isn't a blocker, so approve.

src/error.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@torkleyy torkleyy left a comment

Choose a reason for hiding this comment

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

I didn't read the source code yet, so please forgive me for any stupid comments.

src/net/network_config.rs Outdated Show resolved Hide resolved
src/net/network_config.rs Show resolved Hide resolved
Copy link
Contributor

@torkleyy torkleyy left a comment

Choose a reason for hiding this comment

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

I like it!

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/packet/header/fragment.rs Outdated Show resolved Hide resolved
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 good! Just a few small nits. Once, those are resolved and you resolve @torkleyy's comments. Squash this into one commit, with a description and then merge it!

src/error.rs Outdated

pub type Error = failure::Error;
pub type Result<T> = result::Result<T, Error>;


Copy link
Contributor

Choose a reason for hiding this comment

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

Remove these new lines please

src/packet/fragment_buffer.rs Outdated Show resolved Hide resolved
src/packet/fragment_buffer.rs Show resolved Hide resolved
@fhaynes
Copy link
Collaborator

fhaynes commented Oct 7, 2018

@TimonPost I took a stab at resolving the conflicts

@LucioFranco
Copy link
Contributor

@fhaynes btw

error: expected `;`, found `use`
 --> src/net/udp.rs:5:1
  |
4 | use super::{constants, Packet, RawPacket}
  |                                          - expected `;`
5 | use socket_state::SocketState; 
  | ^^^ unexpected token
```

Fixed a missing semicolon
@fhaynes
Copy link
Collaborator

fhaynes commented Oct 7, 2018

@fhaynes btw

error: expected `;`, found `use`
 --> src/net/udp.rs:5:1
  |
4 | use super::{constants, Packet, RawPacket}
  |                                          - expected `;`
5 | use socket_state::SocketState; 
  | ^^^ unexpected token

Fixed, thanks.

@TimonPost
Copy link
Owner Author

Oke fixed the merge, ran all the tests with success, removed some unused imports and fixed all your comments. So going to merge now since you both have approved.

@TimonPost TimonPost merged commit 69cd007 into TimonPost:master Oct 7, 2018
@TimonPost TimonPost mentioned this pull request Oct 7, 2018
@TimonPost TimonPost deleted the fragmentation branch October 9, 2018 10:18
@TimonPost TimonPost mentioned this pull request Oct 22, 2018
18 tasks
fhaynes added a commit that referenced this pull request Oct 28, 2018
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.

None yet

4 participants