Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failed to parse hardcoded bootstrap peers: no protocol with name dnsaddr This is a problem with the ipfs codebase. Please report it to the dev team. #5143

Closed
bonedaddy opened this issue Jun 21, 2018 · 7 comments · Fixed by #5144
Assignees

Comments

@bonedaddy
Copy link
Contributor

Version information:

go-ipfs version: 0.4.15-Repo version: 6
System version: amd64/linux
Golang version: go1.10.2

Type:

Bug

Description:

I'm attempting to generate a custom IPFS configuration file utilizing github.com/ipfs/go-ipfs/repo/config

While writing a test case, and in attempting to generate a default configuration file using config.Init I am given the following errors message

        rtfsp_test.go:47: failed to parse hardcoded bootstrap peers: no protocol with name dnsaddr
                This is a problem with the ipfs codebase. Please report it to the dev team.

Here's the code causing the issue:

test file:

package rtfsp_test

import (
	"fmt"
	"testing"

	"github.com/RTradeLtd/Temporal/rtfsp"
)

var ipfsConfigPath = "/ipfs/config"
var testIpfsMultiAddrString = "/ip4/192.168.1.242/tcp/4001/ipfs/QmXivHtDyAe8nS7cbQiS7ri9haUM2wGvbinjKws3a4EstT"
var expectedPeerID = "QmXivHtDyAe8nS7cbQiS7ri9haUM2wGvbinjKws3a4EstT"

func TestPrivateConfig(t *testing.T) {
	pcm, err := rtfsp.GenerateConfigManager(ipfsConfigPath)
	if err != nil {
		t.Fatal(err)
	}
	addr, err := pcm.GenerateIPFSMultiAddr(testIpfsMultiAddrString)
	if err != nil {
		t.Fatal(err)
	}
	peerID := addr.ID().Pretty()
	if peerID != expectedPeerID {
		t.Fatal("unexpected peer id returned")
	}

	_, err = pcm.GenerateBootstrapPeer(testIpfsMultiAddrString)
	if err != nil {
		t.Fatal(err)
	}
	bpCfg, err := pcm.ConfigureBootstrap(testIpfsMultiAddrString)
	if err != nil {
		t.Fatal(err)
	}
	fmt.Println(bpCfg)
	fmt.Println(pcm.Config.Bootstrap)
}

func TestConfigGeneration(t *testing.T) {
	pcm, err := rtfsp.GenerateConfigManager(rtfsp.ConfigFilePath)
	if err != nil {
		t.Fatal(err)
	}
	err = pcm.ParseConfigAndWrite()
	if err != nil {
		t.Fatal(err)
	}
}

Implementation File

package rtfsp

import (
	"encoding/json"
	"fmt"
	"os"

	addrUtil "github.com/ipfs/go-ipfs-addr"
	cg "github.com/ipfs/go-ipfs/repo/config"
)

type PrivateConfigManager struct {
	Config *cg.Config
}

const (
	// ConfigFilePath is where the ipfs config file is located
	ConfigFilePath = "/ipfs/config"
	// SwarmKeyPath is the location of our swarm key
	SwarmKeyPath = "/ipfs/swarm.key"
)

// GenerateConfigManager generates the config manager for our private
func GenerateConfigManager(configFilePath string) (*PrivateConfigManager, error) {
	var conf cg.Config
	file, err := os.Open(configFilePath)
	if err != nil {
		return nil, err
	}
	err = json.NewDecoder(file).Decode(&conf)
	pcm := PrivateConfigManager{Config: &conf}
	return &pcm, err
}

func (pcm *PrivateConfigManager) GenerateIPFSMultiAddr(address string) (addrUtil.IPFSAddr, error) {
	ipfsAddr, err := addrUtil.ParseString(address)
	if err != nil {
		return nil, err
	}
	return ipfsAddr, nil
}

func (pcm *PrivateConfigManager) GenerateBootstrapPeer(address string) (cg.BootstrapPeer, error) {
	bpeer, err := cg.ParseBootstrapPeer(address)
	if err != nil {
		return nil, err
	}
	return bpeer, nil
}

// ConfigureBootstrap is a variadic function used to generate a list of bootstrap peers
// it will validate all provided peers, and fail if it detects an error
func (pcm *PrivateConfigManager) ConfigureBootstrap(peers ...string) ([]cg.BootstrapPeer, error) {
	var bpeers []cg.BootstrapPeer
	for _, v := range peers {
		bpeer, err := pcm.GenerateBootstrapPeer(v)
		if err != nil {
			return nil, err
		}
		bpeers = append(bpeers, bpeer)
	}
	pcm.Config.SetBootstrapPeers(bpeers)
	return bpeers, nil
}

// ParseConfigAndWrite is used to parse a configuration object and write it
func (pcm *PrivateConfigManager) ParseConfigAndWrite() error {
	// Create file, truncating if it exists
	cFilePath, err := os.Create(ConfigFilePath)
	if err != nil {
		return err
	}
	cfg, err := cg.Init(cFilePath, 4192)
	if err != nil {
		return err
	}
	fmt.Println(cfg)
	return nil
}

