@@ -16,15 +16,20 @@ enum Type {
1616 UDP (17 , 16 , "udp" ),
1717 DCCP (33 , 16 , "dccp" ),
1818 IP6 (41 , 128 , "ip6" ),
19+ DNS4 (54 , LENGTH_PREFIXED_VAR_SIZE , "dns4" ),
20+ DNS6 (55 , LENGTH_PREFIXED_VAR_SIZE , "dns6" ),
21+ DNSADDR (56 , LENGTH_PREFIXED_VAR_SIZE , "dnsaddr" ),
1922 SCTP (132 , 16 , "sctp" ),
2023 UTP (301 , 0 , "utp" ),
2124 UDT (302 , 0 , "udt" ),
2225 UNIX (400 , LENGTH_PREFIXED_VAR_SIZE , "unix" ),
2326 IPFS (421 , LENGTH_PREFIXED_VAR_SIZE , "ipfs" ),
24- QUIC (460 , 0 , "quic" ),
2527 HTTPS (443 , 0 , "https" ),
26- HTTP (480 , 0 , "http" ),
27- ONION (444 , 80 , "onion" );
28+ ONION (444 , 80 , "onion" ),
29+ QUIC (460 , 0 , "quic" ),
30+ WS (477 , 0 , "ws" ),
31+ P2PCIRCUIT (290 , 0 , "p2p-circuit" ),
32+ HTTP (480 , 0 , "http" );
2833
2934 public final int code , size ;
3035 public final String name ;
@@ -92,15 +97,16 @@ public byte[] addressToBytes(String addr) {
9297 if (x > 65535 )
9398 throw new IllegalStateException ("Failed to parse " +type .name +" address " +addr + " (> 65535" );
9499 return new byte []{(byte )(x >>8 ), (byte )x };
95- case IPFS :
100+ case IPFS : {
96101 Multihash hash = Cid .decode (addr );
97102 ByteArrayOutputStream bout = new ByteArrayOutputStream ();
98103 byte [] hashBytes = hash .toBytes ();
99- byte [] varint = new byte [(32 - Integer .numberOfLeadingZeros (hashBytes .length )+ 6 )/ 7 ];
104+ byte [] varint = new byte [(32 - Integer .numberOfLeadingZeros (hashBytes .length ) + 6 ) / 7 ];
100105 putUvarint (varint , hashBytes .length );
101106 bout .write (varint );
102107 bout .write (hashBytes );
103108 return bout .toByteArray ();
109+ }
104110 case ONION : {
105111 String [] split = addr .split (":" );
106112 if (split .length != 2 )
@@ -138,11 +144,23 @@ public byte[] addressToBytes(String addr) {
138144 dout .flush ();
139145 return b .toByteArray ();
140146 }
147+ case DNS4 :
148+ case DNS6 :
149+ case DNSADDR : {
150+ ByteArrayOutputStream bout = new ByteArrayOutputStream ();
151+ byte [] hashBytes = addr .getBytes ();
152+ byte [] varint = new byte [(32 - Integer .numberOfLeadingZeros (hashBytes .length ) + 6 ) / 7 ];
153+ putUvarint (varint , hashBytes .length );
154+ bout .write (varint );
155+ bout .write (hashBytes );
156+ return bout .toByteArray ();
157+ }
158+ default :
159+ throw new IllegalStateException ("Unknown multiaddr type: " + type );
141160 }
142161 } catch (IOException e ) {
143162 throw new RuntimeException (e );
144163 }
145- throw new IllegalStateException ("Failed to parse address: " +addr );
146164 }
147165
148166 public String readAddress (InputStream in ) throws IOException {
@@ -175,6 +193,12 @@ public String readAddress(InputStream in) throws IOException {
175193 buf = new byte [sizeForAddress ];
176194 read (in , buf );
177195 return new String (buf );
196+ case DNS4 :
197+ case DNS6 :
198+ case DNSADDR :
199+ buf = new byte [sizeForAddress ];
200+ read (in , buf );
201+ return new String (buf );
178202 }
179203 throw new IllegalStateException ("Unimplemented protocol type: " +type .name );
180204 }
0 commit comments