Loading changes/ticket40133 0 → 100644 +5 −0 Original line number Diff line number Diff line o Minor features (protocol simplification): - Tor no longer allows subprotocol versions larger than 63. Previously versions up to UINT32_MAX were allowed, which significantly complicated our code. Implements proposal 318; closes ticket 40133. src/core/or/protover.c +2 −2 Original line number Diff line number Diff line Loading @@ -118,13 +118,13 @@ proto_entry_free_(proto_entry_t *entry) } /** The largest possible protocol version. */ #define MAX_PROTOCOL_VERSION (UINT32_MAX-1) #define MAX_PROTOCOL_VERSION (63) /** * Given a string <b>s</b> and optional end-of-string pointer * <b>end_of_range</b>, parse the protocol range and store it in * <b>low_out</b> and <b>high_out</b>. A protocol range has the format U, or * U-U, where U is an unsigned 32-bit integer. * U-U, where U is an unsigned integer between 0 and 63 inclusive. */ static int parse_version_range(const char *s, const char *end_of_range, Loading src/rust/protover/errors.rs +1 −1 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ impl Display for ProtoverError { ProtoverError::Unparseable => write!(f, "The protover string was unparseable."), ProtoverError::ExceedsMax => write!( f, "The high in a (low, high) protover range exceeds u32::MAX." "The high in a (low, high) protover range exceeds 63." ), ProtoverError::ExceedsExpansionLimit => write!( f, Loading src/rust/protover/protoset.rs +14 −6 Original line number Diff line number Diff line Loading @@ -294,6 +294,10 @@ impl ProtoSet { } } /// Largest allowed protocol version. /// C_RUST_COUPLED: protover.c `MAX_PROTOCOL_VERSION` const MAX_PROTOCOL_VERSION: Version = 63; impl FromStr for ProtoSet { type Err = ProtoverError; Loading Loading @@ -370,7 +374,7 @@ impl FromStr for ProtoSet { let pieces: ::std::str::Split<char> = version_string.split(','); for p in pieces { if p.contains('-') { let (lo,hi) = if p.contains('-') { let mut pair = p.splitn(2, '-'); let low = pair.next().ok_or(ProtoverError::Unparseable)?; Loading @@ -379,12 +383,17 @@ impl FromStr for ProtoSet { let lo: Version = low.parse().or(Err(ProtoverError::Unparseable))?; let hi: Version = high.parse().or(Err(ProtoverError::Unparseable))?; pairs.push((lo, hi)); (lo,hi) } else { let v: u32 = p.parse().or(Err(ProtoverError::Unparseable))?; pairs.push((v, v)); (v, v) }; if lo > MAX_PROTOCOL_VERSION || hi > MAX_PROTOCOL_VERSION { return Err(ProtoverError::ExceedsMax); } pairs.push((lo, hi)); } ProtoSet::from_slice(&pairs[..]) Loading Loading @@ -674,12 +683,11 @@ mod test { #[test] fn test_protoset_into_vec() { let ps: ProtoSet = "1-13,42,9001,4294967294".parse().unwrap(); let ps: ProtoSet = "1-13,42".parse().unwrap(); let v: Vec<Version> = ps.into(); assert!(v.contains(&7)); assert!(v.contains(&9001)); assert!(v.contains(&4294967294)); assert!(v.contains(&42)); } } Loading src/rust/protover/protover.rs +5 −5 Original line number Diff line number Diff line Loading @@ -874,12 +874,12 @@ mod test { #[test] fn test_protoentry_from_str_allowed_number_of_versions() { assert_protoentry_is_parseable!("Desc=1-4294967294"); assert_protoentry_is_parseable!("Desc=1-63"); } #[test] fn test_protoentry_from_str_too_many_versions() { assert_protoentry_is_unparseable!("Desc=1-4294967295"); assert_protoentry_is_unparseable!("Desc=1-64"); } #[test] Loading Loading @@ -918,10 +918,10 @@ mod test { #[test] fn test_protoentry_all_supported_unsupported_high_version() { let protocols: UnvalidatedProtoEntry = "HSDir=12-100".parse().unwrap(); let protocols: UnvalidatedProtoEntry = "HSDir=12-60".parse().unwrap(); let unsupported: Option<UnvalidatedProtoEntry> = protocols.all_supported(); assert_eq!(true, unsupported.is_some()); assert_eq!("HSDir=12-100", &unsupported.unwrap().to_string()); assert_eq!("HSDir=12-60", &unsupported.unwrap().to_string()); } #[test] Loading Loading @@ -970,7 +970,7 @@ mod test { ProtoSet::from_str(&versions).unwrap().to_string() ); versions = "1-3,500"; versions = "1-3,50"; assert_eq!( String::from(versions), ProtoSet::from_str(&versions).unwrap().to_string() Loading Loading
changes/ticket40133 0 → 100644 +5 −0 Original line number Diff line number Diff line o Minor features (protocol simplification): - Tor no longer allows subprotocol versions larger than 63. Previously versions up to UINT32_MAX were allowed, which significantly complicated our code. Implements proposal 318; closes ticket 40133.
src/core/or/protover.c +2 −2 Original line number Diff line number Diff line Loading @@ -118,13 +118,13 @@ proto_entry_free_(proto_entry_t *entry) } /** The largest possible protocol version. */ #define MAX_PROTOCOL_VERSION (UINT32_MAX-1) #define MAX_PROTOCOL_VERSION (63) /** * Given a string <b>s</b> and optional end-of-string pointer * <b>end_of_range</b>, parse the protocol range and store it in * <b>low_out</b> and <b>high_out</b>. A protocol range has the format U, or * U-U, where U is an unsigned 32-bit integer. * U-U, where U is an unsigned integer between 0 and 63 inclusive. */ static int parse_version_range(const char *s, const char *end_of_range, Loading
src/rust/protover/errors.rs +1 −1 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ impl Display for ProtoverError { ProtoverError::Unparseable => write!(f, "The protover string was unparseable."), ProtoverError::ExceedsMax => write!( f, "The high in a (low, high) protover range exceeds u32::MAX." "The high in a (low, high) protover range exceeds 63." ), ProtoverError::ExceedsExpansionLimit => write!( f, Loading
src/rust/protover/protoset.rs +14 −6 Original line number Diff line number Diff line Loading @@ -294,6 +294,10 @@ impl ProtoSet { } } /// Largest allowed protocol version. /// C_RUST_COUPLED: protover.c `MAX_PROTOCOL_VERSION` const MAX_PROTOCOL_VERSION: Version = 63; impl FromStr for ProtoSet { type Err = ProtoverError; Loading Loading @@ -370,7 +374,7 @@ impl FromStr for ProtoSet { let pieces: ::std::str::Split<char> = version_string.split(','); for p in pieces { if p.contains('-') { let (lo,hi) = if p.contains('-') { let mut pair = p.splitn(2, '-'); let low = pair.next().ok_or(ProtoverError::Unparseable)?; Loading @@ -379,12 +383,17 @@ impl FromStr for ProtoSet { let lo: Version = low.parse().or(Err(ProtoverError::Unparseable))?; let hi: Version = high.parse().or(Err(ProtoverError::Unparseable))?; pairs.push((lo, hi)); (lo,hi) } else { let v: u32 = p.parse().or(Err(ProtoverError::Unparseable))?; pairs.push((v, v)); (v, v) }; if lo > MAX_PROTOCOL_VERSION || hi > MAX_PROTOCOL_VERSION { return Err(ProtoverError::ExceedsMax); } pairs.push((lo, hi)); } ProtoSet::from_slice(&pairs[..]) Loading Loading @@ -674,12 +683,11 @@ mod test { #[test] fn test_protoset_into_vec() { let ps: ProtoSet = "1-13,42,9001,4294967294".parse().unwrap(); let ps: ProtoSet = "1-13,42".parse().unwrap(); let v: Vec<Version> = ps.into(); assert!(v.contains(&7)); assert!(v.contains(&9001)); assert!(v.contains(&4294967294)); assert!(v.contains(&42)); } } Loading
src/rust/protover/protover.rs +5 −5 Original line number Diff line number Diff line Loading @@ -874,12 +874,12 @@ mod test { #[test] fn test_protoentry_from_str_allowed_number_of_versions() { assert_protoentry_is_parseable!("Desc=1-4294967294"); assert_protoentry_is_parseable!("Desc=1-63"); } #[test] fn test_protoentry_from_str_too_many_versions() { assert_protoentry_is_unparseable!("Desc=1-4294967295"); assert_protoentry_is_unparseable!("Desc=1-64"); } #[test] Loading Loading @@ -918,10 +918,10 @@ mod test { #[test] fn test_protoentry_all_supported_unsupported_high_version() { let protocols: UnvalidatedProtoEntry = "HSDir=12-100".parse().unwrap(); let protocols: UnvalidatedProtoEntry = "HSDir=12-60".parse().unwrap(); let unsupported: Option<UnvalidatedProtoEntry> = protocols.all_supported(); assert_eq!(true, unsupported.is_some()); assert_eq!("HSDir=12-100", &unsupported.unwrap().to_string()); assert_eq!("HSDir=12-60", &unsupported.unwrap().to_string()); } #[test] Loading Loading @@ -970,7 +970,7 @@ mod test { ProtoSet::from_str(&versions).unwrap().to_string() ); versions = "1-3,500"; versions = "1-3,50"; assert_eq!( String::from(versions), ProtoSet::from_str(&versions).unwrap().to_string() Loading