Skip to content

Commit f0ffe2a

Browse files
committed
Added bootstrap.add and bootstrap.rm
1 parent d017fa8 commit f0ffe2a

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/org/ipfs/IPFS.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class IPFS {
1616
public final Repo repo = new Repo();
1717
public final IPFSObject object = new IPFSObject();
1818
public final Swarm swarm = new Swarm();
19+
public final Bootstrap bootstrap = new Bootstrap();
1920
public final Block block = new Block();
2021
public final Diag diag = new Diag();
2122
public final Config config = new Config();
@@ -221,8 +222,26 @@ public Map ls(String path) throws IOException {
221222

222223
// Network commands
223224

224-
public Map bootstrap() throws IOException {
225-
return retrieveMap("bootstrap/");
225+
public List<MultiAddress> bootstrap() throws IOException {
226+
return ((List<String>)retrieveMap("bootstrap/").get("Peers")).stream().map(x -> new MultiAddress(x)).collect(Collectors.toList());
227+
}
228+
229+
class Bootstrap {
230+
public List<MultiAddress> list() throws IOException {
231+
return bootstrap();
232+
}
233+
234+
public List<MultiAddress> add(MultiAddress addr) throws IOException {
235+
return ((List<String>)retrieveMap("bootstrap/add?arg="+addr).get("Peers")).stream().map(x -> new MultiAddress(x)).collect(Collectors.toList());
236+
}
237+
238+
public List<MultiAddress> rm(MultiAddress addr) throws IOException {
239+
return rm(addr, false);
240+
}
241+
242+
public List<MultiAddress> rm(MultiAddress addr, boolean all) throws IOException {
243+
return ((List<String>)retrieveMap("bootstrap/rm?"+(all ? "all=true&":"")+"arg="+addr).get("Peers")).stream().map(x -> new MultiAddress(x)).collect(Collectors.toList());
244+
}
226245
}
227246

228247
/* ipfs swarm is a tool to manipulate the network swarm. The swarm is the

test/org/ipfs/Test.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void nameTest() {
110110
try {
111111
MerkleNode pointer = new MerkleNode("QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB");
112112
Map pub = ipfs.name.publish(pointer);
113-
String resolved = ipfs.name.resolve((String)pub.get("Name"));
113+
String resolved = ipfs.name.resolve((String) pub.get("Name"));
114114
} catch (IOException e) {
115115
throw new RuntimeException(e);
116116
}
@@ -173,7 +173,6 @@ public void swarmTest() {
173173
String multiaddr = "/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ";
174174
Map connect = ipfs.swarm.connect(multiaddr);
175175
Map disconnect = ipfs.swarm.disconnect(multiaddr);
176-
Map bootstrap = ipfs.bootstrap();
177176
Map<String, Object> addrs = ipfs.swarm.addrs();
178177
if (addrs.size() > 0) {
179178
Map id = ipfs.id(addrs.keySet().stream().findAny().get());
@@ -186,6 +185,19 @@ public void swarmTest() {
186185
}
187186
}
188187

188+
@org.junit.Test
189+
public void bootstrapTest() {
190+
try {
191+
List<MultiAddress> bootstrap = ipfs.bootstrap.list();
192+
System.out.println(bootstrap);
193+
List<MultiAddress> rm = ipfs.bootstrap.rm(bootstrap.get(0), false);
194+
List<MultiAddress> add = ipfs.bootstrap.add(bootstrap.get(0));
195+
System.out.println();
196+
} catch (IOException e) {
197+
throw new RuntimeException(e);
198+
}
199+
}
200+
189201
@org.junit.Test
190202
public void diagTest() {
191203
try {

0 commit comments

Comments
 (0)