From 92da467784af94bb47fceb8228985338dcbb5d99 Mon Sep 17 00:00:00 2001 From: Icarus9913 Date: Tue, 12 Sep 2023 12:46:05 +0800 Subject: [PATCH] stop using go-libp2p deprecated peer.ID.Pretty Signed-off-by: Icarus9913 --- .gitignore | 3 +++ config/init.go | 2 +- core/commands/name/ipns.go | 2 +- core/commands/pubsub.go | 2 +- core/commands/swarm.go | 8 ++++---- core/coreapi/test/api_test.go | 2 +- core/node/builder.go | 2 +- core/node/libp2p/rcmgr.go | 2 +- fuse/ipns/ipns_test.go | 4 ++-- fuse/ipns/ipns_unix.go | 2 +- p2p/local.go | 2 +- 11 files changed, 17 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index cb147456b11e..62825088dfe8 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,6 @@ docs/examples/go-ipfs-as-a-library/example-folder/Qm* /parts /stage /prime + +# IdeaIDE +.idea diff --git a/config/init.go b/config/init.go index 1ccfc72514b7..f40d373bb1e1 100644 --- a/config/init.go +++ b/config/init.go @@ -237,7 +237,7 @@ func CreateIdentity(out io.Writer, opts []options.KeyGenerateOption) (Identity, if err != nil { return ident, err } - ident.PeerID = id.Pretty() + ident.PeerID = id.String() fmt.Fprintf(out, "peer identity: %s\n", ident.PeerID) return ident, nil } diff --git a/core/commands/name/ipns.go b/core/commands/name/ipns.go index 8c2b755d585a..b5c7fd7e388c 100644 --- a/core/commands/name/ipns.go +++ b/core/commands/name/ipns.go @@ -93,7 +93,7 @@ Resolve the value of a dnslink: if err != nil { return err } - name = self.ID().Pretty() + name = self.ID().String() } else { name = req.Arguments[0] } diff --git a/core/commands/pubsub.go b/core/commands/pubsub.go index aadc681d9ab5..d8fccbbd31ba 100644 --- a/core/commands/pubsub.go +++ b/core/commands/pubsub.go @@ -110,7 +110,7 @@ TOPIC AND DATA ENCODING encoder, _ := mbase.EncoderByName("base64url") psm := pubsubMessage{ Data: encoder.Encode(msg.Data()), - From: msg.From().Pretty(), + From: msg.From().String(), Seqno: encoder.Encode(msg.Seq()), } for _, topic := range msg.Topics() { diff --git a/core/commands/swarm.go b/core/commands/swarm.go index fc4d8f7d29d4..f51bc79c7527 100644 --- a/core/commands/swarm.go +++ b/core/commands/swarm.go @@ -262,7 +262,7 @@ var swarmPeersCmd = &cmds.Command{ for _, c := range conns { ci := connInfo{ Addr: c.Address().String(), - Peer: c.ID().Pretty(), + Peer: c.ID().String(), } if verbose || direction { @@ -536,7 +536,7 @@ var swarmAddrsCmd = &cmds.Command{ out := make(map[string][]string) for p, paddrs := range addrs { - s := p.Pretty() + s := p.String() for _, a := range paddrs { out[s] = append(out[s], a.String()) } @@ -680,7 +680,7 @@ ipfs swarm connect /ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N output := make([]string, len(pis)) for i, pi := range pis { - output[i] = "connect " + pi.ID.Pretty() + output[i] = "connect " + pi.ID.String() err := api.Swarm().Connect(req.Context, pi) if err != nil { @@ -745,7 +745,7 @@ it will reconnect. // a good backwards compat solution. Right now, I'm just // preserving the current behavior. for _, addr := range maddrs { - msg := "disconnect " + ainfo.ID.Pretty() + msg := "disconnect " + ainfo.ID.String() if err := api.Swarm().Disconnect(req.Context, addr); err != nil { msg += " failure: " + err.Error() } else { diff --git a/core/coreapi/test/api_test.go b/core/coreapi/test/api_test.go index fa09a96d8fbb..3ae74b97e9a9 100644 --- a/core/coreapi/test/api_test.go +++ b/core/coreapi/test/api_test.go @@ -56,7 +56,7 @@ func (NodeProvider) MakeAPISwarm(t *testing.T, ctx context.Context, fullIdentity } ident = config.Identity{ - PeerID: id.Pretty(), + PeerID: id.String(), PrivKey: base64.StdEncoding.EncodeToString(kbytes), } } else { diff --git a/core/node/builder.go b/core/node/builder.go index 9c4951801ba4..57fa209457a7 100644 --- a/core/node/builder.go +++ b/core/node/builder.go @@ -141,7 +141,7 @@ func defaultRepo(dstore repo.Datastore) (repo.Repo, error) { c.Bootstrap = cfg.DefaultBootstrapAddresses c.Addresses.Swarm = []string{"/ip4/0.0.0.0/tcp/4001", "/ip4/0.0.0.0/udp/4001/quic-v1"} - c.Identity.PeerID = pid.Pretty() + c.Identity.PeerID = pid.String() c.Identity.PrivKey = base64.StdEncoding.EncodeToString(privkeyb) return &repo.Mock{ diff --git a/core/node/libp2p/rcmgr.go b/core/node/libp2p/rcmgr.go index 47a823d5d09e..f545126c47cf 100644 --- a/core/node/libp2p/rcmgr.go +++ b/core/node/libp2p/rcmgr.go @@ -360,7 +360,7 @@ func LimitConfigsToInfo(stats LimitsConfigAndUsage) ResourceInfos { for i, p := range stats.Peers { result = append(result, resourceLimitsAndUsageToResourceInfo( - config.ResourceMgrPeerScopePrefix+i.Pretty(), + config.ResourceMgrPeerScopePrefix+i.String(), p, )...) } diff --git a/fuse/ipns/ipns_test.go b/fuse/ipns/ipns_test.go index ca2ec4c1abca..d26e78c4de4b 100644 --- a/fuse/ipns/ipns_test.go +++ b/fuse/ipns/ipns_test.go @@ -151,7 +151,7 @@ func TestIpnsLocalLink(t *testing.T) { t.Fatal(err) } - if linksto != nd.Identity.Pretty() { + if linksto != nd.Identity.String() { t.Fatal("Link invalid") } } @@ -176,7 +176,7 @@ func TestIpnsBasicIO(t *testing.T) { t.Fatal("Incorrect Read!") } - fname2 := mnt.Dir + "/" + nd.Identity.Pretty() + "/testfile" + fname2 := mnt.Dir + "/" + nd.Identity.String() + "/testfile" rbuf, err = os.ReadFile(fname2) if err != nil { t.Fatal(err) diff --git a/fuse/ipns/ipns_unix.go b/fuse/ipns/ipns_unix.go index b666340158b6..2cb25d33297b 100644 --- a/fuse/ipns/ipns_unix.go +++ b/fuse/ipns/ipns_unix.go @@ -220,7 +220,7 @@ func (r *Root) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) { listing := make([]fuse.Dirent, 0, len(r.Keys)*2) for alias, k := range r.Keys { ent := fuse.Dirent{ - Name: k.ID().Pretty(), + Name: k.ID().String(), Type: fuse.DT_Dir, } link := fuse.Dirent{ diff --git a/p2p/local.go b/p2p/local.go index 6ef110c39316..b02e50b906ed 100644 --- a/p2p/local.go +++ b/p2p/local.go @@ -76,7 +76,7 @@ func (l *localListener) setupStream(local manet.Conn) { remote, err := l.dial(l.ctx) if err != nil { local.Close() - log.Warnf("failed to dial to remote %s/%s", l.peer.Pretty(), l.proto) + log.Warnf("failed to dial to remote %s/%s", l.peer.String(), l.proto) return }