-
Notifications
You must be signed in to change notification settings - Fork 34
Add DhtPacket::get_payload #12
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
Conversation
Pull Request Test Coverage Report for Build 119
💛 - Coveralls |
src/toxcore/dht_new/dht_node.rs
Outdated
| // TODO: add fn for ping/getn req timeouts with hardcoded consts? | ||
| pub fn remove_timed_out(&mut self, secs: u64) { | ||
| for pk in self.getn_timeout.get_timed_out(secs) { | ||
| debug!("Removing timed out node"); |
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 think pk should be added to the message, in other case it will be useless to have many same records in a row.
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.
We should remove that code by Zetok. It is malformed.
src/toxcore/dht_new/dht_impl.rs
Outdated
| trace!(target: "DhtPacket", "With DhtPacket: {:?}", self); | ||
| let decrypted = open(&self.payload, &self.nonce, &self.pk, | ||
| own_secret_key) | ||
| .and_then(|d| Ok(d)) |
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.
It seems this line is unnecessary.
src/toxcore/dht_new/dht_impl.rs
Outdated
| format!("DhtPacket decrypt error: {:?}", e)) | ||
| }); | ||
|
|
||
| match DhtPacketPayload::from_bytes(&decrypted.unwrap_or(vec![0]), self.packet_kind) { |
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.
Why unwrap_or(vec![0])? You already did .map_err(..) part so just add question mark to return error properly.
src/toxcore/dht_new/dht_impl.rs
Outdated
| // 1 | nat ping req|resp (0xfe) | ||
| // 1 | Request or Response flag | ||
| // 8 | Request Id (Ping Id) | ||
| let packet_payload = decrypted.unwrap_or(vec![0,0]); |
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'd propose to do here the same thing as for DhtPacket::get_payload to reduce code size.
src/toxcore/dht_new/dht_impl.rs
Outdated
| if let DhtBase::DhtPacket(ref p) = *self { | ||
| p.packet_kind | ||
| } else { | ||
| unreachable!("DhtRequest packet kind is encrypted.") |
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.
Why this is unreachable? And why error instead of returning PacketKind::DhtRequest?
src/toxcore/dht_new/dht_impl.rs
Outdated
| let key = HashKeys(key_pair.0.clone(), key_pair.1.clone()); | ||
| match self.cache.get(&key) { // if symmetric key exists in cache, returns with the value | ||
| Some(k) => { | ||
| return Ok(k.clone()); |
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.
Space at the end of line :)
|
I reopen this PR with new contents. |
src/toxcore/dht_new/packet.rs
Outdated
| format!("DhtPacket decrypt error: {:?}", e)) | ||
| }); | ||
|
|
||
| match DhtPacketPayload::from_bytes(&decrypted.unwrap_or(vec![0]), self.packet_kind) { |
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.
Why unwrap_or(vec![0])? You already did .map_err(..) part so just add question mark to return error properly.
src/toxcore/dht_new/packet.rs
Outdated
| trace!(target: "DhtPacket", "With DhtPacket: {:?}", self); | ||
| let decrypted = open(&self.payload, &self.nonce, &self.pk, | ||
| own_secret_key) | ||
| .and_then(|d| Ok(d)) |
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.
It seems this line is unnecessary.
src/toxcore/dht_new/packet.rs
Outdated
| - fails to decrypt | ||
| - fails to parse as given packet type | ||
| */ | ||
| pub fn get_payload(&self, own_secret_key: &SecretKey) -> Result<Option<DhtPacketPayload>, 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.
Why Option here?
…>> to Result<DhtPacketPayload>
Make TCP and UDP servers optional
apply new DhtPacketPayload::from_bytes() to get_payload() of dht_impl.rs.
This PR has rebased on #11