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

core/peer: remove deprecated ID.Pretty method #2565

Merged
merged 2 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 core/peer/addrinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func AddrInfoToP2pAddrs(pi *AddrInfo) ([]ma.Multiaddr, error) {

func (pi *AddrInfo) Loggable() map[string]interface{} {
return map[string]interface{}{
"peerID": pi.ID.Pretty(),
"peerID": pi.ID.String(),
"addrs": pi.Addrs,
}
}
Expand Down
10 changes: 5 additions & 5 deletions core/peer/addrinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package peer_test
import (
"testing"

ma "github.com/multiformats/go-multiaddr"

. "github.com/libp2p/go-libp2p/core/peer"

ma "github.com/multiformats/go-multiaddr"
)

var (
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestAddrInfosFromP2pAddrs(t *testing.T) {
t.Fatal(err)
}
for _, info := range infos {
exaddrs, ok := expected[info.ID.Pretty()]
exaddrs, ok := expected[info.ID.String()]
if !ok {
t.Fatalf("didn't expect peer %s", info.ID)
}
Expand All @@ -129,7 +129,7 @@ func TestAddrInfosFromP2pAddrs(t *testing.T) {
t.Fatalf("expected %s, got %s", exaddrs[i], addr)
}
}
delete(expected, info.ID.Pretty())
delete(expected, info.ID.String())
}
}

