~aasg/nixexprs

ref: 0b021297578a635bdf65f31b96e02ff38125a319 nixexprs/patches/ipfs-cluster/ipfs-api-via-unix-socket.patch -rw-r--r-- 1.2 KiB
0b021297 — Aluísio Augusto Silva Gonçalves patches/ipfs-cluster: Patch to enable connecting to IPFS via Unix socket 1 year, 1 month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
diff --git i/ipfsconn/ipfshttp/ipfshttp.go w/ipfsconn/ipfshttp/ipfshttp.go
index bae536e..ffef131 100644
--- i/ipfsconn/ipfshttp/ipfshttp.go
+++ w/ipfsconn/ipfshttp/ipfshttp.go
@@ -9,6 +9,7 @@ import (
 	"fmt"
 	"io"
 	"io/ioutil"
+	"net"
 	"net/http"
 	"net/url"
 	"strconv"
@@ -145,15 +146,24 @@ func NewConnector(cfg *Config) (*Connector, error) {
 		nodeMAddr = resolvedAddrs[0]
 	}
 
-	_, nodeAddr, err := manet.DialArgs(nodeMAddr)
+	network, nodeAddr, err := manet.DialArgs(nodeMAddr)
 	if err != nil {
 		return nil, err
 	}
 
 	c := &http.Client{} // timeouts are handled by context timeouts
+	if network == "unix" {
+		socketPath := nodeAddr
+		nodeAddr = "unix"
+		c.Transport = &http.Transport{
+			DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
+				return net.Dial("unix", socketPath)
+			},
+		}
+	}
 	if cfg.Tracing {
 		c.Transport = &ochttp.Transport{
-			Base:           http.DefaultTransport,
+			Base:           c.Transport,
 			Propagation:    &tracecontext.HTTPFormat{},
 			StartOptions:   trace.StartOptions{SpanKind: trace.SpanKindClient},
 			FormatSpanName: func(req *http.Request) string { return req.Host + ":" + req.URL.Path + ":" + req.Method },