-
Notifications
You must be signed in to change notification settings - Fork 107
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
Move MetaAddr serialization into zebra_network::protocol::external #3020
Merged
+135
−131
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
mod check; | ||
mod preallocate; | ||
mod prop; | ||
mod vectors; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//! Node address types and serialization for the Zcash wire format. | ||
|
||
use std::io::{Read, Write}; | ||
|
||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; | ||
|
||
use zebra_chain::serialization::{ | ||
ReadZcashExt, SerializationError, TrustedPreallocate, WriteZcashExt, ZcashDeserialize, | ||
ZcashDeserializeInto, ZcashSerialize, | ||
}; | ||
|
||
use crate::{ | ||
meta_addr::MetaAddr, | ||
protocol::external::{types::PeerServices, MAX_PROTOCOL_MESSAGE_LEN}, | ||
}; | ||
|
||
impl ZcashSerialize for MetaAddr { | ||
fn zcash_serialize<W: Write>(&self, mut writer: W) -> Result<(), std::io::Error> { | ||
self.last_seen() | ||
.expect( | ||
"unexpected MetaAddr with missing last seen time: MetaAddrs should be sanitized \ | ||
before serialization", | ||
) | ||
.zcash_serialize(&mut writer)?; | ||
|
||
writer.write_u64::<LittleEndian>( | ||
self.services | ||
.expect( | ||
"unexpected MetaAddr with missing peer services: MetaAddrs should be \ | ||
sanitized before serialization", | ||
) | ||
.bits(), | ||
)?; | ||
|
||
writer.write_socket_addr(self.addr)?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl ZcashDeserialize for MetaAddr { | ||
fn zcash_deserialize<R: Read>(mut reader: R) -> Result<Self, SerializationError> { | ||
let untrusted_last_seen = (&mut reader).zcash_deserialize_into()?; | ||
let untrusted_services = | ||
PeerServices::from_bits_truncate(reader.read_u64::<LittleEndian>()?); | ||
let addr = reader.read_socket_addr()?; | ||
|
||
Ok(MetaAddr::new_gossiped_meta_addr( | ||
addr, | ||
untrusted_services, | ||
untrusted_last_seen, | ||
)) | ||
} | ||
} | ||
|
||
/// A serialized meta addr has a 4 byte time, 8 byte services, 16 byte IP addr, and 2 byte port | ||
pub(super) const META_ADDR_SIZE: usize = 4 + 8 + 16 + 2; | ||
|
||
impl TrustedPreallocate for MetaAddr { | ||
fn max_allocation() -> u64 { | ||
// Since a maximal serialized Vec<MetAddr> uses at least three bytes for its length (2MB messages / 30B MetaAddr implies the maximal length is much greater than 253) | ||
// the max allocation can never exceed (MAX_PROTOCOL_MESSAGE_LEN - 3) / META_ADDR_SIZE | ||
((MAX_PROTOCOL_MESSAGE_LEN - 3) / META_ADDR_SIZE) as u64 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Optional suggestion:
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 I'll fix this on top of PR #3022, because it can be fixed in all the preallocate tests.
(And I need to write new preallocate tests in #3022.)