Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

jsipfs daemon does not work properly with java ipfs wrapper #1362

Closed
bastiao opened this issue May 21, 2018 · 2 comments
Closed

jsipfs daemon does not work properly with java ipfs wrapper #1362

bastiao opened this issue May 21, 2018 · 2 comments

Comments

@bastiao
Copy link

bastiao commented May 21, 2018

  • Version:

js-ipfs version: 0.28.2-
Repo version: 6
System version: x64/darwin
Node.js version: v7.2.1

  • Platform:

Darwin Luiss-MacBook-Pro.local 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64 x86_64

  • Subsystem: Unknown

Type: Bug

Severity: Low

Description: The jsipfs daemon does not work properly if you use java ipfs api wrapper. The Java IPFS Wrapper works with ipfs daemon from ipfs.io binaries.

The main problem is related with API. Get like that " http://127.0.0.1:5001/api/v0/get/QmdWFrmDRZmAG8kMX5UG2RmEWpNbUkppeuiLcvNTBnU8df" is not available in jsipfs daemon.

Instead, it accepts a POST with: http://127.0.0.1:5001/api/v0/get?arg=...&stream-channel=true

If you want to better debugging use wireshark.

For use different languages with the jsipfs daemon, it should be nice if this API will also be supported.

Steps to reproduce the error:

  1. Run jsipfs daemon
    $ jsipfs init
    $ jsipfs daemon

  2. Run the following Java code:

IPFS ipfs = new IPFS("/ip4/127.0.0.1/tcp/5001");

NamedStreamable.ByteArrayWrapper file = new NamedStreamable.ByteArrayWrapper("hello.txt", "G'day world! IPFS rocks!".getBytes());
MerkleNode addResult = ipfs.add(file).get(0);

Multihash filePointer = Multihash filePointer = Multihash.fromBase58(addResult.hash.toBase58());
byte[] fileContents = ipfs.cat(filePointer);

It will retrieve


java.lang.RuntimeException: IOException contacting IPFS daemon.
Trailer: null {"Message":"Sorry, something went wrong, please retrace your steps.","Code":1}

	at io.ipfs.api.IPFS.get(IPFS.java:592)
	at io.ipfs.api.IPFS.retrieve(IPFS.java:571)
	at io.ipfs.api.IPFS.get(IPFS.java:105)
	at com.bmdsoftware.pacs.dicoogle.ipfs.TestIPFS.ipfs(TestIPFS.java:59)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.io.FileNotFoundException: http://127.0.0.1:5001/api/v0/get/QmdWFrmDRZmAG8kMX5UG2RmEWpNbUkppeuiLcvNTBnU8df
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1872)
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
	at io.ipfs.api.IPFS.get(IPFS.java:580)
	... 24 more

@alanshaw
Copy link
Member

Hey @bastiao thanks for noticing the issue, the get HTTP API in JS IPFS conforms with the API docs. I'm hesitant to add a new route to the HTTP API to emulate an undocumented API in Go IPFS. It's a bunch of work to create something that we have no spec for and no idea how long it will be around for.

It looks like it would be considerably easier to change to Java IPFS API to comply with the API docs:

https://github.com/ipfs/java-ipfs-api/blob/8d2a2fb9ddcdb20715679c0cefe8cecc33ed7612/src/main/java/io/ipfs/api/IPFS.java#L108-L110

I think this would just need to change to:

public byte[] get(Multihash hash) throws IOException {
    return retrieve("get?arg=" + hash);
}

Would you mind opening an issue over on java-ipfs-api?

@bastiao
Copy link
Author

bastiao commented May 22, 2018

@alanshaw I will go further it and let you know.
Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants