Skip to content

Commit

Permalink
Support connecting to the IPFS API via Unix domain sockets
Browse files Browse the repository at this point in the history
This is based on similar work done for ipfs at ipfs/kubo#6678.
  • Loading branch information
AluisioASG committed Sep 1, 2020
1 parent 3ef09ee commit a89eb92
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ipfsconn/ipfshttp/ipfshttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -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 },
Expand Down

0 comments on commit a89eb92

Please sign in to comment.