File tree Expand file tree Collapse file tree 3 files changed +30
-1
lines changed
Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,10 @@ public IPFS(String host, int port) {
3131 this (host , port , "/api/v0/" );
3232 }
3333
34+ public IPFS (MultiAddress addr ) {
35+ this (addr .getHost (), addr .getTCPPort (), "/api/v0/" );
36+ }
37+
3438 public IPFS (String host , int port , String version ) {
3539 this .host = host ;
3640 this .port = port ;
Original file line number Diff line number Diff line change @@ -20,6 +20,31 @@ public byte[] getBytes() {
2020 return Arrays .copyOfRange (raw , 0 , raw .length );
2121 }
2222
23+ public boolean isTCPIP () {
24+ String [] parts = toString ().substring (1 ).split ("/" );
25+ if (parts .length != 4 )
26+ return false ;
27+ if (!parts [0 ].startsWith ("ip" ))
28+ return false ;
29+ if (!parts [2 ].equals ("tcp" ))
30+ return false ;
31+ return true ;
32+ }
33+
34+ public String getHost () {
35+ String [] parts = toString ().substring (1 ).split ("/" );
36+ if (parts [0 ].startsWith ("ip" ))
37+ return parts [1 ];
38+ throw new IllegalStateException ("This multiaddress doesn't have a host: " +toString ());
39+ }
40+
41+ public int getTCPPort () {
42+ String [] parts = toString ().substring (1 ).split ("/" );
43+ if (parts [2 ].startsWith ("tcp" ))
44+ return Integer .parseInt (parts [3 ]);
45+ throw new IllegalStateException ("This multiaddress doesn't have a tcp port: " +toString ());
46+ }
47+
2348 private static byte [] decodeFromString (String addr ) {
2449 while (addr .endsWith ("/" ))
2550 addr = addr .substring (0 , addr .length ()-1 );
Original file line number Diff line number Diff line change 55
66public class Test {
77
8- IPFS ipfs = new IPFS (" 127.0.0.1" , 5001 );
8+ IPFS ipfs = new IPFS (new MultiAddress ( "/ip4/ 127.0.0.1/tcp/ 5001" ) );
99 @ org .junit .Test
1010 public void base58Test () {
1111 String input = "QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB" ;
You can’t perform that action at this time.
0 commit comments