@@ -25,7 +25,7 @@ public enum PinType {all, direct, indirect, recursive}
25
25
public final String host ;
26
26
public final int port ;
27
27
public final String protocol ;
28
- private final String version ;
28
+ private final String apiVersion ;
29
29
private final int connectTimeoutMillis ;
30
30
private final int readTimeoutMillis ;
31
31
public final Key key = new Key ();
@@ -36,6 +36,7 @@ public enum PinType {all, direct, indirect, recursive}
36
36
public final IPFSObject object = new IPFSObject ();
37
37
public final Swarm swarm = new Swarm ();
38
38
public final Bootstrap bootstrap = new Bootstrap ();
39
+ public final Bitswap bitswap = new Bitswap ();
39
40
public final Block block = new Block ();
40
41
public final CidAPI cid = new CidAPI ();
41
42
public final Dag dag = new Dag ();
@@ -50,6 +51,7 @@ public enum PinType {all, direct, indirect, recursive}
50
51
public final Stats stats = new Stats ();
51
52
public final Name name = new Name ();
52
53
public final Pubsub pubsub = new Pubsub ();
54
+ public final VersionAPI version = new VersionAPI ();
53
55
54
56
public IPFS (String host , int port ) {
55
57
this (host , port , "/api/v0/" , false );
@@ -81,7 +83,7 @@ public IPFS(String host, int port, String version, int connectTimeoutMillis, int
81
83
this .protocol = "http" ;
82
84
}
83
85
84
- this .version = version ;
86
+ this .apiVersion = version ;
85
87
// Check IPFS is sufficiently recent
86
88
try {
87
89
Version detected = Version .parse (version ());
@@ -98,7 +100,7 @@ public IPFS(String host, int port, String version, int connectTimeoutMillis, int
98
100
* @return current IPFS object with configured timeout
99
101
*/
100
102
public IPFS timeout (int timeout ) {
101
- return new IPFS (host , port , version , timeout , timeout , protocol .equals ("https" ));
103
+ return new IPFS (host , port , apiVersion , timeout , timeout , protocol .equals ("https" ));
102
104
}
103
105
104
106
public String shutdown () throws IOException {
@@ -118,7 +120,7 @@ public List<MerkleNode> add(NamedStreamable file, boolean wrap, boolean hashOnly
118
120
}
119
121
120
122
public List <MerkleNode > add (List <NamedStreamable > files , boolean wrap , boolean hashOnly ) throws IOException {
121
- Multipart m = new Multipart (protocol + "://" + host + ":" + port + version + "add?stream-channels=true&w=" +wrap + "&n=" +hashOnly , "UTF-8" );
123
+ Multipart m = new Multipart (protocol + "://" + host + ":" + port + apiVersion + "add?stream-channels=true&w=" +wrap + "&n=" +hashOnly , "UTF-8" );
122
124
for (NamedStreamable file : files ) {
123
125
if (file .isDirectory ()) {
124
126
m .addSubtree (Paths .get ("" ), file );
@@ -269,7 +271,7 @@ public Map ls() throws IOException {
269
271
270
272
public class MultibaseAPI {
271
273
public String decode (NamedStreamable encoded_file ) {
272
- Multipart m = new Multipart (protocol + "://" + host + ":" + port + version +
274
+ Multipart m = new Multipart (protocol + "://" + host + ":" + port + apiVersion +
273
275
"multibase/decode" , "UTF-8" );
274
276
try {
275
277
if (encoded_file .isDirectory ()) {
@@ -284,7 +286,7 @@ public String decode(NamedStreamable encoded_file) {
284
286
}
285
287
public String encode (Optional <String > encoding , NamedStreamable file ) {
286
288
String b = encoding .map (f -> "?b=" + f ).orElse ("?b=base64url" );
287
- Multipart m = new Multipart (protocol + "://" + host + ":" + port + version +
289
+ Multipart m = new Multipart (protocol + "://" + host + ":" + port + apiVersion +
288
290
"multibase/encode" + b , "UTF-8" );
289
291
try {
290
292
if (file .isDirectory ()) {
@@ -302,7 +304,7 @@ public List<Map> list(boolean prefix, boolean numeric) throws IOException {
302
304
}
303
305
public String transcode (Optional <String > encoding , NamedStreamable file ) {
304
306
String b = encoding .map (f -> "?b=" + f ).orElse ("?b=base64url" );
305
- Multipart m = new Multipart (protocol + "://" + host + ":" + port + version +
307
+ Multipart m = new Multipart (protocol + "://" + host + ":" + port + apiVersion +
306
308
"multibase/transcode" + b , "UTF-8" );
307
309
try {
308
310
if (file .isDirectory ()) {
@@ -341,6 +343,13 @@ public Map version() throws IOException {
341
343
}
342
344
}
343
345
346
+
347
+ public class VersionAPI {
348
+ public Map versionDeps () throws IOException {
349
+ return retrieveMap ("version/deps" );
350
+ }
351
+ }
352
+
344
353
public class Pubsub {
345
354
public Object ls () throws IOException {
346
355
return retrieveAndParse ("pubsub/ls" );
@@ -363,7 +372,7 @@ public Object peers(String topic) throws IOException {
363
372
*/
364
373
public void pub (String topic , String data ) {
365
374
String encodedTopic = Multibase .encode (Multibase .Base .Base64Url , topic .getBytes ());
366
- Multipart m = new Multipart (protocol +"://" + host + ":" + port + version +"pubsub/pub?arg=" + encodedTopic , "UTF-8" );
375
+ Multipart m = new Multipart (protocol +"://" + host + ":" + port + apiVersion +"pubsub/pub?arg=" + encodedTopic , "UTF-8" );
367
376
try {
368
377
m .addFilePart ("file" , Paths .get ("" ), new NamedStreamable .ByteArrayWrapper (data .getBytes ()));
369
378
String res = m .finish ();
@@ -445,7 +454,7 @@ public List<MerkleNode> put(List<byte[]> data, Optional<String> format) throws I
445
454
446
455
public MerkleNode put (byte [] data , Optional <String > format ) throws IOException {
447
456
String fmt = format .map (f -> "&format=" + f ).orElse ("" );
448
- Multipart m = new Multipart (protocol +"://" + host + ":" + port + version +"block/put?stream-channels=true" + fmt , "UTF-8" );
457
+ Multipart m = new Multipart (protocol +"://" + host + ":" + port + apiVersion +"block/put?stream-channels=true" + fmt , "UTF-8" );
449
458
try {
450
459
m .addFilePart ("file" , Paths .get ("" ), new NamedStreamable .ByteArrayWrapper (data ));
451
460
String res = m .finish ();
@@ -465,7 +474,7 @@ public Map stat(Multihash hash) throws IOException {
465
474
public class IPFSObject {
466
475
@ Deprecated
467
476
public List <MerkleNode > put (List <byte []> data ) throws IOException {
468
- Multipart m = new Multipart (protocol +"://" + host + ":" + port + version +"object/put?stream-channels=true" , "UTF-8" );
477
+ Multipart m = new Multipart (protocol +"://" + host + ":" + port + apiVersion +"object/put?stream-channels=true" , "UTF-8" );
469
478
for (byte [] f : data )
470
479
m .addFilePart ("file" , Paths .get ("" ), new NamedStreamable .ByteArrayWrapper (f ));
471
480
String res = m .finish ();
@@ -475,7 +484,7 @@ public List<MerkleNode> put(List<byte[]> data) throws IOException {
475
484
public List <MerkleNode > put (String encoding , List <byte []> data ) throws IOException {
476
485
if (!"json" .equals (encoding ) && !"protobuf" .equals (encoding ))
477
486
throw new IllegalArgumentException ("Encoding must be json or protobuf" );
478
- Multipart m = new Multipart (protocol +"://" + host + ":" + port + version +"object/put?stream-channels=true&encoding=" +encoding , "UTF-8" );
487
+ Multipart m = new Multipart (protocol +"://" + host + ":" + port + apiVersion +"object/put?stream-channels=true&encoding=" +encoding , "UTF-8" );
479
488
for (byte [] f : data )
480
489
m .addFilePart ("file" , Paths .get ("" ), new NamedStreamable .ByteArrayWrapper (f ));
481
490
String res = m .finish ();
@@ -529,7 +538,7 @@ public MerkleNode patch(Multihash base, String command, Optional<byte[]> data, O
529
538
case "append-data" :
530
539
if (!data .isPresent ())
531
540
throw new IllegalStateException ("set-data requires data!" );
532
- Multipart m = new Multipart (protocol +"://" + host + ":" + port + version +"object/patch/" +command +"?arg=" +base .toBase58 ()+"&stream-channels=true" , "UTF-8" );
541
+ Multipart m = new Multipart (protocol +"://" + host + ":" + port + apiVersion +"object/patch/" +command +"?arg=" +base .toBase58 ()+"&stream-channels=true" , "UTF-8" );
533
542
m .addFilePart ("file" , Paths .get ("" ), new NamedStreamable .ByteArrayWrapper (data .get ()));
534
543
String res = m .finish ();
535
544
return MerkleNode .fromJSON (JSONParser .parse (res ));
@@ -665,7 +674,7 @@ public Map stat(String path) throws IOException {
665
674
public String write (String path , NamedStreamable uploadFile , boolean create , boolean parents ) throws IOException {
666
675
String arg = URLEncoder .encode (path , "UTF-8" );
667
676
String rpcParams = "files/write?arg=" + arg + "&create=" + create + "&parents=" + parents ;
668
- URL target = new URL (protocol ,host ,port ,version + rpcParams );
677
+ URL target = new URL (protocol ,host ,port ,apiVersion + rpcParams );
669
678
Multipart m = new Multipart (target .toString (),"UTF-8" );
670
679
if (uploadFile .isDirectory ()) {
671
680
throw new IllegalArgumentException ("Input must be a file" );
@@ -704,6 +713,21 @@ public List<MultiAddress> bootstrap() throws IOException {
704
713
}).collect (Collectors .toList ());
705
714
}
706
715
716
+ public class Bitswap {
717
+ public Map ledger (Multihash peerId ) throws IOException {
718
+ return retrieveMap ("bitswap/ledger?arg=" +peerId );
719
+ }
720
+
721
+ public String reprovide () throws IOException {
722
+ return retrieveString ("bitswap/reprovide" );
723
+ }
724
+ public Map stat () throws IOException {
725
+ return retrieveMap ("bitswap/stat" );
726
+ }
727
+ public Map wantlist (Multihash peerId ) throws IOException {
728
+ return retrieveMap ("bitswap/wantlist?peer=" + peerId );
729
+ }
730
+ }
707
731
public class Bootstrap {
708
732
709
733
public List <MultiAddress > add (MultiAddress addr ) throws IOException {
@@ -762,7 +786,12 @@ public Map<Multihash, List<MultiAddress>> addrs() throws IOException {
762
786
.map (MultiAddress ::new )
763
787
.collect (Collectors .toList ())));
764
788
}
765
-
789
+ public Map listenAddrs () throws IOException {
790
+ return retrieveMap ("swarm/addrs/listen" );
791
+ }
792
+ public Map localAddrs (boolean showPeerId ) throws IOException {
793
+ return retrieveMap ("swarm/addrs/local?id=" + showPeerId );
794
+ }
766
795
public Map connect (MultiAddress multiAddr ) throws IOException {
767
796
Map m = retrieveMap ("swarm/connect?arg=" +multiAddr );
768
797
return m ;
@@ -772,6 +801,24 @@ public Map disconnect(MultiAddress multiAddr) throws IOException {
772
801
Map m = retrieveMap ("swarm/disconnect?arg=" +multiAddr );
773
802
return m ;
774
803
}
804
+ public Map filters () throws IOException {
805
+ return retrieveMap ("swarm/filters" );
806
+ }
807
+ public Map filtersAdd (String multiAddrFilter ) throws IOException {
808
+ return retrieveMap ("swarm/filters/add?arg=" +multiAddrFilter );
809
+ }
810
+ public Map filtersRm (String multiAddrFilter ) throws IOException {
811
+ return retrieveMap ("swarm/filters/rm?arg=" +multiAddrFilter );
812
+ }
813
+ public Map peeringLs () throws IOException {
814
+ return retrieveMap ("swarm/peering/ls" );
815
+ }
816
+ public Map peeringAdd (MultiAddress multiAddr ) throws IOException {
817
+ return retrieveMap ("swarm/peering/add?arg=" +multiAddr );
818
+ }
819
+ public Map peeringRm (Multihash multiAddr ) throws IOException {
820
+ return retrieveMap ("swarm/peering/rm?arg=" +multiAddr );
821
+ }
775
822
}
776
823
777
824
public class Dag {
@@ -792,7 +839,7 @@ public MerkleNode put(byte[] object, String outputFormat) throws IOException {
792
839
}
793
840
794
841
public MerkleNode put (String inputFormat , byte [] object , String outputFormat ) throws IOException {
795
- String prefix = protocol + "://" + host + ":" + port + version ;
842
+ String prefix = protocol + "://" + host + ":" + port + apiVersion ;
796
843
Multipart m = new Multipart (prefix + "dag/put/?stream-channels=true&input-codec=" + inputFormat + "&store-codec=" + outputFormat , "UTF-8" );
797
844
m .addFilePart ("file" , Paths .get ("" ), new NamedStreamable .ByteArrayWrapper (object ));
798
845
String res = m .finish ();
@@ -886,7 +933,7 @@ public Map profileApply(String profile, boolean dryRun) throws IOException {
886
933
}
887
934
888
935
public void replace (NamedStreamable file ) throws IOException {
889
- Multipart m = new Multipart (protocol +"://" + host + ":" + port + version +"config/replace?stream-channels=true" , "UTF-8" );
936
+ Multipart m = new Multipart (protocol +"://" + host + ":" + port + apiVersion +"config/replace?stream-channels=true" , "UTF-8" );
890
937
m .addFilePart ("file" , Paths .get ("" ), file );
891
938
String res = m .finish ();
892
939
}
@@ -957,12 +1004,12 @@ private void retrieveAndParseStream(String path, Consumer<Object> results, Consu
957
1004
}
958
1005
959
1006
private String retrieveString (String path ) throws IOException {
960
- URL target = new URL (protocol , host , port , version + path );
1007
+ URL target = new URL (protocol , host , port , apiVersion + path );
961
1008
return new String (IPFS .get (target , connectTimeoutMillis , readTimeoutMillis ));
962
1009
}
963
1010
964
1011
private byte [] retrieve (String path ) throws IOException {
965
- URL target = new URL (protocol , host , port , version + path );
1012
+ URL target = new URL (protocol , host , port , apiVersion + path );
966
1013
return IPFS .get (target , connectTimeoutMillis , readTimeoutMillis );
967
1014
}
968
1015
@@ -1055,7 +1102,7 @@ private List<Object> getAndParseStream(String path) throws IOException {
1055
1102
}
1056
1103
1057
1104
private InputStream retrieveStream (String path ) throws IOException {
1058
- URL target = new URL (protocol , host , port , version + path );
1105
+ URL target = new URL (protocol , host , port , apiVersion + path );
1059
1106
return IPFS .getStream (target , connectTimeoutMillis , readTimeoutMillis );
1060
1107
}
1061
1108
@@ -1069,7 +1116,7 @@ private static InputStream getStream(URL target, int connectTimeoutMillis, int r
1069
1116
}
1070
1117
1071
1118
private Map postMap (String path , byte [] body , Map <String , String > headers ) throws IOException {
1072
- URL target = new URL (protocol , host , port , version + path );
1119
+ URL target = new URL (protocol , host , port , apiVersion + path );
1073
1120
return (Map ) JSONParser .parse (new String (post (target , body , headers , connectTimeoutMillis , readTimeoutMillis )));
1074
1121
}
1075
1122
0 commit comments