[ 
https://issues.apache.org/jira/browse/DRILL-7745?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17177091#comment-17177091
 ] 

ASF GitHub Bot commented on DRILL-7745:
---------------------------------------

dbw9580 commented on a change in pull request #2084:
URL: https://github.com/apache/drill/pull/2084#discussion_r470025016



##########
File path: 
contrib/storage-ipfs/src/main/java/org/apache/drill/exec/store/ipfs/IPFSCompat.java
##########
@@ -0,0 +1,284 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.drill.exec.store.ipfs;
+
+import io.ipfs.api.IPFS;
+import io.ipfs.api.JSONParser;
+import io.ipfs.multihash.Multihash;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+
+/**
+ * Compatibility fixes for java-ipfs-http-client library
+ *
+ * Supports IPFS up to version v0.4.23, due to new restrictions enforcing all 
API calls to be made with POST method.
+ * Upstream issue tracker: 
https://github.com/ipfs-shipyard/java-ipfs-http-client/issues/157
+ */
+public class IPFSCompat {
+  public final String host;
+  public final int port;
+  private final String version;
+  public final String protocol;
+  public final int readTimeout;
+  public static final int DEFAULT_READ_TIMEOUT = 0;
+
+  public final DHT dht = new DHT();
+  public final Name name = new Name();
+
+  public IPFSCompat(IPFS ipfs) {
+    this(ipfs.host, ipfs.port);
+  }
+
+  public IPFSCompat(String host, int port) {
+    this(host, port, "/api/v0/", false, DEFAULT_READ_TIMEOUT);
+  }
+
+  public IPFSCompat(String host, int port, String version, boolean ssl, int 
readTimeout) {
+    this.host = host;
+    this.port = port;
+
+    if(ssl) {
+      this.protocol = "https";
+    } else {
+      this.protocol = "http";
+    }
+
+    this.version = version;
+    this.readTimeout = readTimeout;
+  }
+
+  /**
+   * Resolve names to IPFS CIDs.
+   * See <a 
href="https://docs.ipfs.io/reference/http/api/#api-v0-resolve";>resolve in IPFS 
doc</a>.
+   * @param scheme the scheme of the name to resolve, usually IPFS or IPNS
+   * @param path the path to the object
+   * @param recursive whether recursively resolve names until it is a IPFS CID
+   * @return a Map of JSON object, with the result as the value of key "Path"
+   */
+  public Map resolve(String scheme, String path, boolean recursive) {
+    AtomicReference<Map> ret = new AtomicReference<>();
+    getObjectStream(
+        "resolve?arg=/" + scheme+"/"+path +"&r="+recursive,
+        res -> {
+          ret.set((Map) res);
+          return true;
+        },
+        err -> {
+          throw new RuntimeException(err);
+        }
+    );
+    return ret.get();
+  }
+
+  public class DHT {
+    /**
+     * Find internet addresses of a given peer.
+     * See <a 
href="https://docs.ipfs.io/reference/http/api/#api-v0-dht-findpeer";>dht/findpeer
 in IPFS doc</a>.
+     * @param id the id of the peer to query
+     * @param timeout timeout value in seconds
+     * @param executor executor
+     * @return List of Multiaddresses of the peer
+     */
+    public List<String> findpeerListTimeout(Multihash id, int timeout, 
ExecutorService executor) {
+      AtomicReference<List<String>> ret = new AtomicReference<>();
+      timeLimitedExec(
+          "name/resolve?arg=" + id,
+          timeout,
+          res -> {
+            Map peer = (Map) res;

Review comment:
       Made some changes in 39bab37.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Add storage plugin for IPFS
> ---------------------------
>
>                 Key: DRILL-7745
>                 URL: https://issues.apache.org/jira/browse/DRILL-7745
>             Project: Apache Drill
>          Issue Type: New Feature
>          Components: Storage - Other
>    Affects Versions: 1.18.0
>            Reporter: Bowen Ding
>            Assignee: Bowen Ding
>            Priority: Major
>
> See introduction here: [https://github.com/bdchain/Minerva]
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to