Skip to content

Commit 012af76

Browse files
authored
*: Add quic-v1 codepoint (#64)
1 parent 1cfb923 commit 012af76

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
- Create `protocol_stack` for Multiaddr. See [PR 60]
44

5+
- Add `QuicV1` instance for `Multiaddr`. See [PR 64]
6+
7+
[PR 60]: https://github.com/multiformats/rust-multiaddr/pull/60
8+
[PR 64]: https://github.com/multiformats/rust-multiaddr/pull/64
9+
510
# 0.15.0 [2022-10-20]
611

712
- Add `WebRTC` instance for `Multiaddr`. See [PR 59].

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ use multiaddr::{Multiaddr, multiaddr};
4040

4141
let address = "/ip4/127.0.0.1/tcp/1234".parse::<Multiaddr>().unwrap();
4242
// or with a macro
43-
let other = multiaddr!(Ip4([127, 0, 0, 1]), Udp(10500u16), Quic);
43+
let other = multiaddr!(Ip4([127, 0, 0, 1]), Udp(10500u16), QuicV1);
4444

4545
assert_eq!(address.to_string(), "/ip4/127.0.0.1/tcp/1234");
46-
assert_eq!(other.to_string(), "/ip4/127.0.0.1/udp/10500/quic");
46+
assert_eq!(other.to_string(), "/ip4/127.0.0.1/udp/10500/quic-v1");
4747
```
4848

4949
## Maintainers

src/protocol.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const ONION3: u32 = 445;
3737
const P2P: u32 = 421;
3838
const P2P_CIRCUIT: u32 = 290;
3939
const QUIC: u32 = 460;
40+
const QUIC_V1: u32 = 461;
4041
const SCTP: u32 = 132;
4142
const TCP: u32 = 6;
4243
const TLS: u32 = 448;
@@ -92,6 +93,7 @@ pub enum Protocol<'a> {
9293
P2p(Multihash),
9394
P2pCircuit,
9495
Quic,
96+
QuicV1,
9597
Sctp(u16),
9698
Tcp(u16),
9799
Tls,
@@ -182,6 +184,7 @@ impl<'a> Protocol<'a> {
182184
.and_then(|s| read_onion3(&s.to_uppercase()))
183185
.map(|(a, p)| Protocol::Onion3((a, p).into())),
184186
"quic" => Ok(Protocol::Quic),
187+
"quic-v1" => Ok(Protocol::QuicV1),
185188
"ws" => Ok(Protocol::Ws(Cow::Borrowed("/"))),
186189
"wss" => Ok(Protocol::Wss(Cow::Borrowed("/"))),
187190
"x-parity-ws" => {
@@ -314,6 +317,7 @@ impl<'a> Protocol<'a> {
314317
}
315318
P2P_CIRCUIT => Ok((Protocol::P2pCircuit, input)),
316319
QUIC => Ok((Protocol::Quic, input)),
320+
QUIC_V1 => Ok((Protocol::QuicV1, input)),
317321
SCTP => {
318322
let (data, rest) = split_at(2, input)?;
319323
let mut rdr = Cursor::new(data);
@@ -437,6 +441,7 @@ impl<'a> Protocol<'a> {
437441
w.write_u16::<BigEndian>(addr.port())?
438442
}
439443
Protocol::Quic => w.write_all(encode::u32(QUIC, &mut buf))?,
444+
Protocol::QuicV1 => w.write_all(encode::u32(QUIC_V1, &mut buf))?,
440445
Protocol::Utp => w.write_all(encode::u32(UTP, &mut buf))?,
441446
Protocol::Udt => w.write_all(encode::u32(UDT, &mut buf))?,
442447
Protocol::Http => w.write_all(encode::u32(HTTP, &mut buf))?,
@@ -498,6 +503,7 @@ impl<'a> Protocol<'a> {
498503
P2p(a) => P2p(a),
499504
P2pCircuit => P2pCircuit,
500505
Quic => Quic,
506+
QuicV1 => QuicV1,
501507
Sctp(a) => Sctp(a),
502508
Tcp(a) => Tcp(a),
503509
Tls => Tls,
@@ -534,6 +540,7 @@ impl<'a> Protocol<'a> {
534540
P2p(_) => "p2p",
535541
P2pCircuit => "p2p-circuit",
536542
Quic => "quic",
543+
QuicV1 => "quic-v1",
537544
Sctp(_) => "sctp",
538545
Tcp(_) => "tcp",
539546
Tls => "tls",

tests/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ struct Proto(Protocol<'static>);
8888
impl Arbitrary for Proto {
8989
fn arbitrary<G: Gen>(g: &mut G) -> Self {
9090
use Protocol::*;
91-
match u8::arbitrary(g) % 26 {
92-
// TODO: Add Protocol::Quic
91+
match u8::arbitrary(g) % 27 {
9392
0 => Proto(Dccp(Arbitrary::arbitrary(g))),
9493
1 => Proto(Dns(Cow::Owned(SubString::arbitrary(g).0))),
9594
2 => Proto(Dns4(Cow::Owned(SubString::arbitrary(g).0))),
@@ -133,6 +132,7 @@ impl Arbitrary for Proto {
133132
Proto(Onion3((a, std::cmp::max(1, u16::arbitrary(g))).into()))
134133
}
135134
25 => Proto(Tls),
135+
26 => Proto(QuicV1),
136136
_ => panic!("outside range"),
137137
}
138138
}
@@ -579,6 +579,7 @@ fn protocol_stack() {
579579
"p2p-webrtc-star",
580580
"p2p-websocket-star",
581581
"quic",
582+
"quic-v1",
582583
"tls",
583584
"udt",
584585
"utp",

0 commit comments

Comments
 (0)