Skip to content

Commit 6293cd4

Browse files
committed
name.publish and name.resolve implemented
1 parent 162d358 commit 6293cd4

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/org/ipfs/IPFS.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,19 @@ public byte[] data(MerkleNode merkleObject) throws IOException {
164164
}
165165

166166
class Name {
167-
// TODO publish
167+
public Map publish(MerkleNode node) throws IOException {
168+
return publish(Optional.empty(), node);
169+
}
168170

169-
// TODO resolve
171+
public Map publish(Optional<String> id, MerkleNode node) throws IOException {
172+
Map res = (Map) retrieveAndParse("name/publish?arg=" + (id.isPresent() ? id+"&arg=" : "") + "/ipfs/"+node.hash);
173+
return res;
174+
}
175+
176+
public String resolve(String addr) throws IOException {
177+
Map res = (Map) retrieveAndParse("name/resolve?arg=" + addr);
178+
return (String)res.get("Path");
179+
}
170180
}
171181

172182
class DHT {

test/org/ipfs/Test.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@ public void fileTest() {
9696
}
9797
}
9898

99+
@org.junit.Test
100+
public void nameTest() {
101+
try {
102+
MerkleNode pointer = new MerkleNode("QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB");
103+
Map pub = ipfs.name.publish(pointer);
104+
String resolved = ipfs.name.resolve((String)pub.get("Name"));
105+
System.out.println(resolved);
106+
} catch (IOException e) {
107+
throw new RuntimeException(e);
108+
}
109+
}
110+
99111
@org.junit.Test
100112
public void dnsTest() {
101113
try {

0 commit comments

Comments
 (0)