fix(network): use initiatorOnlyDiffusionMode correctly after spec fix (#384)

This commit is contained in:
Andrew Westberg 2024-01-25 06:32:54 -05:00 committed by GitHub
parent 7b2894e4a2
commit 24b5086b4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -33,19 +33,19 @@ impl VersionTable {
let values = vec![ let values = vec![
( (
PROTOCOL_V7, PROTOCOL_V7,
VersionData::new(network_magic, false, None, None), VersionData::new(network_magic, true, None, None),
), ),
( (
PROTOCOL_V8, PROTOCOL_V8,
VersionData::new(network_magic, false, None, None), VersionData::new(network_magic, true, None, None),
), ),
( (
PROTOCOL_V9, PROTOCOL_V9,
VersionData::new(network_magic, false, None, None), VersionData::new(network_magic, true, None, None),
), ),
( (
PROTOCOL_V10, PROTOCOL_V10,
VersionData::new(network_magic, false, None, None), VersionData::new(network_magic, true, None, None),
), ),
] ]
.into_iter() .into_iter()
@ -58,25 +58,25 @@ impl VersionTable {
let values = vec![ let values = vec![
( (
PROTOCOL_V7, PROTOCOL_V7,
VersionData::new(network_magic, false, None, None), VersionData::new(network_magic, true, None, None),
), ),
( (
PROTOCOL_V8, PROTOCOL_V8,
VersionData::new(network_magic, false, None, None), VersionData::new(network_magic, true, None, None),
), ),
( (
PROTOCOL_V9, PROTOCOL_V9,
VersionData::new(network_magic, false, None, None), VersionData::new(network_magic, true, None, None),
), ),
( (
PROTOCOL_V10, PROTOCOL_V10,
VersionData::new(network_magic, false, None, None), VersionData::new(network_magic, true, None, None),
), ),
( (
PROTOCOL_V11, PROTOCOL_V11,
VersionData::new( VersionData::new(
network_magic, network_magic,
false, true,
Some(PEER_SHARING_DISABLED), Some(PEER_SHARING_DISABLED),
Some(false), Some(false),
), ),
@ -85,7 +85,7 @@ impl VersionTable {
PROTOCOL_V12, PROTOCOL_V12,
VersionData::new( VersionData::new(
network_magic, network_magic,
false, true,
Some(PEER_SHARING_DISABLED), Some(PEER_SHARING_DISABLED),
Some(false), Some(false),
), ),
@ -94,7 +94,7 @@ impl VersionTable {
PROTOCOL_V13, PROTOCOL_V13,
VersionData::new( VersionData::new(
network_magic, network_magic,
false, true,
Some(PEER_SHARING_DISABLED), Some(PEER_SHARING_DISABLED),
Some(false), Some(false),
), ),
@ -112,7 +112,7 @@ impl VersionTable {
PROTOCOL_V11, PROTOCOL_V11,
VersionData::new( VersionData::new(
network_magic, network_magic,
false, true,
Some(PEER_SHARING_DISABLED), Some(PEER_SHARING_DISABLED),
Some(false), Some(false),
), ),
@ -121,7 +121,7 @@ impl VersionTable {
PROTOCOL_V12, PROTOCOL_V12,
VersionData::new( VersionData::new(
network_magic, network_magic,
false, true,
Some(PEER_SHARING_DISABLED), Some(PEER_SHARING_DISABLED),
Some(false), Some(false),
), ),
@ -130,7 +130,7 @@ impl VersionTable {
PROTOCOL_V13, PROTOCOL_V13,
VersionData::new( VersionData::new(
network_magic, network_magic,
false, true,
Some(PEER_SHARING_DISABLED), Some(PEER_SHARING_DISABLED),
Some(false), Some(false),
), ),
@ -146,7 +146,7 @@ impl VersionTable {
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub struct VersionData { pub struct VersionData {
network_magic: u64, network_magic: u64,
initiator_and_responder_diffusion_mode: bool, initiator_only_diffusion_mode: bool,
peer_sharing: Option<u8>, peer_sharing: Option<u8>,
query: Option<bool>, query: Option<bool>,
} }
@ -154,13 +154,13 @@ pub struct VersionData {
impl VersionData { impl VersionData {
pub fn new( pub fn new(
network_magic: u64, network_magic: u64,
initiator_and_responder_diffusion_mode: bool, initiator_only_diffusion_mode: bool,
peer_sharing: Option<u8>, peer_sharing: Option<u8>,
query: Option<bool>, query: Option<bool>,
) -> Self { ) -> Self {
VersionData { VersionData {
network_magic, network_magic,
initiator_and_responder_diffusion_mode, initiator_only_diffusion_mode,
peer_sharing, peer_sharing,
query, query,
} }
@ -177,14 +177,14 @@ impl Encode<()> for VersionData {
(Some(peer_sharing), Some(query)) => { (Some(peer_sharing), Some(query)) => {
e.array(4)? e.array(4)?
.u64(self.network_magic)? .u64(self.network_magic)?
.bool(self.initiator_and_responder_diffusion_mode)? .bool(self.initiator_only_diffusion_mode)?
.u8(peer_sharing)? .u8(peer_sharing)?
.bool(query)?; .bool(query)?;
} }
_ => { _ => {
e.array(2)? e.array(2)?
.u64(self.network_magic)? .u64(self.network_magic)?
.bool(self.initiator_and_responder_diffusion_mode)?; .bool(self.initiator_only_diffusion_mode)?;
} }
}; };
@ -196,7 +196,7 @@ impl<'b> Decode<'b, ()> for VersionData {
fn decode(d: &mut Decoder<'b>, _ctx: &mut ()) -> Result<Self, decode::Error> { fn decode(d: &mut Decoder<'b>, _ctx: &mut ()) -> Result<Self, decode::Error> {
let len = d.array()?; let len = d.array()?;
let network_magic = d.u64()?; let network_magic = d.u64()?;
let initiator_and_responder_diffusion_mode = d.bool()?; let initiator_only_diffusion_mode = d.bool()?;
let peer_sharing = match len { let peer_sharing = match len {
Some(4) => Some(d.u8()?), Some(4) => Some(d.u8()?),
_ => None, _ => None,
@ -208,7 +208,7 @@ impl<'b> Decode<'b, ()> for VersionData {
Ok(Self { Ok(Self {
network_magic, network_magic,
initiator_and_responder_diffusion_mode, initiator_only_diffusion_mode,
peer_sharing, peer_sharing,
query, query,
}) })