Skip to content

Commit 8ae7849

Browse files
committed
fix: don't break /dns/ipfs-mydomain.com addresses in 7 to 8 migration
1 parent 6d6b79c commit 8ae7849

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

ipfs-7-to-8/migration/config_conv.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,12 @@ func ver7to8(bootstrap []string) []string {
123123
for _, addr := range bootstrap {
124124
if isDNSAddr, err := isDNSBootstrapPeer(addr); !isDNSAddr || err != nil {
125125
if isSmall, err := isSmallKeyPeer(addr); !isSmall || err != nil {
126-
// Replace /ipfs with /p2p
127-
addr = strings.Replace(addr, "/ipfs", "/p2p", -1)
126+
// Change the protocol string from "ipfs" to "p2p".
127+
// Make sure we don't break addresses like
128+
// /dns4/ipfs-bootstrap.com/...
129+
// by matching specifically /ipfs/Qm or /ipfs/1...
130+
addr = strings.Replace(addr, "/ipfs/Qm", "/p2p/Qm", -1)
131+
addr = strings.Replace(addr, "/ipfs/1", "/p2p/1", -1)
128132
res = append(res, addr)
129133
}
130134
}

ipfs-7-to-8/migration/config_conv_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ func TestForward(t *testing.T) {
6666
bootstrap := []string{
6767
// peer with old key (should be filtered out)
6868
"/ip4/178.62.158.247/tcp/4001/p2p/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd",
69-
// peer with unknown key (should be included)
70-
"/ip4/178.62.158.248/tcp/4001/p2p/QmSomeNewKeygSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd",
69+
// peer with unknown key (should be included, /ipfs/ replaced with /p2p/)
70+
"/ip4/178.62.158.248/tcp/4001/ipfs/QmSomeNewKeygSp2LA3dPaeykiS1J6DifTC88f5uV562wK",
7171
// unrecognized format (should be included)
7272
"/ip4/178.62.158.248/tcp/4001/wut/some-new-format",
73+
// peer with /dns/ipfs.my-domain.com (should be included, "ipfs" in domain should not be changed)
74+
"/dns4/ipfs-bootstrap.com/tcp/4001/ipfs/Qm1234567KeygSp2LA3dPaeykiS1J6DifTC88f5u123456",
7375
}
7476
exp := []string{
7577
// new dnsaddr peers
@@ -78,9 +80,11 @@ func TestForward(t *testing.T) {
7880
"/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb",
7981
"/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt",
8082
// peer with unknown key
81-
"/ip4/178.62.158.248/tcp/4001/p2p/QmSomeNewKeygSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd",
83+
"/ip4/178.62.158.248/tcp/4001/p2p/QmSomeNewKeygSp2LA3dPaeykiS1J6DifTC88f5uV562wK",
8284
// unrecognized format
8385
"/ip4/178.62.158.248/tcp/4001/wut/some-new-format",
86+
// peer with /dns/ipfs.my-domain.com
87+
"/dns4/ipfs-bootstrap.com/tcp/4001/p2p/Qm1234567KeygSp2LA3dPaeykiS1J6DifTC88f5u123456",
8488
}
8589
if res := ver7to8(bootstrap); !arrayMatch(exp, res) {
8690
fmt.Println(res)

0 commit comments

Comments
 (0)