-
Notifications
You must be signed in to change notification settings - Fork 157
Add remote_pubkey to Packet Meta #436
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
Changes from all commits
5b791f8
3517360
d7b5e94
a7864d3
e10cb05
7eb366e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ use { | |
| }; | ||
| use { | ||
| bitflags::bitflags, | ||
| solana_pubkey::Pubkey, | ||
| std::{ | ||
| fmt, | ||
| net::{IpAddr, Ipv4Addr, SocketAddr}, | ||
|
|
@@ -72,6 +73,7 @@ pub struct Meta { | |
| pub addr: IpAddr, | ||
| pub port: u16, | ||
| pub flags: PacketFlags, | ||
| remote_pubkey: Pubkey, | ||
| } | ||
|
|
||
| #[cfg(feature = "frozen-abi")] | ||
|
|
@@ -300,6 +302,21 @@ impl Meta { | |
| pub fn is_from_staked_node(&self) -> bool { | ||
| self.flags.contains(PacketFlags::FROM_STAKED_NODE) | ||
| } | ||
|
|
||
| #[inline] | ||
| pub fn remote_pubkey(&self) -> Option<Pubkey> { | ||
| if self.remote_pubkey == Pubkey::default() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In such cases it may be preferable to explicitly compare with array of zeros rather than relying on the Default impl staying stable. Unlikely to be a problem for us of course. |
||
| None | ||
| } else { | ||
| Some(self.remote_pubkey) | ||
| } | ||
| } | ||
|
|
||
| /// Sets the remote pubkey. Use Pubkey::default() to clear. | ||
| #[inline] | ||
| pub fn set_remote_pubkey(&mut self, pubkey: Pubkey) { | ||
| self.remote_pubkey = pubkey; | ||
lijunwangs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| impl Default for Meta { | ||
|
|
@@ -309,6 +326,7 @@ impl Default for Meta { | |
| addr: IpAddr::V4(Ipv4Addr::UNSPECIFIED), | ||
| port: 0, | ||
| flags: PacketFlags::empty(), | ||
| remote_pubkey: Pubkey::default(), | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -355,4 +373,16 @@ mod tests { | |
| Err("the size limit has been reached".to_string()), | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_remote_pubkey() { | ||
| let mut meta = Meta::default(); | ||
| assert!(meta.remote_pubkey().is_none()); | ||
| let pubkey = Pubkey::new_unique(); | ||
| meta.set_remote_pubkey(pubkey); | ||
| assert_eq!(meta.remote_pubkey(), Some(pubkey)); | ||
| let pubkey = Pubkey::default(); | ||
| meta.set_remote_pubkey(pubkey); | ||
| assert!(meta.remote_pubkey().is_none()); | ||
| } | ||
| } | ||
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.
Flagging that this is technically a breaking change for anyone who builds a
Metawithout usingDefaultin some way, ie:It's not a problem, but probably requires a breaking release
Uh oh!
There was an error while loading. Please reload this page.
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 they can still use struct Meta, by putting the new flag with default
Met {
size,
add,
port,
flags,
..Meta::default()
}
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.
Correct, but that does still constitute a breaking change since old code will no longer compile.
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.
True, whenever we introduce a field it will break as we lack a constructor.