refactor: stop using go-libp2p deprecated peer.ID.Pretty
Signed-off-by: Icarus9913 <icaruswu66@qq.com>
Icarus9913 committed
Sep 18, 2023 at 21:58 UTC
9fdb0856052f35c93373822255dee8105f6255e9
18 files changed
+30
-30
client/rpc/dht.go
+1
-1
@@ -17,7 +17,7 @@ func (api *DhtAPI) FindPeer(ctx context.Context, p peer.ID) (peer.AddrInfo, erro
17
Type routing.QueryEventType
18
Responses []peer.AddrInfo
19
}
20
- resp, err := api.core().Request("dht/findpeer", p.Pretty()).Send(ctx)
20
+ resp, err := api.core().Request("dht/findpeer", p.String()).Send(ctx)
21
if err != nil {
22
return peer.AddrInfo{}, err
23
}
client/rpc/swarm.go
+1
-1
@@ -14,7 +14,7 @@ import (
14
type SwarmAPI HttpApi
15
16
func (api *SwarmAPI) Connect(ctx context.Context, pi peer.AddrInfo) error {
17
- pidma, err := multiaddr.NewComponent("p2p", pi.ID.Pretty())
17
+ pidma, err := multiaddr.NewComponent("p2p", pi.ID.String())
18
if err != nil {
19
return err
20
}
config/init.go
+1
-1
@@ -237,7 +237,7 @@ func CreateIdentity(out io.Writer, opts []options.KeyGenerateOption) (Identity,
237
if err != nil {
238
return ident, err
239
}
240
- ident.PeerID = id.Pretty()
240
+ ident.PeerID = id.String()
241
fmt.Fprintf(out, "peer identity: %s\n", ident.PeerID)
242
return ident, nil
243
}
core/commands/dht_test.go
+2
-2
@@ -14,12 +14,12 @@ func TestKeyTranslation(t *testing.T) {
14
pkname := namesys.PkKeyForID(pid)
15
ipnsname := ipns.NameFromPeer(pid).RoutingKey()
16
17
- pkk, err := escapeDhtKey("/pk/" + pid.Pretty())
17
+ pkk, err := escapeDhtKey("/pk/" + pid.String())
18
if err != nil {
19
t.Fatal(err)
20
}
21
22
- ipnsk, err := escapeDhtKey("/ipns/" + pid.Pretty())
22
+ ipnsk, err := escapeDhtKey("/ipns/" + pid.String())
23
if err != nil {
24
t.Fatal(err)
25
}
core/commands/name/ipns.go
+1
-1
@@ -93,7 +93,7 @@ Resolve the value of a dnslink:
93
if err != nil {
94
return err
95
}
96
- name = self.ID().Pretty()
96
+ name = self.ID().String()
97
} else {
98
name = req.Arguments[0]
99
}
core/commands/ping.go
+2
-2
@@ -79,7 +79,7 @@ trip latency information.
79
if len(n.Peerstore.Addrs(pid)) == 0 {
80
// Make sure we can find the node in question
81
if err := res.Emit(&PingResult{
82
- Text: fmt.Sprintf("Looking up peer %s", pid.Pretty()),
82
+ Text: fmt.Sprintf("Looking up peer %s", pid),
83
Success: true,
84
}); err != nil {
85
return err
@@ -95,7 +95,7 @@ trip latency information.
95
}
96
97
if err := res.Emit(&PingResult{
98
- Text: fmt.Sprintf("PING %s.", pid.Pretty()),
98
+ Text: fmt.Sprintf("PING %s.", pid),
99
Success: true,
100
}); err != nil {
101
return err
core/commands/pubsub.go
+2
-2
@@ -110,7 +110,7 @@ TOPIC AND DATA ENCODING
110
encoder, _ := mbase.EncoderByName("base64url")
111
psm := pubsubMessage{
112
Data: encoder.Encode(msg.Data()),
113
- From: msg.From().Pretty(),
113
+ From: msg.From().String(),
114
Seqno: encoder.Encode(msg.Seq()),
115
}
116
for _, topic := range msg.Topics() {
@@ -323,7 +323,7 @@ TOPIC AND DATA ENCODING
323
list := &stringList{make([]string, 0, len(peers))}
324
325
for _, peer := range peers {
326
- list.Strings = append(list.Strings, peer.Pretty())
326
+ list.Strings = append(list.Strings, peer.String())
327
}
328
sort.Strings(list.Strings)
329
return cmds.EmitOnce(res, list)
core/commands/routing.go
+2
-2
@@ -114,7 +114,7 @@ var findProvidersRoutingCmd = &cmds.Command{
114
if verbose {
115
fmt.Fprintf(out, "provider: ")
116
}
117
- fmt.Fprintf(out, "%s\n", prov.ID.Pretty())
117
+ fmt.Fprintf(out, "%s\n", prov.ID)
118
if verbose {
119
for _, a := range prov.Addrs {
120
fmt.Fprintf(out, "\t%s\n", a)
@@ -479,7 +479,7 @@ identified by QmFoo.
479
return nil
480
},
481
routing.Value: func(obj *routing.QueryEvent, out io.Writer, verbose bool) error {
482
- fmt.Fprintf(out, "%s\n", obj.ID.Pretty())
482
+ fmt.Fprintf(out, "%s\n", obj.ID)
483
return nil
484
},
485
}
core/commands/swarm.go
+5
-5
@@ -262,7 +262,7 @@ var swarmPeersCmd = &cmds.Command{
262
for _, c := range conns {
263
ci := connInfo{
264
Addr: c.Address().String(),
265
- Peer: c.ID().Pretty(),
265
+ Peer: c.ID().String(),
266
}
267
268
if verbose || direction {
@@ -536,7 +536,7 @@ var swarmAddrsCmd = &cmds.Command{
536
537
out := make(map[string][]string)
538
for p, paddrs := range addrs {
539
- s := p.Pretty()
539
+ s := p.String()
540
for _, a := range paddrs {
541
out[s] = append(out[s], a.String())
542
}
@@ -599,7 +599,7 @@ var swarmAddrsLocalCmd = &cmds.Command{
599
for _, addr := range maddrs {
600
saddr := addr.String()
601
if showid {
602
- saddr = path.Join(saddr, p2pProtocolName, self.ID().Pretty())
602
+ saddr = path.Join(saddr, p2pProtocolName, self.ID().String())
603
}
604
addrs = append(addrs, saddr)
605
}
@@ -680,7 +680,7 @@ ipfs swarm connect /ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N
680
681
output := make([]string, len(pis))
682
for i, pi := range pis {
683
- output[i] = "connect " + pi.ID.Pretty()
683
+ output[i] = "connect " + pi.ID.String()
684
685
err := api.Swarm().Connect(req.Context, pi)
686
if err != nil {
@@ -745,7 +745,7 @@ it will reconnect.
745
// a good backwards compat solution. Right now, I'm just
746
// preserving the current behavior.
747
for _, addr := range maddrs {
748
- msg := "disconnect " + ainfo.ID.Pretty()
748
+ msg := "disconnect " + ainfo.ID.String()
749
if err := api.Swarm().Disconnect(req.Context, addr); err != nil {
750
msg += " failure: " + err.Error()
751
} else {
core/coreapi/test/api_test.go
+1
-1
@@ -56,7 +56,7 @@ func (NodeProvider) MakeAPISwarm(t *testing.T, ctx context.Context, fullIdentity
56
}
57
58
ident = config.Identity{
59
- PeerID: id.Pretty(),
59
+ PeerID: id.String(),
60
PrivKey: base64.StdEncoding.EncodeToString(kbytes),
61
}
62
} else {
core/node/builder.go
+1
-1
@@ -141,7 +141,7 @@ func defaultRepo(dstore repo.Datastore) (repo.Repo, error) {
141
142
c.Bootstrap = cfg.DefaultBootstrapAddresses
143
c.Addresses.Swarm = []string{"/ip4/0.0.0.0/tcp/4001", "/ip4/0.0.0.0/udp/4001/quic-v1"}
144
- c.Identity.PeerID = pid.Pretty()
144
+ c.Identity.PeerID = pid.String()
145
c.Identity.PrivKey = base64.StdEncoding.EncodeToString(privkeyb)
146
147
return &repo.Mock{
core/node/libp2p/hostopt.go
+1
-1
@@ -17,7 +17,7 @@ var DefaultHostOption HostOption = constructPeerHost
17
func constructPeerHost(id peer.ID, ps peerstore.Peerstore, options ...libp2p.Option) (host.Host, error) {
18
pkey := ps.PrivKey(id)
19
if pkey == nil {
20
- return nil, fmt.Errorf("missing private key for node ID: %s", id.Pretty())
20
+ return nil, fmt.Errorf("missing private key for node ID: %s", id)
21
}
22
options = append([]libp2p.Option{libp2p.Identity(pkey), libp2p.Peerstore(ps)}, options...)
23
return libp2p.New(options...)
core/node/libp2p/rcmgr.go
+1
-1
@@ -360,7 +360,7 @@ func LimitConfigsToInfo(stats LimitsConfigAndUsage) ResourceInfos {
360
361
for i, p := range stats.Peers {
362
result = append(result, resourceLimitsAndUsageToResourceInfo(
363
- config.ResourceMgrPeerScopePrefix+i.Pretty(),
363
+ config.ResourceMgrPeerScopePrefix+i.String(),
364
p,
365
)...)
366
}
fuse/ipns/ipns_test.go
+2
-2
@@ -151,7 +151,7 @@ func TestIpnsLocalLink(t *testing.T) {
151
t.Fatal(err)
152
}
153
154
- if linksto != nd.Identity.Pretty() {
154
+ if linksto != nd.Identity.String() {
155
t.Fatal("Link invalid")
156
}
157
}
@@ -176,7 +176,7 @@ func TestIpnsBasicIO(t *testing.T) {
176
t.Fatal("Incorrect Read!")
177
}
178
179
- fname2 := mnt.Dir + "/" + nd.Identity.Pretty() + "/testfile"
179
+ fname2 := mnt.Dir + "/" + nd.Identity.String() + "/testfile"
180
rbuf, err = os.ReadFile(fname2)
181
if err != nil {
182
t.Fatal(err)
fuse/ipns/ipns_unix.go
+1
-1
@@ -220,7 +220,7 @@ func (r *Root) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
220
listing := make([]fuse.Dirent, 0, len(r.Keys)*2)
221
for alias, k := range r.Keys {
222
ent := fuse.Dirent{
223
- Name: k.ID().Pretty(),
223
+ Name: k.ID().String(),
224
Type: fuse.DT_Dir,
225
}
226
link := fuse.Dirent{
p2p/local.go
+2
-2
@@ -76,7 +76,7 @@ func (l *localListener) setupStream(local manet.Conn) {
76
remote, err := l.dial(l.ctx)
77
if err != nil {
78
local.Close()
79
- log.Warnf("failed to dial to remote %s/%s", l.peer.Pretty(), l.proto)
79
+ log.Warnf("failed to dial to remote %s/%s", l.peer, l.proto)
80
return
81
}
82
@@ -109,7 +109,7 @@ func (l *localListener) ListenAddress() ma.Multiaddr {
109
}
110
111
func (l *localListener) TargetAddress() ma.Multiaddr {
112
- addr, err := ma.NewMultiaddr(maPrefix + l.peer.Pretty())
112
+ addr, err := ma.NewMultiaddr(maPrefix + l.peer.String())
113
if err != nil {
114
panic(err)
115
}
p2p/remote.go
+3
-3
@@ -55,13 +55,13 @@ func (l *remoteListener) handleStream(remote net.Stream) {
55
peer := remote.Conn().RemotePeer()
56
57
if l.reportRemote {
58
- if _, err := fmt.Fprintf(local, "%s\n", peer.Pretty()); err != nil {
58
+ if _, err := fmt.Fprintf(local, "%s\n", peer); err != nil {
59
_ = remote.Reset()
60
return
61
}
62
}
63
64
- peerMa, err := ma.NewMultiaddr(maPrefix + peer.Pretty())
64
+ peerMa, err := ma.NewMultiaddr(maPrefix + peer.String())
65
if err != nil {
66
_ = remote.Reset()
67
return
@@ -88,7 +88,7 @@ func (l *remoteListener) Protocol() protocol.ID {
88
}
89
90
func (l *remoteListener) ListenAddress() ma.Multiaddr {
91
- addr, err := ma.NewMultiaddr(maPrefix + l.p2p.identity.Pretty())
91
+ addr, err := ma.NewMultiaddr(maPrefix + l.p2p.identity.String())
92
if err != nil {
93
panic(err)
94
}
plugin/plugins/peerlog/peerlog.go
+1
-1
@@ -148,7 +148,7 @@ func (pl *peerLogPlugin) collectEvents(node *core.IpfsNode) {
148
case e = <-pl.events:
149
}
150
151
- peerID := zap.String("peer", e.peer.Pretty())
151
+ peerID := zap.String("peer", e.peer.String())
152
153
switch e.kind {
154
case eventConnect: