From c6192cebf462bffcfed88012a7f18836f0499857 Mon Sep 17 00:00:00 2001 From: Kishan Mohanbhai Sagathiya Date: Sun, 11 Aug 2019 19:06:45 +0530 Subject: [PATCH 1/3] Use `p2p` protocol name over `ipfs` for multiaddr --- api/rest/client/client_test.go | 2 +- api/util.go | 2 +- cmd/ipfs-cluster-ctl/main.go | 2 +- pstoremgr/pstoremgr_test.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/rest/client/client_test.go b/api/rest/client/client_test.go index 6d0ee13a..e39aed42 100644 --- a/api/rest/client/client_test.go +++ b/api/rest/client/client_test.go @@ -62,7 +62,7 @@ func apiMAddr(a *rest.API) ma.Multiaddr { } func peerMAddr(a *rest.API) ma.Multiaddr { - ipfsAddr, _ := ma.NewMultiaddr(fmt.Sprintf("/ipfs/%s", peer.IDB58Encode(a.Host().ID()))) + ipfsAddr, _ := ma.NewMultiaddr(fmt.Sprintf("/p2p/%s", peer.IDB58Encode(a.Host().ID()))) for _, a := range a.Host().Addrs() { if _, err := a.ValueForProtocol(ma.P_IP4); err == nil { return a.Encapsulate(ipfsAddr) diff --git a/api/util.go b/api/util.go index 9f8a38ae..a044d0f2 100644 --- a/api/util.go +++ b/api/util.go @@ -35,7 +35,7 @@ func StringsToPeers(strs []string) []peer.ID { // peer ID is bad. func MustLibp2pMultiaddrJoin(addr Multiaddr, p peer.ID) Multiaddr { v := addr.Value() - pidAddr, err := ma.NewMultiaddr("/ipfs/" + peer.IDB58Encode(p)) + pidAddr, err := ma.NewMultiaddr("/p2p/" + peer.IDB58Encode(p)) // let this break badly if err != nil { panic("called MustLibp2pMultiaddrJoin with bad peer!") diff --git a/cmd/ipfs-cluster-ctl/main.go b/cmd/ipfs-cluster-ctl/main.go index f49df483..dd400e51 100644 --- a/cmd/ipfs-cluster-ctl/main.go +++ b/cmd/ipfs-cluster-ctl/main.go @@ -58,7 +58,7 @@ responses in a user-readable format. The location of the IPFS Cluster server is assumed to be %s, but can be configured with the --host option. To use the secure libp2p-http API endpoint, use "--host" with the full cluster libp2p listener -address (including the "/ipfs/" part), and --secret (the +address (including the "/p2p/" part), and --secret (the 32-byte cluster secret as it appears in the cluster configuration). For feedback, bug reports or any additional information, visit diff --git a/pstoremgr/pstoremgr_test.go b/pstoremgr/pstoremgr_test.go index 64711745..a6517e87 100644 --- a/pstoremgr/pstoremgr_test.go +++ b/pstoremgr/pstoremgr_test.go @@ -28,7 +28,7 @@ func clean(pm *Manager) { } func testAddr(loc string, pid peer.ID) ma.Multiaddr { - m, _ := ma.NewMultiaddr(loc + "/ipfs/" + peer.IDB58Encode(pid)) + m, _ := ma.NewMultiaddr(loc + "/p2p/" + peer.IDB58Encode(pid)) return m } From 6656b80a006f238b435b5c9022fe3c5f693f4e99 Mon Sep 17 00:00:00 2001 From: Kishan Mohanbhai Sagathiya Date: Thu, 15 Aug 2019 16:49:26 +0530 Subject: [PATCH 2/3] Some more occurences of /ipfs and use SwapToP2pMultiaddrs (very helpful since ipfs still send addresses with `/ipfs` tag) --- api/rest/client/client.go | 2 +- api/rest/client/client_test.go | 2 +- api/rest/restapi.go | 2 +- api/types_test.go | 2 +- api/util.go | 2 +- cluster.go | 2 +- cmd/ipfs-cluster-ctl/main.go | 2 ++ cmd/ipfs-cluster-service/daemon.go | 2 ++ cmd/ipfs-cluster-service/main.go | 2 +- consensus/raft/consensus.go | 2 +- peer_manager_test.go | 2 +- pstoremgr/pstoremgr.go | 2 +- sharness/t0021-service-init.sh | 4 ++-- test/rpc_api_mock.go | 2 +- 14 files changed, 17 insertions(+), 13 deletions(-) diff --git a/api/rest/client/client.go b/api/rest/client/client.go index dff262c9..d9585bda 100644 --- a/api/rest/client/client.go +++ b/api/rest/client/client.go @@ -349,7 +349,7 @@ func IsPeerAddress(addr ma.Multiaddr) bool { if addr == nil { return false } - pid, err := addr.ValueForProtocol(ma.P_IPFS) + pid, err := addr.ValueForProtocol(ma.P_P2P) dnsaddr, err2 := addr.ValueForProtocol(madns.DnsaddrProtocol.Code) return (pid != "" && err == nil) || (dnsaddr != "" && err2 == nil) } diff --git a/api/rest/client/client_test.go b/api/rest/client/client_test.go index e39aed42..015f3f7a 100644 --- a/api/rest/client/client_test.go +++ b/api/rest/client/client_test.go @@ -228,7 +228,7 @@ func TestDNSMultiaddress(t *testing.T) { } func TestPeerAddress(t *testing.T) { - peerAddr, _ := ma.NewMultiaddr("/dns4/localhost/tcp/1234/ipfs/QmP7R7gWEnruNePxmCa9GBa4VmUNexLVnb1v47R8Gyo3LP") + peerAddr, _ := ma.NewMultiaddr("/dns4/localhost/tcp/1234/p2p/QmP7R7gWEnruNePxmCa9GBa4VmUNexLVnb1v47R8Gyo3LP") cfg := &Config{ APIAddr: peerAddr, Host: "localhost", diff --git a/api/rest/restapi.go b/api/rest/restapi.go index 780ebe01..bcf87b2f 100644 --- a/api/rest/restapi.go +++ b/api/rest/restapi.go @@ -481,7 +481,7 @@ func (api *API) runLibp2pServer(ctx context.Context) { listenMsg := "" for _, a := range api.host.Addrs() { - listenMsg += fmt.Sprintf(" %s/ipfs/%s\n", a, api.host.ID().Pretty()) + listenMsg += fmt.Sprintf(" %s/p2p/%s\n", a, api.host.ID().Pretty()) } logger.Infof("REST API (libp2p-http): ENABLED. Listening on:\n%s\n", listenMsg) diff --git a/api/types_test.go b/api/types_test.go index a6fbcad3..184fe386 100644 --- a/api/types_test.go +++ b/api/types_test.go @@ -18,7 +18,7 @@ import ( var testTime = time.Date(2017, 12, 31, 15, 45, 50, 0, time.UTC) var testMAddr, _ = ma.NewMultiaddr("/ip4/1.2.3.4") var testMAddr2, _ = ma.NewMultiaddr("/dns4/a.b.c.d") -var testMAddr3, _ = ma.NewMultiaddr("/ip4/127.0.0.1/tcp/8081/ws/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd") +var testMAddr3, _ = ma.NewMultiaddr("/ip4/127.0.0.1/tcp/8081/ws/p2p/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd") var testCid1, _ = cid.Decode("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmq") var testCid2, _ = cid.Decode("QmYCLpFCj9Av8NFjkQogvtXspnTDFWaizLpVFEijHTH4eV") var testCid3, _ = cid.Decode("QmZmdA3UZKuHuy9FrWsxJ82q21nbEh97NUnxTzF5EHxZia") diff --git a/api/util.go b/api/util.go index a044d0f2..1ad23c2f 100644 --- a/api/util.go +++ b/api/util.go @@ -31,7 +31,7 @@ func StringsToPeers(strs []string) []peer.ID { } // MustLibp2pMultiaddrJoin takes a LibP2P multiaddress and a peer ID and -// encapsulates a new /ipfs/ address. It will panic if the given +// encapsulates a new /p2p/ address. It will panic if the given // peer ID is bad. func MustLibp2pMultiaddrJoin(addr Multiaddr, p peer.ID) Multiaddr { v := addr.Value() diff --git a/cluster.go b/cluster.go index 2e6f875b..818ab732 100644 --- a/cluster.go +++ b/cluster.go @@ -120,7 +120,7 @@ func NewCluster( listenAddrs := "" for _, addr := range host.Addrs() { - listenAddrs += fmt.Sprintf(" %s/ipfs/%s\n", addr, host.ID().Pretty()) + listenAddrs += fmt.Sprintf(" %s/p2p/%s\n", addr, host.ID().Pretty()) } logger.Infof("IPFS Cluster v%s listening on:\n%s\n", version.Version, listenAddrs) diff --git a/cmd/ipfs-cluster-ctl/main.go b/cmd/ipfs-cluster-ctl/main.go index dd400e51..a07c93e3 100644 --- a/cmd/ipfs-cluster-ctl/main.go +++ b/cmd/ipfs-cluster-ctl/main.go @@ -88,6 +88,8 @@ func checkErr(doing string, err error) { func main() { ctx := context.Background() + ma.SwapToP2pMultiaddrs() + app := cli.NewApp() app.Name = programName app.Usage = "CLI for IPFS Cluster" diff --git a/cmd/ipfs-cluster-service/daemon.go b/cmd/ipfs-cluster-service/daemon.go index 4e9e9d24..71841d93 100644 --- a/cmd/ipfs-cluster-service/daemon.go +++ b/cmd/ipfs-cluster-service/daemon.go @@ -52,6 +52,8 @@ func daemon(c *cli.Context) error { logger.Info("Initializing. For verbose output run with \"-l debug\". Please wait...") + ma.SwapToP2pMultiaddrs() + ctx, cancel := context.WithCancel(context.Background()) bootstraps := parseBootstraps(c.StringSlice("bootstrap")) diff --git a/cmd/ipfs-cluster-service/main.go b/cmd/ipfs-cluster-service/main.go index f4fd03eb..34b78f58 100644 --- a/cmd/ipfs-cluster-service/main.go +++ b/cmd/ipfs-cluster-service/main.go @@ -95,7 +95,7 @@ $ ipfs-cluster-service daemon Launch a peer and join existing cluster: -$ ipfs-cluster-service daemon --bootstrap /ip4/192.168.1.2/tcp/9096/ipfs/QmPSoSaPXpyunaBwHs1rZBKYSqRV4bLRk32VGYLuvdrypL +$ ipfs-cluster-service daemon --bootstrap /ip4/192.168.1.2/tcp/9096/p2p/QmPSoSaPXpyunaBwHs1rZBKYSqRV4bLRk32VGYLuvdrypL `, programName, programName, diff --git a/consensus/raft/consensus.go b/consensus/raft/consensus.go index 22258682..0ba0d97b 100644 --- a/consensus/raft/consensus.go +++ b/consensus/raft/consensus.go @@ -542,7 +542,7 @@ func (cc *Consensus) Peers(ctx context.Context) ([]peer.ID, error) { } func parsePIDFromMultiaddr(addr ma.Multiaddr) string { - pidstr, err := addr.ValueForProtocol(ma.P_IPFS) + pidstr, err := addr.ValueForProtocol(ma.P_P2P) if err != nil { panic("peer badly encoded") } diff --git a/peer_manager_test.go b/peer_manager_test.go index 23fa6dc1..711df476 100644 --- a/peer_manager_test.go +++ b/peer_manager_test.go @@ -73,7 +73,7 @@ func clusterAddr(c *Cluster) ma.Multiaddr { for _, a := range c.host.Addrs() { if _, err := a.ValueForProtocol(ma.P_IP4); err == nil { p := peer.IDB58Encode(c.id) - cAddr, _ := ma.NewMultiaddr(fmt.Sprintf("%s/ipfs/%s", a, p)) + cAddr, _ := ma.NewMultiaddr(fmt.Sprintf("%s/p2p/%s", a, p)) return cAddr } } diff --git a/pstoremgr/pstoremgr.go b/pstoremgr/pstoremgr.go index ee6dfd82..5a90b247 100644 --- a/pstoremgr/pstoremgr.go +++ b/pstoremgr/pstoremgr.go @@ -57,7 +57,7 @@ func New(ctx context.Context, h host.Host, peerstorePath string) *Manager { } // ImportPeer adds a new peer address to the host's peerstore, optionally -// dialing to it. The address is expected to include the /ipfs/ +// dialing to it. The address is expected to include the /p2p/ // protocol part or to be a /dnsaddr/multiaddress // Peers are added with the given ttl. func (pm *Manager) ImportPeer(addr ma.Multiaddr, connect bool, ttl time.Duration) (peer.ID, error) { diff --git a/sharness/t0021-service-init.sh b/sharness/t0021-service-init.sh index 3421e40c..468aab68 100755 --- a/sharness/t0021-service-init.sh +++ b/sharness/t0021-service-init.sh @@ -5,8 +5,8 @@ test_description="Test init functionality" . lib/test-lib.sh test_expect_success "cluster-service init with --peers succeeds and fills peerstore" ' - PEER1=/ip4/192.168.0.129/tcp/9196/ipfs/12D3KooWRN8KRjpyg9rsW2w7StbBRGper65psTZm68cjud9KAkaW - PEER2=/ip4/192.168.0.129/tcp/9196/ipfs/12D3KooWPwrYNj7VficHw5qYidepMGA85756kYgMdNmRM9A1ZHjN + PEER1=/ip4/192.168.0.129/tcp/9196/p2p/12D3KooWRN8KRjpyg9rsW2w7StbBRGper65psTZm68cjud9KAkaW + PEER2=/ip4/192.168.0.129/tcp/9196/p2p/12D3KooWPwrYNj7VficHw5qYidepMGA85756kYgMdNmRM9A1ZHjN ipfs-cluster-service --config "test-config" init --peers $PEER1,$PEER2 && grep -q $PEER1 test-config/peerstore && grep -q $PEER2 test-config/peerstore diff --git a/test/rpc_api_mock.go b/test/rpc_api_mock.go index 65674dc6..85140f0c 100644 --- a/test/rpc_api_mock.go +++ b/test/rpc_api_mock.go @@ -154,7 +154,7 @@ func (mock *mockCluster) ID(ctx context.Context, in struct{}, out *api.ID) error // DefaultConfigCrypto, // DefaultConfigKeyLength) - addr, _ := api.NewMultiaddr("/ip4/127.0.0.1/tcp/4001/ipfs/" + PeerID1.Pretty()) + addr, _ := api.NewMultiaddr("/ip4/127.0.0.1/tcp/4001/p2p/" + PeerID1.Pretty()) *out = api.ID{ ID: PeerID1, //PublicKey: pubkey, From aab5f9bd0b485fc525cc18699c044745f82479bc Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Fri, 23 Aug 2019 22:45:32 +0200 Subject: [PATCH 3/3] Enable p2p addresses in a single place --- api/types.go | 3 +++ cmd/ipfs-cluster-ctl/main.go | 2 -- cmd/ipfs-cluster-service/daemon.go | 2 -- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/api/types.go b/api/types.go index 65a19118..5b42e91d 100644 --- a/api/types.go +++ b/api/types.go @@ -36,6 +36,9 @@ import ( var logger = logging.Logger("apitypes") func init() { + // Use /p2p/ multiaddresses + multiaddr.SwapToP2pMultiaddrs() + // intialize trackerStatusString stringTrackerStatus = make(map[string]TrackerStatus) for k, v := range trackerStatusString { diff --git a/cmd/ipfs-cluster-ctl/main.go b/cmd/ipfs-cluster-ctl/main.go index a07c93e3..dd400e51 100644 --- a/cmd/ipfs-cluster-ctl/main.go +++ b/cmd/ipfs-cluster-ctl/main.go @@ -88,8 +88,6 @@ func checkErr(doing string, err error) { func main() { ctx := context.Background() - ma.SwapToP2pMultiaddrs() - app := cli.NewApp() app.Name = programName app.Usage = "CLI for IPFS Cluster" diff --git a/cmd/ipfs-cluster-service/daemon.go b/cmd/ipfs-cluster-service/daemon.go index 71841d93..4e9e9d24 100644 --- a/cmd/ipfs-cluster-service/daemon.go +++ b/cmd/ipfs-cluster-service/daemon.go @@ -52,8 +52,6 @@ func daemon(c *cli.Context) error { logger.Info("Initializing. For verbose output run with \"-l debug\". Please wait...") - ma.SwapToP2pMultiaddrs() - ctx, cancel := context.WithCancel(context.Background()) bootstraps := parseBootstraps(c.StringSlice("bootstrap"))