Skip to content

Commit

Permalink
Fix #462: Support DNS multiaddresses for node_multiaddress
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
  • Loading branch information
hsanjuan committed Jun 12, 2018
1 parent a668414 commit 78a25e3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.9-stretch AS builder
FROM golang:1.10-stretch AS builder
MAINTAINER Hector Sanjuan <hector@protocol.ai>

# This dockerfile builds and runs ipfs-cluster-service.
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.9-stretch AS builder
FROM golang:1.10-stretch AS builder
MAINTAINER Hector Sanjuan <hector@protocol.ai>

# This build state just builds the cluster binaries
Expand Down
19 changes: 18 additions & 1 deletion ipfsconn/ipfshttp/ipfshttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ import (
logging "github.com/ipfs/go-log"
peer "github.com/libp2p/go-libp2p-peer"
ma "github.com/multiformats/go-multiaddr"
madns "github.com/multiformats/go-multiaddr-dns"
manet "github.com/multiformats/go-multiaddr-net"
)

// DNSTimeout is used when resolving DNS multiaddresses in this module
var DNSTimeout = 5 * time.Second

var logger = logging.Logger("ipfshttp")

// Connector implements the IPFSConnector interface
Expand Down Expand Up @@ -112,7 +116,20 @@ func NewConnector(cfg *Config) (*Connector, error) {
return nil, err
}

_, nodeAddr, err := manet.DialArgs(cfg.NodeAddr)
nodeMAddr := cfg.NodeAddr
// dns multiaddresses need to be resolved first
if madns.Matches(nodeMAddr) {
ctx, cancel := context.WithTimeout(context.Background(), DNSTimeout)
defer cancel()
resolvedAddrs, err := madns.Resolve(ctx, cfg.NodeAddr)
if err != nil {
logger.Error(err)
return nil, err
}
nodeMAddr = resolvedAddrs[0]
}

_, nodeAddr, err := manet.DialArgs(nodeMAddr)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pstoremgr/pstoremgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var logger = logging.Logger("pstoremgr")

// Timeouts for network operations triggered by the Manager
var (
DNSTimeout = 2 * time.Second
DNSTimeout = 5 * time.Second
ConnectTimeout = 10 * time.Second
)

Expand Down

0 comments on commit 78a25e3

Please sign in to comment.