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

refactor: stop using go-libp2p deprecated peer.ID.Pretty #10121

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
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),
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),
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(),
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())
}
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)
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)
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(),
}

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()
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())
}
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()

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()
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)
}
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(),
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())

switch e.kind {
case eventConnect:
Expand Down