stop using go-libp2p deprecated peer.ID.Pretty

Signed-off-by: Icarus9913 <icaruswu66@qq.com>
This commit is contained in:
Icarus9913 2023-09-12 12:55:04 +08:00
parent f06d67c5a2
commit 2a8ea957fa
6 changed files with 11 additions and 11 deletions

View File

@ -381,7 +381,7 @@ func (c *client) sendRequestToPeer(ctx context.Context, peer peer.ID, req *Reque
defer span.End() defer span.End()
if span.IsRecordingEvents() { if span.IsRecordingEvents() {
span.AddAttributes( span.AddAttributes(
trace.StringAttribute("peer", peer.Pretty()), trace.StringAttribute("peer", peer.String()),
) )
} }
defer func() { defer func() {

View File

@ -282,7 +282,7 @@ var NetDisconnect = &cli.Command{
fmt.Println("failure") fmt.Println("failure")
return err return err
} }
fmt.Printf("disconnect %s: ", pid.Pretty()) fmt.Printf("disconnect %s: ", pid)
err = api.NetDisconnect(ctx, pid) err = api.NetDisconnect(ctx, pid)
if err != nil { if err != nil {
fmt.Println("failure") fmt.Println("failure")
@ -312,7 +312,7 @@ var NetConnect = &cli.Command{
} }
for _, pi := range pis { for _, pi := range pis {
fmt.Printf("connect %s: ", pi.ID.Pretty()) fmt.Printf("connect %s: ", pi.ID)
err := api.NetConnect(ctx, pi) err := api.NetConnect(ctx, pi)
if err != nil { if err != nil {
fmt.Println("failure") fmt.Println("failure")

View File

@ -86,7 +86,7 @@ func (ts *apiSuite) testID(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
require.Regexp(t, "^12", id.Pretty()) require.Regexp(t, "^12", id.String())
} }
func (ts *apiSuite) testConnectTwo(t *testing.T) { func (ts *apiSuite) testConnectTwo(t *testing.T) {

View File

@ -342,7 +342,7 @@ func (cc *Consensus) RedirectToLeader(method string, arg interface{}, ret interf
return false, nil return false, nil
} }
logger.Debugf("redirecting %s to leader: %s", method, leader.Pretty()) logger.Debugf("redirecting %s to leader: %s", method, leader)
finalErr = cc.RpcClient.CallContext( finalErr = cc.RpcClient.CallContext(
ctx, ctx,
leader, leader,
@ -394,7 +394,7 @@ func (cc *Consensus) Commit(ctx context.Context, op *ConsensusOp) error {
func (cc *Consensus) AddPeer(ctx context.Context, pid peer.ID) error { func (cc *Consensus) AddPeer(ctx context.Context, pid peer.ID) error {
var finalErr error var finalErr error
for i := 0; i <= cc.config.CommitRetries; i++ { for i := 0; i <= cc.config.CommitRetries; i++ {
logger.Debugf("attempt #%d: AddPeer %s", i, pid.Pretty()) logger.Debugf("attempt #%d: AddPeer %s", i, pid)
if finalErr != nil { if finalErr != nil {
logger.Errorf("retrying to add peer. Attempt #%d failed: %s", i, finalErr) logger.Errorf("retrying to add peer. Attempt #%d failed: %s", i, finalErr)
} }
@ -408,7 +408,7 @@ func (cc *Consensus) AddPeer(ctx context.Context, pid peer.ID) error {
time.Sleep(cc.config.CommitRetryDelay) time.Sleep(cc.config.CommitRetryDelay)
continue continue
} }
logger.Infof("peer added to Raft: %s", pid.Pretty()) logger.Infof("peer added to Raft: %s", pid)
break break
} }
return finalErr return finalErr
@ -419,7 +419,7 @@ func (cc *Consensus) AddPeer(ctx context.Context, pid peer.ID) error {
func (cc *Consensus) RmPeer(ctx context.Context, pid peer.ID) error { func (cc *Consensus) RmPeer(ctx context.Context, pid peer.ID) error {
var finalErr error var finalErr error
for i := 0; i <= cc.config.CommitRetries; i++ { for i := 0; i <= cc.config.CommitRetries; i++ {
logger.Debugf("attempt #%d: RmPeer %s", i, pid.Pretty()) logger.Debugf("attempt #%d: RmPeer %s", i, pid)
if finalErr != nil { if finalErr != nil {
logger.Errorf("retrying to remove peer. Attempt #%d failed: %s", i, finalErr) logger.Errorf("retrying to remove peer. Attempt #%d failed: %s", i, finalErr)
} }
@ -433,7 +433,7 @@ func (cc *Consensus) RmPeer(ctx context.Context, pid peer.ID) error {
time.Sleep(cc.config.CommitRetryDelay) time.Sleep(cc.config.CommitRetryDelay)
continue continue
} }
logger.Infof("peer removed from Raft: %s", pid.Pretty()) logger.Infof("peer removed from Raft: %s", pid)
break break
} }
return finalErr return finalErr

View File

@ -36,7 +36,7 @@ func (a *NetAPI) NetStat(ctx context.Context, scope string) (result api.NetStat,
if len(stat.Peers) > 0 { if len(stat.Peers) > 0 {
result.Peers = make(map[string]network.ScopeStat, len(stat.Peers)) result.Peers = make(map[string]network.ScopeStat, len(stat.Peers))
for p, stat := range stat.Peers { for p, stat := range stat.Peers {
result.Peers[p.Pretty()] = stat result.Peers[p.String()] = stat
} }
} }

View File

@ -41,7 +41,7 @@ func Peerstore() (peerstore.Peerstore, error) {
func Host(mctx helpers.MetricsCtx, lc fx.Lifecycle, params P2PHostIn) (RawHost, error) { func Host(mctx helpers.MetricsCtx, lc fx.Lifecycle, params P2PHostIn) (RawHost, error) {
pkey := params.Peerstore.PrivKey(params.ID) pkey := params.Peerstore.PrivKey(params.ID)
if pkey == nil { if pkey == nil {
return nil, fmt.Errorf("missing private key for node ID: %s", params.ID.Pretty()) return nil, fmt.Errorf("missing private key for node ID: %s", params.ID)
} }
opts := []libp2p.Option{ opts := []libp2p.Option{