-
Notifications
You must be signed in to change notification settings - Fork 66
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
Conversation
There was a problem hiding this 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/packet/header/fragment.rs
Outdated
wtr.write(&header.parse()?)?; | ||
}, | ||
None => { | ||
return Err(Error::new(ErrorKind::Other, "Invalid fragment header")); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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/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)?; |
There was a problem hiding this comment.
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?
There was a problem hiding this 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.
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it!
There was a problem hiding this 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>; | ||
|
||
|
There was a problem hiding this comment.
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
@TimonPost I took a stab at resolving the conflicts |
@fhaynes btw
|
Fixed a missing semicolon
Fixed, thanks. |
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. |
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:
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.
byteorder
so that I can control more better how a header gets serialized an deserialized.Still, need to do: