From 6cef973b925c54e5028022d3da22e0f73b001541 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Thu, 22 Jul 2021 21:17:36 +0200 Subject: [PATCH] remove deprecated functions in the peer package (#205) --- peer/addrinfo.go | 2 +- peer/addrinfo_test.go | 4 ++-- peer/peer.go | 40 +++------------------------------------- peer/peer_serde.go | 8 ++++---- peer/peer_test.go | 6 +++--- 5 files changed, 13 insertions(+), 47 deletions(-) diff --git a/peer/addrinfo.go b/peer/addrinfo.go index 6c579fc8..19b07a4b 100644 --- a/peer/addrinfo.go +++ b/peer/addrinfo.go @@ -87,7 +87,7 @@ func AddrInfoFromP2pAddr(m ma.Multiaddr) (*AddrInfo, error) { // AddrInfoToP2pAddrs converts an AddrInfo to a list of Multiaddrs. func AddrInfoToP2pAddrs(pi *AddrInfo) ([]ma.Multiaddr, error) { var addrs []ma.Multiaddr - p2ppart, err := ma.NewComponent("p2p", IDB58Encode(pi.ID)) + p2ppart, err := ma.NewComponent("p2p", Encode(pi.ID)) if err != nil { return nil, err } diff --git a/peer/addrinfo_test.go b/peer/addrinfo_test.go index 1369ff8e..86fe87ff 100644 --- a/peer/addrinfo_test.go +++ b/peer/addrinfo_test.go @@ -15,11 +15,11 @@ var ( func init() { var err error - testID, err = IDB58Decode("QmS3zcG7LhYZYSJMhyRZvTddvbNUqtt8BJpaSs6mi1K5Va") + testID, err = Decode("QmS3zcG7LhYZYSJMhyRZvTddvbNUqtt8BJpaSs6mi1K5Va") if err != nil { panic(err) } - maddrPeer = ma.StringCast("/p2p/" + IDB58Encode(testID)) + maddrPeer = ma.StringCast("/p2p/" + Encode(testID)) maddrTpt = ma.StringCast("/ip4/127.0.0.1/tcp/1234") maddrFull = maddrTpt.Encapsulate(maddrPeer) } diff --git a/peer/peer.go b/peer/peer.go index 81b88d9f..fd895c84 100644 --- a/peer/peer.go +++ b/peer/peer.go @@ -2,12 +2,11 @@ package peer import ( - "encoding/hex" "errors" "fmt" "strings" - cid "github.com/ipfs/go-cid" + "github.com/ipfs/go-cid" ic "github.com/libp2p/go-libp2p-core/crypto" b58 "github.com/mr-tron/base58/base58" mh "github.com/multiformats/go-multihash" @@ -43,7 +42,7 @@ type ID string // Pretty returns a base58-encoded string representation of the ID. func (id ID) Pretty() string { - return IDB58Encode(id) + return Encode(id) } // Loggable returns a pretty peer ID string in loggable JSON format. @@ -131,39 +130,6 @@ func IDFromBytes(b []byte) (ID, error) { return ID(b), nil } -// IDB58Decode decodes a peer ID. -// -// Deprecated: Use Decode. -func IDB58Decode(s string) (ID, error) { - return Decode(s) -} - -// IDB58Encode returns the base58-encoded multihash representation of the ID. -// -// Deprecated: Use Encode. -func IDB58Encode(id ID) string { - return b58.Encode([]byte(id)) -} - -// IDHexDecode accepts a hex-encoded multihash representing a peer ID -// and returns the decoded ID if the input is valid. -// -// Deprecated: Don't raw-hex encode peer IDs, use base16 CIDs. -func IDHexDecode(s string) (ID, error) { - m, err := mh.FromHexString(s) - if err != nil { - return "", err - } - return ID(m), err -} - -// IDHexEncode returns the hex-encoded multihash representation of the ID. -// -// Deprecated: Don't raw-hex encode peer IDs, use base16 CIDs. -func IDHexEncode(id ID) string { - return hex.EncodeToString([]byte(id)) -} - // Decode accepts an encoded peer ID and returns the decoded ID if the input is // valid. // @@ -191,7 +157,7 @@ func Decode(s string) (ID, error) { // At the moment, it base58 encodes the peer ID but, in the future, it will // switch to encoding it as a CID by default. func Encode(id ID) string { - return IDB58Encode(id) + return b58.Encode([]byte(id)) } // FromCid converts a CID to a peer ID, if possible. diff --git a/peer/peer_serde.go b/peer/peer_serde.go index e401fbbb..e3ac3f2c 100644 --- a/peer/peer_serde.go +++ b/peer/peer_serde.go @@ -47,7 +47,7 @@ func (id ID) Size() int { } func (id ID) MarshalJSON() ([]byte, error) { - return json.Marshal(IDB58Encode(id)) + return json.Marshal(Encode(id)) } func (id *ID) UnmarshalJSON(data []byte) (err error) { @@ -55,18 +55,18 @@ func (id *ID) UnmarshalJSON(data []byte) (err error) { if err = json.Unmarshal(data, &v); err != nil { return err } - *id, err = IDB58Decode(v) + *id, err = Decode(v) return err } // MarshalText returns the text encoding of the ID. func (id ID) MarshalText() ([]byte, error) { - return []byte(IDB58Encode(id)), nil + return []byte(Encode(id)), nil } // UnmarshalText restores the ID from its text encoding. func (id *ID) UnmarshalText(data []byte) error { - pid, err := IDB58Decode(string(data)) + pid, err := Decode(string(data)) if err != nil { return err } diff --git a/peer/peer_test.go b/peer/peer_test.go index b203a7ad..fa6d81c8 100644 --- a/peer/peer_test.go +++ b/peer/peer_test.go @@ -90,7 +90,7 @@ func (ks *keyset) load(hpkp, skBytesStr string) error { func TestIDMatchesPublicKey(t *testing.T) { test := func(ks keyset) { - p1, err := IDB58Decode(ks.hpkp) + p1, err := Decode(ks.hpkp) if err != nil { t.Fatal(err) } @@ -125,7 +125,7 @@ func TestIDMatchesPublicKey(t *testing.T) { func TestIDMatchesPrivateKey(t *testing.T) { test := func(ks keyset) { - p1, err := IDB58Decode(ks.hpkp) + p1, err := Decode(ks.hpkp) if err != nil { t.Fatal(err) } @@ -155,7 +155,7 @@ func TestIDMatchesPrivateKey(t *testing.T) { func TestIDEncoding(t *testing.T) { test := func(ks keyset) { - p1, err := IDB58Decode(ks.hpkp) + p1, err := Decode(ks.hpkp) if err != nil { t.Fatal(err) }