I'm using the following versioned go-ipfs dependencies

[[projects]]
  branch = "master"
  name = "github.com/ipfs/go-ipfs"
  packages = [
    "blockservice",
    "merkledag",
    "merkledag/pb",
    "merkledag/utils",
    "namesys",
    "namesys/opts",
    "path",
    "pin",
    "pin/internal/pb",
    "thirdparty/verifcid",
    "unixfs",
    "unixfs/pb"
  ]
  revision = "2a9de81e64d563c5bd86b058aa251cbe94faf86f"
@lanzafame
Copy link
Contributor

@postables This will because the key_gen.sh script you have performs ipfs bootstrap rm --all, which removes all the standard bootstrap peers and you have replaced them, I am guessing in the /ipfs/config file you have something starting with /dnsaddr but the last part of that address isn't a valid IPFSAddr, i.e. /ipfs/Qm..., address. The error comes from here, which is called from here via iaddr.ParseString.

@bonedaddy
Copy link
Contributor Author

bonedaddy commented Jun 21, 2018

@lanzafame in this case I have not ran key_gen.sh at all, before running my test I started with a fresh IPFS configuration file. OK I'll take a look at those links and see if there's some kind of formatting error.

@bonedaddy
Copy link
Contributor Author

I believe the problem is with the default bootstrap peer list that is provided by the go-ipfs package.

I just tried on a brand new installation, with a fresh configuration and got the same error:

=== RUN   TestPrivateConfig
[/ip4/192.168.1.242/tcp/4001/ipfs/QmXivHtDyAe8nS7cbQiS7ri9haUM2wGvbinjKws3a4EstT]
[/ip4/192.168.1.242/tcp/4001/ipfs/QmXivHtDyAe8nS7cbQiS7ri9haUM2wGvbinjKws3a4EstT]
--- PASS: TestPrivateConfig (0.00s)
=== RUN   TestConfigGeneration
--- FAIL: TestConfigGeneration (4.19s)
	rtfsp_test.go:47: failed to parse hardcoded bootstrap peers: no protocol with name dnsaddr
		This is a problem with the ipfs codebase. Please report it to the dev team.
FAIL
FAIL	command-line-arguments	4.209s

Here are the commands I ran in sequence:

 2020  mkdir /ipfs
 2021  sudo mkdir /ipfs
 2022  whoami
 2023  sudo chown -R $(whoami):$(whoami) /ipfs
 2024  export IPFS_PATH=/ipfs
 2025  ipfs init
 2026  go test -v rtfsp_test.go 

@Stebalien
Copy link
Member

Try importing the github.com/multiformats/go-multiaddr-dns package. That should magically fix your problem.

Stebalien added a commit that referenced this issue Jun 21, 2018
We need it to parse the dnsaddr addresses. While we import it elsewhere, we
should really be importing it every where we need it so that other users can
import our packages directly.

fixes #5143

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
@ghost ghost assigned Stebalien Jun 21, 2018
@ghost ghost added the status/in-progress In progress label Jun 21, 2018
@Stebalien
Copy link
Member

@postables pleas try #5144.

@bonedaddy
Copy link
Contributor Author

Awesome thanks! I'll try this when I get home tonight. Just want to make sure I understand what the issue was, is it that the go-multiaddr-dns package is what's used to parse dnsaddr protocols, and because the go-ipfs package that was being used to parse protocol addresses when setting up configurations via github.com/ipfs/go-ipfs/repo/config didn't import go-multiaddr-dns and subsequently there was no logic to recognize dnsaddr as a valid protocol address?

@bonedaddy
Copy link
Contributor Author

@Stebalien @lanzafame the fix proposed in #5144 works and my tests now pass :) Thank you both and the IPFS team at large for the work you all have done and the diligence that is exhibited with the IPFS project, absolutely fantastic.

@ghost ghost removed the status/in-progress In progress label Jun 21, 2018
laurentsenta pushed a commit to laurentsenta/kubo that referenced this issue Feb 25, 2022
We need it to parse the dnsaddr addresses. While we import it elsewhere, we
should really be importing it every where we need it so that other users can
import our packages directly.

fixes ipfs#5143

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
laurentsenta pushed a commit to laurentsenta/kubo that referenced this issue Feb 25, 2022
…p_peers

We need it to parse the dnsaddr addresses. While we import it elsewhere, we
should really be importing it every where we need it so that other users can
import our packages directly.

fixes ipfs#5143

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
laurentsenta pushed a commit to laurentsenta/kubo that referenced this issue Mar 4, 2022
…p_peers

We need it to parse the dnsaddr addresses. While we import it elsewhere, we
should really be importing it every where we need it so that other users can
import our packages directly.

fixes ipfs#5143

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants