Skip to content

Commit 00634da

Browse files
authored
Merge pull request #8 from gjeanmart/master
Add support for DNS address
2 parents 1b6c66c + 4475d03 commit 00634da

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/main/java/io/ipfs/multiaddr/MultiAddress.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public boolean isTCPIP() {
4040

4141
public String getHost() {
4242
String[] parts = toString().substring(1).split("/");
43-
if (parts[0].startsWith("ip"))
43+
if (parts[0].startsWith("ip") || parts[0].startsWith("dns"))
4444
return parts[1];
4545
throw new IllegalStateException("This multiaddress doesn't have a host: "+toString());
4646
}

src/test/java/io/ipfs/api/MultiAddressTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,17 @@ public void bytesToString() {
155155
test.accept("/ip4/127.0.0.1/udp/1234/ip4/127.0.0.1/tcp/4321", "047f0000011104d2047f0000010610e1");
156156
}
157157

158+
@Test
159+
public void dns() {
160+
String dns = "mydomain.com";
161+
int port = 5001;
162+
String address = "/dns6/"+dns+"/tcp/"+port+"/https";
163+
MultiAddress multiAddress = new MultiAddress(address);
164+
165+
Assert.assertEquals("host should be equal to " + dns, dns, multiAddress.getHost());
166+
Assert.assertEquals("port should be equal to " + port, port, multiAddress.getTCPPort());
167+
}
168+
158169
public static byte[] fromHex(String hex) {
159170
if (hex.length() % 2 != 0)
160171
throw new IllegalStateException("Uneven number of hex digits!");

0 commit comments

Comments
 (0)