Skip to content

Commit

Permalink
stop using go-libp2p deprecated peer.ID.Pretty
Browse files Browse the repository at this point in the history
Signed-off-by: Icarus9913 <icaruswu66@qq.com>
  • Loading branch information
Icarus9913 committed Sep 12, 2023
1 parent 0eeb1f5 commit 4ba5a95
Show file tree
Hide file tree
Showing 18 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion client/rpc/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (api *DhtAPI) FindPeer(ctx context.Context, p peer.ID) (peer.AddrInfo, erro
Type routing.QueryEventType
Responses []peer.AddrInfo
}
resp, err := api.core().Request("dht/findpeer", p.Pretty()).Send(ctx)
resp, err := api.core().Request("dht/findpeer", p.String()).Send(ctx)
if err != nil {
return peer.AddrInfo{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion client/rpc/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
type SwarmAPI HttpApi

func (api *SwarmAPI) Connect(ctx context.Context, pi peer.AddrInfo) error {
pidma, err := multiaddr.NewComponent("p2p", pi.ID.Pretty())
pidma, err := multiaddr.NewComponent("p2p", pi.ID.String())

Check warning on line 17 in client/rpc/swarm.go

View check run for this annotation

Codecov / codecov/patch

client/rpc/swarm.go#L17

Added line #L17 was not covered by tests
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions core/commands/dht_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ func TestKeyTranslation(t *testing.T) {
pkname := namesys.PkKeyForID(pid)
ipnsname := ipns.NameFromPeer(pid).RoutingKey()

pkk, err := escapeDhtKey("/pk/" + pid.Pretty())
pkk, err := escapeDhtKey("/pk/" + pid.String())
if err != nil {
t.Fatal(err)
}

ipnsk, err := escapeDhtKey("/ipns/" + pid.Pretty())
ipnsk, err := escapeDhtKey("/ipns/" + pid.String())
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion core/commands/name/ipns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down
4 changes: 2 additions & 2 deletions core/commands/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ trip latency information.
if len(n.Peerstore.Addrs(pid)) == 0 {
// Make sure we can find the node in question
if err := res.Emit(&PingResult{
Text: fmt.Sprintf("Looking up peer %s", pid.Pretty()),
Text: fmt.Sprintf("Looking up peer %s", pid),

Check warning on line 82 in core/commands/ping.go

View check run for this annotation

Codecov / codecov/patch

core/commands/ping.go#L82

Added line #L82 was not covered by tests
Success: true,
}); err != nil {
return err
Expand All @@ -95,7 +95,7 @@ trip latency information.
}

if err := res.Emit(&PingResult{
Text: fmt.Sprintf("PING %s.", pid.Pretty()),
Text: fmt.Sprintf("PING %s.", pid),

Check warning on line 98 in core/commands/ping.go

View check run for this annotation

Codecov / codecov/patch

core/commands/ping.go#L98

Added line #L98 was not covered by tests
Success: true,
}); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions core/commands/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),

Check warning on line 113 in core/commands/pubsub.go

View check run for this annotation

Codecov / codecov/patch

core/commands/pubsub.go#L113

Added line #L113 was not covered by tests
Seqno: encoder.Encode(msg.Seq()),
}
for _, topic := range msg.Topics() {
Expand Down Expand Up @@ -323,7 +323,7 @@ TOPIC AND DATA ENCODING
list := &stringList{make([]string, 0, len(peers))}

for _, peer := range peers {
list.Strings = append(list.Strings, peer.Pretty())
list.Strings = append(list.Strings, peer.String())

Check warning on line 326 in core/commands/pubsub.go

View check run for this annotation

Codecov / codecov/patch

core/commands/pubsub.go#L326

Added line #L326 was not covered by tests
}
sort.Strings(list.Strings)
return cmds.EmitOnce(res, list)
Expand Down
4 changes: 2 additions & 2 deletions core/commands/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ var findProvidersRoutingCmd = &cmds.Command{
if verbose {
fmt.Fprintf(out, "provider: ")
}
fmt.Fprintf(out, "%s\n", prov.ID.Pretty())
fmt.Fprintf(out, "%s\n", prov.ID)

Check warning on line 117 in core/commands/routing.go

View check run for this annotation

Codecov / codecov/patch

core/commands/routing.go#L117

Added line #L117 was not covered by tests
if verbose {
for _, a := range prov.Addrs {
fmt.Fprintf(out, "\t%s\n", a)
Expand Down Expand Up @@ -479,7 +479,7 @@ identified by QmFoo.
return nil
},
routing.Value: func(obj *routing.QueryEvent, out io.Writer, verbose bool) error {
fmt.Fprintf(out, "%s\n", obj.ID.Pretty())
fmt.Fprintf(out, "%s\n", obj.ID)

Check warning on line 482 in core/commands/routing.go

View check run for this annotation

Codecov / codecov/patch

core/commands/routing.go#L482

Added line #L482 was not covered by tests
return nil
},
}
Expand Down
10 changes: 5 additions & 5 deletions core/commands/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),

Check warning on line 265 in core/commands/swarm.go

View check run for this annotation

Codecov / codecov/patch

core/commands/swarm.go#L265

Added line #L265 was not covered by tests
}

if verbose || direction {
Expand Down Expand Up @@ -536,7 +536,7 @@ var swarmAddrsCmd = &cmds.Command{

out := make(map[string][]string)
for p, paddrs := range addrs {
s := p.Pretty()
s := p.String()

Check warning on line 539 in core/commands/swarm.go

View check run for this annotation

Codecov / codecov/patch

core/commands/swarm.go#L539

Added line #L539 was not covered by tests
for _, a := range paddrs {
out[s] = append(out[s], a.String())
}
Expand Down Expand Up @@ -599,7 +599,7 @@ var swarmAddrsLocalCmd = &cmds.Command{
for _, addr := range maddrs {
saddr := addr.String()
if showid {
saddr = path.Join(saddr, p2pProtocolName, self.ID().Pretty())
saddr = path.Join(saddr, p2pProtocolName, self.ID().String())

Check warning on line 602 in core/commands/swarm.go

View check run for this annotation

Codecov / codecov/patch

core/commands/swarm.go#L602

Added line #L602 was not covered by tests
}
addrs = append(addrs, saddr)
}
Expand Down Expand Up @@ -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()

Check warning on line 683 in core/commands/swarm.go

View check run for this annotation

Codecov / codecov/patch

core/commands/swarm.go#L683

Added line #L683 was not covered by tests

err := api.Swarm().Connect(req.Context, pi)
if err != nil {
Expand Down Expand Up @@ -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()

Check warning on line 748 in core/commands/swarm.go

View check run for this annotation

Codecov / codecov/patch

core/commands/swarm.go#L748

Added line #L748 was not covered by tests
if err := api.Swarm().Disconnect(req.Context, addr); err != nil {
msg += " failure: " + err.Error()
} else {
Expand Down
2 changes: 1 addition & 1 deletion core/coreapi/test/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion core/node/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion core/node/libp2p/hostopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var DefaultHostOption HostOption = constructPeerHost
func constructPeerHost(id peer.ID, ps peerstore.Peerstore, options ...libp2p.Option) (host.Host, error) {
pkey := ps.PrivKey(id)
if pkey == nil {
return nil, fmt.Errorf("missing private key for node ID: %s", id.Pretty())
return nil, fmt.Errorf("missing private key for node ID: %s", id)

Check warning on line 20 in core/node/libp2p/hostopt.go

View check run for this annotation

Codecov / codecov/patch

core/node/libp2p/hostopt.go#L20

Added line #L20 was not covered by tests
}
options = append([]libp2p.Option{libp2p.Identity(pkey), libp2p.Peerstore(ps)}, options...)
return libp2p.New(options...)
Expand Down
2 changes: 1 addition & 1 deletion core/node/libp2p/rcmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),

Check warning on line 363 in core/node/libp2p/rcmgr.go

View check run for this annotation

Codecov / codecov/patch

core/node/libp2p/rcmgr.go#L363

Added line #L363 was not covered by tests
p,
)...)
}
Expand Down
4 changes: 2 additions & 2 deletions fuse/ipns/ipns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion fuse/ipns/ipns_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions p2p/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, l.proto)
return
}

Expand Down Expand Up @@ -109,7 +109,7 @@ func (l *localListener) ListenAddress() ma.Multiaddr {
}

func (l *localListener) TargetAddress() ma.Multiaddr {
addr, err := ma.NewMultiaddr(maPrefix + l.peer.Pretty())
addr, err := ma.NewMultiaddr(maPrefix + l.peer.String())
if err != nil {
panic(err)
}
Expand Down
6 changes: 3 additions & 3 deletions p2p/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ func (l *remoteListener) handleStream(remote net.Stream) {
peer := remote.Conn().RemotePeer()

if l.reportRemote {
if _, err := fmt.Fprintf(local, "%s\n", peer.Pretty()); err != nil {
if _, err := fmt.Fprintf(local, "%s\n", peer); err != nil {
_ = remote.Reset()
return
}
}

peerMa, err := ma.NewMultiaddr(maPrefix + peer.Pretty())
peerMa, err := ma.NewMultiaddr(maPrefix + peer.String())
if err != nil {
_ = remote.Reset()
return
Expand All @@ -88,7 +88,7 @@ func (l *remoteListener) Protocol() protocol.ID {
}

func (l *remoteListener) ListenAddress() ma.Multiaddr {
addr, err := ma.NewMultiaddr(maPrefix + l.p2p.identity.Pretty())
addr, err := ma.NewMultiaddr(maPrefix + l.p2p.identity.String())
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/plugins/peerlog/peerlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (pl *peerLogPlugin) collectEvents(node *core.IpfsNode) {
case e = <-pl.events:
}

peerID := zap.String("peer", e.peer.Pretty())
peerID := zap.String("peer", e.peer.String())

Check warning on line 151 in plugin/plugins/peerlog/peerlog.go

View check run for this annotation

Codecov / codecov/patch

plugin/plugins/peerlog/peerlog.go#L151

Added line #L151 was not covered by tests

switch e.kind {
case eventConnect:
Expand Down

0 comments on commit 4ba5a95

Please sign in to comment.