@@ -28,6 +28,8 @@ const IP4: u32 = 4;
2828const IP6 : u32 = 41 ;
2929const P2P_WEBRTC_DIRECT : u32 = 276 ;
3030const P2P_WEBRTC_STAR : u32 = 275 ;
31+ const WEBRTC : u32 = 280 ;
32+ const CERTHASH : u32 = 466 ;
3133const P2P_WEBSOCKET_STAR : u32 = 479 ;
3234const MEMORY : u32 = 777 ;
3335const ONION : u32 = 444 ;
@@ -80,6 +82,8 @@ pub enum Protocol<'a> {
8082 Ip6 ( Ipv6Addr ) ,
8183 P2pWebRtcDirect ,
8284 P2pWebRtcStar ,
85+ WebRTC ,
86+ Certhash ( Multihash ) ,
8387 P2pWebSocketStar ,
8488 /// Contains the "port" to contact. Similar to TCP or UDP, 0 means "assign me a port".
8589 Memory ( u64 ) ,
@@ -192,6 +196,12 @@ impl<'a> Protocol<'a> {
192196 }
193197 "p2p-websocket-star" => Ok ( Protocol :: P2pWebSocketStar ) ,
194198 "p2p-webrtc-star" => Ok ( Protocol :: P2pWebRtcStar ) ,
199+ "webrtc" => Ok ( Protocol :: WebRTC ) ,
200+ "certhash" => {
201+ let s = iter. next ( ) . ok_or ( Error :: InvalidProtocolString ) ?;
202+ let ( _base, decoded) = multibase:: decode ( s) ?;
203+ Ok ( Protocol :: Certhash ( Multihash :: from_bytes ( & decoded) ?) )
204+ }
195205 "p2p-webrtc-direct" => Ok ( Protocol :: P2pWebRtcDirect ) ,
196206 "p2p-circuit" => Ok ( Protocol :: P2pCircuit ) ,
197207 "memory" => {
@@ -268,6 +278,12 @@ impl<'a> Protocol<'a> {
268278 }
269279 P2P_WEBRTC_DIRECT => Ok ( ( Protocol :: P2pWebRtcDirect , input) ) ,
270280 P2P_WEBRTC_STAR => Ok ( ( Protocol :: P2pWebRtcStar , input) ) ,
281+ WEBRTC => Ok ( ( Protocol :: WebRTC , input) ) ,
282+ CERTHASH => {
283+ let ( n, input) = decode:: usize ( input) ?;
284+ let ( data, rest) = split_at ( n, input) ?;
285+ Ok ( ( Protocol :: Certhash ( Multihash :: from_bytes ( data) ?) , rest) )
286+ }
271287 P2P_WEBSOCKET_STAR => Ok ( ( Protocol :: P2pWebSocketStar , input) ) ,
272288 MEMORY => {
273289 let ( data, rest) = split_at ( 8 , input) ?;
@@ -441,6 +457,13 @@ impl<'a> Protocol<'a> {
441457 }
442458 Protocol :: P2pWebSocketStar => w. write_all ( encode:: u32 ( P2P_WEBSOCKET_STAR , & mut buf) ) ?,
443459 Protocol :: P2pWebRtcStar => w. write_all ( encode:: u32 ( P2P_WEBRTC_STAR , & mut buf) ) ?,
460+ Protocol :: WebRTC => w. write_all ( encode:: u32 ( WEBRTC , & mut buf) ) ?,
461+ Protocol :: Certhash ( hash) => {
462+ w. write_all ( encode:: u32 ( CERTHASH , & mut buf) ) ?;
463+ let bytes = hash. to_bytes ( ) ;
464+ w. write_all ( encode:: usize ( bytes. len ( ) , & mut encode:: usize_buffer ( ) ) ) ?;
465+ w. write_all ( & bytes) ?
466+ }
444467 Protocol :: P2pWebRtcDirect => w. write_all ( encode:: u32 ( P2P_WEBRTC_DIRECT , & mut buf) ) ?,
445468 Protocol :: P2pCircuit => w. write_all ( encode:: u32 ( P2P_CIRCUIT , & mut buf) ) ?,
446469 Protocol :: Memory ( port) => {
@@ -466,6 +489,8 @@ impl<'a> Protocol<'a> {
466489 Ip6 ( a) => Ip6 ( a) ,
467490 P2pWebRtcDirect => P2pWebRtcDirect ,
468491 P2pWebRtcStar => P2pWebRtcStar ,
492+ WebRTC => WebRTC ,
493+ Certhash ( hash) => Certhash ( hash) ,
469494 P2pWebSocketStar => P2pWebSocketStar ,
470495 Memory ( a) => Memory ( a) ,
471496 Onion ( addr, port) => Onion ( Cow :: Owned ( addr. into_owned ( ) ) , port) ,
@@ -502,6 +527,12 @@ impl<'a> fmt::Display for Protocol<'a> {
502527 Ip6 ( addr) => write ! ( f, "/ip6/{}" , addr) ,
503528 P2pWebRtcDirect => f. write_str ( "/p2p-webrtc-direct" ) ,
504529 P2pWebRtcStar => f. write_str ( "/p2p-webrtc-star" ) ,
530+ WebRTC => f. write_str ( "/webrtc" ) ,
531+ Certhash ( hash) => write ! (
532+ f,
533+ "/certhash/{}" ,
534+ multibase:: encode( multibase:: Base :: Base64Url , hash. to_bytes( ) )
535+ ) ,
505536 P2pWebSocketStar => f. write_str ( "/p2p-websocket-star" ) ,
506537 Memory ( port) => write ! ( f, "/memory/{}" , port) ,
507538 Onion ( addr, port) => {
0 commit comments