Expand All @@ -144,7 +144,7 @@ func TestAddrInfoJSON(t *testing.T) {
t.Fatal(err)
}
if addrInfo.ID != testID {
t.Fatalf("expected ID to equal %s, got %s", testID.Pretty(), addrInfo.ID.Pretty())
t.Fatalf("expected ID to equal %s, got %s", testID, addrInfo.ID)
}
if len(addrInfo.Addrs) != 1 || !addrInfo.Addrs[0].Equal(maddrFull) {
t.Fatalf("expected addrs to match %v, got %v", maddrFull, addrInfo.Addrs)
Expand Down
6 changes: 0 additions & 6 deletions core/peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ const maxInlineKeyLength = 42
// hash output as a multihash. See IDFromPublicKey for details.
type ID string

// Pretty returns a base58-encoded string representation of the ID.
// Deprecated: use String() instead.
func (id ID) Pretty() string {
return id.String()
}

// Loggable returns a pretty peer ID string in loggable JSON format.
func (id ID) Loggable() map[string]interface{} {
return map[string]interface{}{
Expand Down
10 changes: 5 additions & 5 deletions p2p/host/autonat/svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (as *autoNATService) handleStream(s network.Stream) {
defer s.Close()

pid := s.Conn().RemotePeer()
log.Debugf("New stream from %s", pid.Pretty())
log.Debugf("New stream from %s", pid)

r := pbio.NewDelimitedReader(s, maxMsgSize)
w := pbio.NewDelimitedWriter(s)
Expand All @@ -78,14 +78,14 @@ func (as *autoNATService) handleStream(s network.Stream) {

err := r.ReadMsg(&req)
if err != nil {
log.Debugf("Error reading message from %s: %s", pid.Pretty(), err.Error())
log.Debugf("Error reading message from %s: %s", pid, err.Error())
s.Reset()
return
}

t := req.GetType()
if t != pb.Message_DIAL {
log.Debugf("Unexpected message from %s: %s (%d)", pid.Pretty(), t.String(), t)
log.Debugf("Unexpected message from %s: %s (%d)", pid, t.String(), t)
s.Reset()
return
}
Expand All @@ -96,7 +96,7 @@ func (as *autoNATService) handleStream(s network.Stream) {

err = w.WriteMsg(&res)
if err != nil {
log.Debugf("Error writing response to %s: %s", pid.Pretty(), err.Error())
log.Debugf("Error writing response to %s: %s", pid, err.Error())
s.Reset()
return
}
Expand Down Expand Up @@ -234,7 +234,7 @@ func (as *autoNATService) doDial(pi peer.AddrInfo) *pb.Message_DialResponse {

conn, err := as.config.dialer.DialPeer(ctx, pi.ID)
if err != nil {
log.Debugf("error dialing %s: %s", pi.ID.Pretty(), err.Error())
log.Debugf("error dialing %s: %s", pi.ID, err.Error())
// wait for the context to timeout to avoid leaking timing information
// this renders the service ineffective as a port scanner
<-ctx.Done()
Expand Down
2 changes: 1 addition & 1 deletion p2p/host/autorelay/relay_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ func (rf *relayFinder) relayAddrs(addrs []ma.Multiaddr) []ma.Multiaddr {
for p := range rf.relays {
addrs := cleanupAddressSet(rf.host.Peerstore().Addrs(p))
relayAddrCnt += len(addrs)
circuit := ma.StringCast(fmt.Sprintf("/p2p/%s/p2p-circuit", p.Pretty()))
circuit := ma.StringCast(fmt.Sprintf("/p2p/%s/p2p-circuit", p))
for _, addr := range addrs {
pub := addr.Encapsulate(circuit)
raddrs = append(raddrs, pub)
Expand Down
12 changes: 6 additions & 6 deletions p2p/host/peerstore/pstoreds/addr_book.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ func (ab *dsAddrBook) storeSignedPeerRecord(p peer.ID, envelope *record.Envelope
func (ab *dsAddrBook) GetPeerRecord(p peer.ID) *record.Envelope {
pr, err := ab.loadRecord(p, true, false)
if err != nil {
log.Errorf("unable to load record for peer %s: %v", p.Pretty(), err)
log.Errorf("unable to load record for peer %s: %v", p, err)
return nil
}
pr.RLock()
Expand All @@ -372,7 +372,7 @@ func (ab *dsAddrBook) GetPeerRecord(p peer.ID) *record.Envelope {
}
state, _, err := record.ConsumeEnvelope(pr.CertifiedRecord.Raw, peer.PeerRecordEnvelopeDomain)
if err != nil {
log.Errorf("error unmarshaling stored signed peer record for peer %s: %v", p.Pretty(), err)
log.Errorf("error unmarshaling stored signed peer record for peer %s: %v", p, err)
return nil
}
return state
Expand All @@ -398,7 +398,7 @@ func (ab *dsAddrBook) SetAddrs(p peer.ID, addrs []ma.Multiaddr, ttl time.Duratio
func (ab *dsAddrBook) UpdateAddrs(p peer.ID, oldTTL time.Duration, newTTL time.Duration) {
pr, err := ab.loadRecord(p, true, false)
if err != nil {
log.Errorf("failed to update ttls for peer %s: %s\n", p.Pretty(), err)
log.Errorf("failed to update ttls for peer %s: %s\n", p, err)
return
}

Expand All @@ -423,7 +423,7 @@ func (ab *dsAddrBook) UpdateAddrs(p peer.ID, oldTTL time.Duration, newTTL time.D
func (ab *dsAddrBook) Addrs(p peer.ID) []ma.Multiaddr {
pr, err := ab.loadRecord(p, true, true)
if err != nil {
log.Warn("failed to load peerstore entry for peer %v while querying addrs, err: %v", p, err)
log.Warnf("failed to load peerstore entry for peer %s while querying addrs, err: %v", p, err)
return nil
}

Expand Down Expand Up @@ -466,7 +466,7 @@ func (ab *dsAddrBook) ClearAddrs(p peer.ID) {

key := addrBookBase.ChildString(b32.RawStdEncoding.EncodeToString([]byte(p)))
if err := ab.ds.Delete(context.TODO(), key); err != nil {
log.Errorf("failed to clear addresses for peer %s: %v", p.Pretty(), err)
log.Errorf("failed to clear addresses for peer %s: %v", p, err)
}
}

Expand All @@ -477,7 +477,7 @@ func (ab *dsAddrBook) setAddrs(p peer.ID, addrs []ma.Multiaddr, ttl time.Duratio

pr, err := ab.loadRecord(p, true, false)
if err != nil {
return fmt.Errorf("failed to load peerstore entry for peer %v while setting addrs, err: %v", p, err)
return fmt.Errorf("failed to load peerstore entry for peer %s while setting addrs, err: %v", p, err)
}

pr.Lock()
Expand Down
12 changes: 6 additions & 6 deletions p2p/host/peerstore/pstoreds/addr_book_gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (gc *dsAddrBookGc) purgeLookahead() {
cached.Lock()
if cached.clean(gc.ab.clock.Now()) {
if err = cached.flush(batch); err != nil {
log.Warnf("failed to flush entry modified by GC for peer: &v, err: %v", id.Pretty(), err)
log.Warnf("failed to flush entry modified by GC for peer: %s, err: %v", id, err)
}
}
dropOrReschedule(gcKey, cached)
Expand All @@ -241,7 +241,7 @@ func (gc *dsAddrBookGc) purgeLookahead() {
if record.clean(gc.ab.clock.Now()) {
err = record.flush(batch)
if err != nil {
log.Warnf("failed to flush entry modified by GC for peer: &v, err: %v", id.Pretty(), err)
log.Warnf("failed to flush entry modified by GC for peer: %s, err: %v", id, err)
}
}
dropOrReschedule(gcKey, record)
Expand Down Expand Up @@ -353,7 +353,7 @@ func (gc *dsAddrBookGc) populateLookahead() {
}
gcKey := gcLookaheadBase.ChildString(fmt.Sprintf("%d/%s", cached.Addrs[0].Expiry, idb32))
if err = batch.Put(context.TODO(), gcKey, []byte{}); err != nil {
log.Warnf("failed while inserting GC entry for peer: %v, err: %v", id.Pretty(), err)
log.Warnf("failed while inserting GC entry for peer: %s, err: %v", id, err)
}
cached.RUnlock()
continue
Expand All @@ -363,17 +363,17 @@ func (gc *dsAddrBookGc) populateLookahead() {

val, err := gc.ab.ds.Get(context.TODO(), ds.RawKey(result.Key))
if err != nil {
log.Warnf("failed which getting record from store for peer: %v, err: %v", id.Pretty(), err)
log.Warnf("failed which getting record from store for peer: %s, err: %v", id, err)
continue
}
if err := proto.Unmarshal(val, record); err != nil {
log.Warnf("failed while unmarshalling record from store for peer: %v, err: %v", id.Pretty(), err)
log.Warnf("failed while unmarshalling record from store for peer: %s, err: %v", id, err)
continue
}
if len(record.Addrs) > 0 && record.Addrs[0].Expiry <= until {
gcKey := gcLookaheadBase.ChildString(fmt.Sprintf("%d/%s", record.Addrs[0].Expiry, idb32))
if err = batch.Put(context.TODO(), gcKey, []byte{}); err != nil {
log.Warnf("failed while inserting GC entry for peer: %v, err: %v", id.Pretty(), err)
log.Warnf("failed while inserting GC entry for peer: %s, err: %v", id, err)
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions p2p/host/peerstore/pstoreds/keybook.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (kb *dsKeyBook) PubKey(p peer.ID) ic.PubKey {
if value, err := kb.ds.Get(context.TODO(), key); err == nil {
pk, err = ic.UnmarshalPublicKey(value)
if err != nil {
log.Errorf("error when unmarshalling pubkey from datastore for peer %s: %s\n", p.Pretty(), err)
log.Errorf("error when unmarshalling pubkey from datastore for peer %s: %s\n", p, err)
}
} else if err == ds.ErrNotFound {
pk, err = p.ExtractPublicKey()
Expand All @@ -47,20 +47,20 @@ func (kb *dsKeyBook) PubKey(p peer.ID) ic.PubKey {
case peer.ErrNoPublicKey:
return nil
default:
log.Errorf("error when extracting pubkey from peer ID for peer %s: %s\n", p.Pretty(), err)
log.Errorf("error when extracting pubkey from peer ID for peer %s: %s\n", p, err)
return nil
}
pkb, err := ic.MarshalPublicKey(pk)
if err != nil {
log.Errorf("error when turning extracted pubkey into bytes for peer %s: %s\n", p.Pretty(), err)
log.Errorf("error when turning extracted pubkey into bytes for peer %s: %s\n", p, err)
return nil
}
if err := kb.ds.Put(context.TODO(), key, pkb); err != nil {
log.Errorf("error when adding extracted pubkey to peerstore for peer %s: %s\n", p.Pretty(), err)
log.Errorf("error when adding extracted pubkey to peerstore for peer %s: %s\n", p, err)
return nil
}
} else {
log.Errorf("error when fetching pubkey from datastore for peer %s: %s\n", p.Pretty(), err)
log.Errorf("error when fetching pubkey from datastore for peer %s: %s\n", p, err)
}

return pk
Expand All @@ -74,11 +74,11 @@ func (kb *dsKeyBook) AddPubKey(p peer.ID, pk ic.PubKey) error {

val, err := ic.MarshalPublicKey(pk)
if err != nil {
log.Errorf("error while converting pubkey byte string for peer %s: %s\n", p.Pretty(), err)
log.Errorf("error while converting pubkey byte string for peer %s: %s\n", p, err)
return err
}
if err := kb.ds.Put(context.TODO(), peerToKey(p, pubSuffix), val); err != nil {
log.Errorf("error while updating pubkey in datastore for peer %s: %s\n", p.Pretty(), err)
log.Errorf("error while updating pubkey in datastore for peer %s: %s\n", p, err)
return err
}
return nil
Expand Down Expand Up @@ -107,11 +107,11 @@ func (kb *dsKeyBook) AddPrivKey(p peer.ID, sk ic.PrivKey) error {

val, err := ic.MarshalPrivateKey(sk)
if err != nil {
log.Errorf("error while converting privkey byte string for peer %s: %s\n", p.Pretty(), err)
log.Errorf("error while converting privkey byte string for peer %s: %s\n", p, err)
return err
}
if err := kb.ds.Put(context.TODO(), peerToKey(p, privSuffix), val); err != nil {
log.Errorf("error while updating privkey in datastore for peer %s: %s\n", p.Pretty(), err)
log.Errorf("error while updating privkey in datastore for peer %s: %s\n", p, err)
}
return err
}
Expand Down
2 changes: 1 addition & 1 deletion p2p/host/peerstore/test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func RandomPeer(b *testing.B, addrCount int) *peerpair {
}

for i := 0; i < addrCount; i++ {
if addrs[i], err = ma.NewMultiaddr(fmt.Sprintf(aFmt, i, pid.Pretty())); err != nil {
if addrs[i], err = ma.NewMultiaddr(fmt.Sprintf(aFmt, i, pid)); err != nil {
b.Fatal(err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions p2p/net/connmgr/decay.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func (t *decayingTag) Bump(p peer.ID, delta int) error {
default:
return fmt.Errorf(
"unable to bump decaying tag for peer %s, tag %s, delta %d; queue full (len=%d)",
p.Pretty(), t.name, delta, len(t.trkr.bumpTagCh))
p, t.name, delta, len(t.trkr.bumpTagCh))
}
}

Expand All @@ -337,7 +337,7 @@ func (t *decayingTag) Remove(p peer.ID) error {
default:
return fmt.Errorf(
"unable to remove decaying tag for peer %s, tag %s; queue full (len=%d)",
p.Pretty(), t.name, len(t.trkr.removeTagCh))
p.String(), t.name, len(t.trkr.removeTagCh))
marten-seemann marked this conversation as resolved.
Show resolved Hide resolved
marten-seemann marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
6 changes: 3 additions & 3 deletions p2p/net/gostream/gostream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestServerClient(t *testing.T) {
}
defer listener.Close()

if listener.Addr().String() != srvHost.ID().Pretty() {
if listener.Addr().String() != srvHost.ID().String() {
t.Error("bad listener address")
return
}
Expand Down Expand Up @@ -91,11 +91,11 @@ func TestServerClient(t *testing.T) {
t.Fatal(err)
}

if clientConn.LocalAddr().String() != clientHost.ID().Pretty() {
if clientConn.LocalAddr().String() != clientHost.ID().String() {
t.Fatal("Bad LocalAddr")
}

if clientConn.RemoteAddr().String() != srvHost.ID().Pretty() {
if clientConn.RemoteAddr().String() != srvHost.ID().String() {
t.Fatal("Bad RemoteAddr")
}

Expand Down
2 changes: 1 addition & 1 deletion p2p/net/swarm/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func (s *Swarm) addConn(tc transport.CapableConn, dir network.Direction) (*Conn,
// TODO Send disconnect with reason here
err := tc.Close()
if err != nil {
log.Warnf("failed to close connection with peer %s and addr %s; err: %s", p.Pretty(), addr, err)
log.Warnf("failed to close connection with peer %s and addr %s; err: %s", p, addr, err)
}
return nil, ErrGaterDisallowedConnection
}
Expand Down
6 changes: 3 additions & 3 deletions p2p/net/swarm/swarm_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (c *Conn) IsClosed() bool {

func (c *Conn) ID() string {
// format: <first 10 chars of peer id>-<global conn ordinal>
return fmt.Sprintf("%s-%d", c.RemotePeer().Pretty()[0:10], c.id)
return fmt.Sprintf("%s-%d", c.RemotePeer().String()[:10], c.id)
}

// Close closes this connection.
Expand Down Expand Up @@ -147,9 +147,9 @@ func (c *Conn) String() string {
"<swarm.Conn[%T] %s (%s) <-> %s (%s)>",
c.conn.Transport(),
c.conn.LocalMultiaddr(),
c.conn.LocalPeer().Pretty(),
c.conn.LocalPeer(),
c.conn.RemoteMultiaddr(),
c.conn.RemotePeer().Pretty(),
c.conn.RemotePeer(),
)
}

Expand Down
4 changes: 2 additions & 2 deletions p2p/net/swarm/swarm_dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func (s *Swarm) dialPeer(ctx context.Context, p peer.ID) (*Conn, error) {
}

if s.gater != nil && !s.gater.InterceptPeerDial(p) {
log.Debugf("gater disallowed outbound connection to peer %s", p.Pretty())
log.Debugf("gater disallowed outbound connection to peer %s", p)
return nil, &DialError{Peer: p, Cause: ErrGaterDisallowedConnection}
}

Expand Down Expand Up @@ -343,7 +343,7 @@ func (s *Swarm) addrsForDial(ctx context.Context, p peer.ID) (goodAddrs []ma.Mul

func (s *Swarm) resolveAddrs(ctx context.Context, pi peer.AddrInfo) ([]ma.Multiaddr, error) {
proto := ma.ProtocolWithCode(ma.P_P2P).Name
p2paddr, err := ma.NewMultiaddr("/" + proto + "/" + pi.ID.Pretty())
p2paddr, err := ma.NewMultiaddr("/" + proto + "/" + pi.ID.String())
if err != nil {
return nil, err
}
Expand Down
Loading