Skip to content

Commit 2c5e768

Browse files
authored
feat: add IPNS and DNSLink resolution support (#114)
* feat: add IPNS and DNSLink resolution support - resolve IPNS names and DNSLinks to CIDs - detect and handle PeerIDs (CIDv1 and legacy formats) - use delegated-ipfs.dev DoH endpoint for consistent DNS resolution - disable caching for fresh diagnostic results - show resolution info in UI with diagnostic links * test: add unit tests for IPNS/DNSLink resolution - add tests for buildDiagnosticURL, resolveInput, resolveMutablePath - cover all 3 PeerID formats from libp2p spec (CIDv1, legacy Qm, Ed25519) - fix bug: PeerID v1 now correctly sets IsMutableInput=true
1 parent 9f6c647 commit 2c5e768

File tree

7 files changed

+656
-48
lines changed

7 files changed

+656
-48
lines changed

daemon.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ import (
1212
"github.com/ipfs/boxo/bitswap/message/pb"
1313
"github.com/ipfs/boxo/bitswap/network"
1414
"github.com/ipfs/boxo/bitswap/network/httpnet"
15+
"github.com/ipfs/boxo/gateway"
16+
"github.com/ipfs/boxo/namesys"
1517
"github.com/ipfs/boxo/routing/http/client"
1618
"github.com/ipfs/boxo/routing/http/contentrouter"
1719
"github.com/ipfs/go-cid"
1820
vole "github.com/ipshipyard/vole/lib"
21+
doh "github.com/libp2p/go-doh-resolver"
1922
"github.com/libp2p/go-libp2p"
2023
dhtpb "github.com/libp2p/go-libp2p-kad-dht/pb"
2124
"github.com/libp2p/go-libp2p/core/host"
@@ -37,6 +40,7 @@ type daemon struct {
3740
h host.Host
3841
dht kademlia
3942
dhtMessenger *dhtpb.ProtocolMessenger
43+
ns namesys.NameSystem
4044
createTestHost func() (host.Host, error)
4145
promRegistry *prometheus.Registry
4246
httpSkipVerify bool
@@ -90,10 +94,34 @@ func newDaemon(ctx context.Context, acceleratedDHT bool) (*daemon, error) {
9094
return nil, err
9195
}
9296

97+
// Create DNS resolver with delegated-ipfs.dev DoH endpoint to match IPFS Mainnet behavior.
98+
// This endpoint is used by the Helia ecosystem in browsers and ensures consistent
99+
// DNSLink resolution without requiring local DNS resolver configuration.
100+
// DNS caching is disabled (doh.WithCacheDisabled) because this is a diagnostic tool
101+
// that should always query current DNS state rather than serve potentially stale cached results.
102+
dnsResolver, err := gateway.NewDNSResolver(
103+
map[string]string{
104+
".": "https://delegated-ipfs.dev/dns-query",
105+
},
106+
doh.WithCacheDisabled(),
107+
)
108+
if err != nil {
109+
return nil, fmt.Errorf("failed to create DNS resolver: %w", err)
110+
}
111+
112+
// Create namesys without caching (no WithCache option) to ensure fresh IPNS resolution.
113+
// Diagnostic tools should not cache IPNS records as users expect to see current network state
114+
// when running checks, not cached data from previous resolutions.
115+
ns, err := namesys.NewNameSystem(d, namesys.WithDNSResolver(dnsResolver))
116+
if err != nil {
117+
return nil, err
118+
}
119+
93120
return &daemon{
94121
h: h,
95122
dht: d,
96123
dhtMessenger: pm,
124+
ns: ns,
97125
promRegistry: promRegistry,
98126
createTestHost: func() (host.Host, error) {
99127
// TODO: when behind NAT, this will fail to determine its own public addresses which will block it from running dctur and hole punching
@@ -106,6 +134,14 @@ func newDaemon(ctx context.Context, acceleratedDHT bool) (*daemon, error) {
106134
}}, nil
107135
}
108136

137+
type MutableResolution struct {
138+
InputPath string `json:"InputPath,omitempty"`
139+
ResolvedPath string `json:"ResolvedPath,omitempty"`
140+
DiagnosticURL string `json:"DiagnosticURL,omitempty"`
141+
Error string `json:"Error,omitempty"`
142+
IsMutableInput bool `json:"IsMutableInput,omitempty"`
143+
}
144+
109145
type cidCheckOutput *[]providerOutput
110146

111147
type providerOutput struct {

go.mod

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/ipfs/go-datastore v0.9.0
1111
github.com/ipfs/go-ipld-format v0.6.3
1212
github.com/ipshipyard/vole v0.0.0-20251030190237-1448fb4935ac
13+
github.com/libp2p/go-doh-resolver v0.5.0
1314
github.com/libp2p/go-libp2p v0.43.0
1415
github.com/libp2p/go-libp2p-kad-dht v0.35.1
1516
github.com/libp2p/go-libp2p-record v0.3.1
@@ -26,21 +27,26 @@ require (
2627
github.com/TylerBrock/colorjson v0.0.0-20200706003622-8a50f05110d2 // indirect
2728
github.com/VividCortex/ewma v1.2.0 // indirect
2829
github.com/ajg/form v1.5.1 // indirect
30+
github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b // indirect
2931
github.com/andybalholm/brotli v1.1.0 // indirect
3032
github.com/benbjohnson/clock v1.3.5 // indirect
3133
github.com/beorn7/perks v1.0.1 // indirect
3234
github.com/cespare/xxhash/v2 v2.3.0 // indirect
3335
github.com/cheggaaa/pb/v3 v3.1.7 // indirect
3436
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
37+
github.com/crackcomm/go-gitignore v0.0.0-20241020182519-7843d2ba8fdf // indirect
3538
github.com/cskr/pubsub v1.0.2 // indirect
3639
github.com/davecgh/go-spew v1.1.1 // indirect
3740
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
3841
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
42+
github.com/dustin/go-humanize v1.0.1 // indirect
3943
github.com/fatih/color v1.18.0 // indirect
4044
github.com/fatih/structs v1.1.0 // indirect
45+
github.com/felixge/httpsnoop v1.0.4 // indirect
4146
github.com/filecoin-project/go-clock v0.1.0 // indirect
4247
github.com/flynn/noise v1.1.0 // indirect
4348
github.com/francoispqt/gojay v1.2.13 // indirect
49+
github.com/gabriel-vasile/mimetype v1.4.10 // indirect
4450
github.com/gammazero/chanqueue v1.1.1 // indirect
4551
github.com/gammazero/deque v1.1.0 // indirect
4652
github.com/go-logr/logr v1.4.3 // indirect
@@ -56,13 +62,18 @@ require (
5662
github.com/huin/goupnp v1.3.0 // indirect
5763
github.com/imkira/go-interpol v1.1.0 // indirect
5864
github.com/ipfs/bbloom v0.0.4 // indirect
65+
github.com/ipfs/go-bitfield v1.1.0 // indirect
5966
github.com/ipfs/go-cidutil v0.1.0 // indirect
6067
github.com/ipfs/go-dsqueue v0.1.0 // indirect
6168
github.com/ipfs/go-ipfs-pq v0.0.3 // indirect
69+
github.com/ipfs/go-ipfs-redirects-file v0.1.2 // indirect
70+
github.com/ipfs/go-ipld-cbor v0.2.1 // indirect
6271
github.com/ipfs/go-ipld-legacy v0.2.2 // indirect
6372
github.com/ipfs/go-log/v2 v2.8.2 // indirect
6473
github.com/ipfs/go-metrics-interface v0.3.0 // indirect
6574
github.com/ipfs/go-peertaskqueue v0.8.2 // indirect
75+
github.com/ipfs/go-unixfsnode v1.10.2 // indirect
76+
github.com/ipld/go-car/v2 v2.16.0 // indirect
6677
github.com/ipld/go-codec-dagpb v1.7.0 // indirect
6778
github.com/ipld/go-ipld-prime v0.21.0 // indirect
6879
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
@@ -102,6 +113,7 @@ require (
102113
github.com/nxadm/tail v1.4.11 // indirect
103114
github.com/onsi/gomega v1.36.3 // indirect
104115
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
116+
github.com/petar/GoLLRB v0.0.0-20210522233825-ae3b015fd3e9 // indirect
105117
github.com/pion/datachannel v1.5.10 // indirect
106118
github.com/pion/dtls/v2 v2.2.12 // indirect
107119
github.com/pion/dtls/v3 v3.0.6 // indirect
@@ -135,8 +147,12 @@ require (
135147
github.com/sergi/go-diff v1.3.1 // indirect
136148
github.com/smartystreets/assertions v1.13.0 // indirect
137149
github.com/spaolacci/murmur3 v1.1.0 // indirect
150+
github.com/ucarion/urlpath v0.0.0-20200424170820-7ccc79b76bbb // indirect
138151
github.com/valyala/bytebufferpool v1.0.0 // indirect
139152
github.com/valyala/fasthttp v1.55.0 // indirect
153+
github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc // indirect
154+
github.com/whyrusleeping/cbor v0.0.0-20171005072247-63513f603b11 // indirect
155+
github.com/whyrusleeping/cbor-gen v0.3.1 // indirect
140156
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
141157
github.com/wlynxg/anet v0.0.5 // indirect
142158
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
@@ -148,6 +164,7 @@ require (
148164
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
149165
go.opencensus.io v0.24.0 // indirect
150166
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
167+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0 // indirect
151168
go.opentelemetry.io/otel v1.38.0 // indirect
152169
go.opentelemetry.io/otel/metric v1.38.0 // indirect
153170
go.opentelemetry.io/otel/trace v1.38.0 // indirect
@@ -167,6 +184,7 @@ require (
167184
golang.org/x/text v0.30.0 // indirect
168185
golang.org/x/time v0.12.0 // indirect
169186
golang.org/x/tools v0.38.0 // indirect
187+
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
170188
gonum.org/v1/gonum v0.16.0 // indirect
171189
google.golang.org/protobuf v1.36.10 // indirect
172190
gopkg.in/yaml.v3 v3.0.1 // indirect

0 commit comments

Comments
 (0)