From e989d6febe5467738aff0803a52c38f7bff06e5b Mon Sep 17 00:00:00 2001 From: Juan Batiz-Benet Date: Thu, 16 Oct 2014 07:17:49 -0700 Subject: [PATCH] move IDFromPubKey to peer pkg --- cmd/ipfs/init.go | 4 ++-- crypto/spipe/handshake.go | 12 +----------- daemon/daemon_test.go | 4 ++-- peer/peer.go | 10 ++++++++++ routing/dht/dht_test.go | 3 +-- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/cmd/ipfs/init.go b/cmd/ipfs/init.go index f75251b09..2c4446c58 100644 --- a/cmd/ipfs/init.go +++ b/cmd/ipfs/init.go @@ -10,7 +10,7 @@ import ( "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander" config "github.com/jbenet/go-ipfs/config" ci "github.com/jbenet/go-ipfs/crypto" - spipe "github.com/jbenet/go-ipfs/crypto/spipe" + peer "github.com/jbenet/go-ipfs/peer" updates "github.com/jbenet/go-ipfs/updates" u "github.com/jbenet/go-ipfs/util" ) @@ -121,7 +121,7 @@ func initCmd(c *commander.Command, inp []string) error { } cfg.Identity.PrivKey = base64.StdEncoding.EncodeToString(skbytes) - id, err := spipe.IDFromPubKey(pk) + id, err := peer.IDFromPubKey(pk) if err != nil { return err } diff --git a/crypto/spipe/handshake.go b/crypto/spipe/handshake.go index ea06afbdd..8c0ef3d55 100644 --- a/crypto/spipe/handshake.go +++ b/crypto/spipe/handshake.go @@ -288,16 +288,6 @@ func (s *SecurePipe) handleSecureOut(hashType string, mIV, mCKey, mMKey []byte) } } -// IDFromPubKey retrieves a Public Key from the peer given by pk -func IDFromPubKey(pk ci.PubKey) (peer.ID, error) { - b, err := pk.Bytes() - if err != nil { - return nil, err - } - hash := u.Hash(b) - return peer.ID(hash), nil -} - // Determines which algorithm to use. Note: f(a, b) = f(b, a) func selectBest(myPrefs, theirPrefs string) (string, error) { // Person with greatest hash gets first choice. @@ -334,7 +324,7 @@ func selectBest(myPrefs, theirPrefs string) (string, error) { // else, construct it. func getOrConstructPeer(peers peer.Peerstore, rpk ci.PubKey) (*peer.Peer, error) { - rid, err := IDFromPubKey(rpk) + rid, err := peer.IDFromPubKey(rpk) if err != nil { return nil, err } diff --git a/daemon/daemon_test.go b/daemon/daemon_test.go index ad65bfe26..7fba74269 100644 --- a/daemon/daemon_test.go +++ b/daemon/daemon_test.go @@ -9,7 +9,7 @@ import ( config "github.com/jbenet/go-ipfs/config" core "github.com/jbenet/go-ipfs/core" ci "github.com/jbenet/go-ipfs/crypto" - spipe "github.com/jbenet/go-ipfs/crypto/spipe" + peer "github.com/jbenet/go-ipfs/peer" ) func TestInitializeDaemonListener(t *testing.T) { @@ -23,7 +23,7 @@ func TestInitializeDaemonListener(t *testing.T) { t.Fatal(err) } - ident, _ := spipe.IDFromPubKey(pub) + ident, _ := peer.IDFromPubKey(pub) privKey := base64.StdEncoding.EncodeToString(prbytes) pID := ident.Pretty() diff --git a/peer/peer.go b/peer/peer.go index 0961f3408..1887208dd 100644 --- a/peer/peer.go +++ b/peer/peer.go @@ -36,6 +36,16 @@ func DecodePrettyID(s string) ID { return b58.Decode(s) } +// IDFromPubKey retrieves a Public Key from the peer given by pk +func IDFromPubKey(pk ic.PubKey) (ID, error) { + b, err := pk.Bytes() + if err != nil { + return nil, err + } + hash := u.Hash(b) + return ID(hash), nil +} + // Map maps Key (string) : *Peer (slices are not comparable). type Map map[u.Key]*Peer diff --git a/routing/dht/dht_test.go b/routing/dht/dht_test.go index 36f27a222..2861be73a 100644 --- a/routing/dht/dht_test.go +++ b/routing/dht/dht_test.go @@ -10,7 +10,6 @@ import ( ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr" ci "github.com/jbenet/go-ipfs/crypto" - spipe "github.com/jbenet/go-ipfs/crypto/spipe" inet "github.com/jbenet/go-ipfs/net" mux "github.com/jbenet/go-ipfs/net/mux" netservice "github.com/jbenet/go-ipfs/net/service" @@ -74,7 +73,7 @@ func makePeer(addr ma.Multiaddr) *peer.Peer { } p.PrivKey = sk p.PubKey = pk - id, err := spipe.IDFromPubKey(pk) + id, err := peer.IDFromPubKey(pk) if err != nil { panic(err) }