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) {
31
31
this (host , port , "/api/v0/" );
32
32
}
33
33
34
+ public IPFS (MultiAddress addr ) {
35
+ this (addr .getHost (), addr .getTCPPort (), "/api/v0/" );
36
+ }
37
+
34
38
public IPFS (String host , int port , String version ) {
35
39
this .host = host ;
36
40
this .port = port ;
Original file line number Diff line number Diff line change @@ -20,6 +20,31 @@ public byte[] getBytes() {
20
20
return Arrays .copyOfRange (raw , 0 , raw .length );
21
21
}
22
22
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
+
23
48
private static byte [] decodeFromString (String addr ) {
24
49
while (addr .endsWith ("/" ))
25
50
addr = addr .substring (0 , addr .length ()-1 );
Original file line number Diff line number Diff line change 5
5
6
6
public class Test {
7
7
8
- IPFS ipfs = new IPFS (" 127.0.0.1" , 5001 );
8
+ IPFS ipfs = new IPFS (new MultiAddress ( "/ip4/ 127.0.0.1/tcp/ 5001" ) );
9
9
@ org .junit .Test
10
10
public void base58Test () {
11
11
String input = "QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB" ;
You can’t perform that action at this time.
0 commit comments