@cryptotaxi247 / kubo / commits / e989d6feb

move IDFromPubKey to peer pkg

Juan Batiz-Benet committed Oct 16, 2014 at 07:17 UTC e989d6febe5467738aff0803a52c38f7bff06e5b
5 files changed +16 -17
cmd/ipfs/init.go
+2 -2
@@ -10,7 +10,7 @@ import (
10 "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
11 config "github.com/jbenet/go-ipfs/config"
12 ci "github.com/jbenet/go-ipfs/crypto"
13 - spipe "github.com/jbenet/go-ipfs/crypto/spipe"
13 + peer "github.com/jbenet/go-ipfs/peer"
14 updates "github.com/jbenet/go-ipfs/updates"
15 u "github.com/jbenet/go-ipfs/util"
16 )
@@ -121,7 +121,7 @@ func initCmd(c *commander.Command, inp []string) error {
121 }
122 cfg.Identity.PrivKey = base64.StdEncoding.EncodeToString(skbytes)
123
124 - id, err := spipe.IDFromPubKey(pk)
124 + id, err := peer.IDFromPubKey(pk)
125 if err != nil {
126 return err
127 }
crypto/spipe/handshake.go
+1 -11
@@ -288,16 +288,6 @@ func (s *SecurePipe) handleSecureOut(hashType string, mIV, mCKey, mMKey []byte)
288 }
289 }
290
291 -// IDFromPubKey retrieves a Public Key from the peer given by pk
292 -func IDFromPubKey(pk ci.PubKey) (peer.ID, error) {
293 - b, err := pk.Bytes()
294 - if err != nil {
295 - return nil, err
296 - }
297 - hash := u.Hash(b)
298 - return peer.ID(hash), nil
299 -}
300 -
291 // Determines which algorithm to use. Note: f(a, b) = f(b, a)
292 func selectBest(myPrefs, theirPrefs string) (string, error) {
293 // Person with greatest hash gets first choice.
@@ -334,7 +324,7 @@ func selectBest(myPrefs, theirPrefs string) (string, error) {
324 // else, construct it.
325 func getOrConstructPeer(peers peer.Peerstore, rpk ci.PubKey) (*peer.Peer, error) {
326
337 - rid, err := IDFromPubKey(rpk)
327 + rid, err := peer.IDFromPubKey(rpk)
328 if err != nil {
329 return nil, err
330 }
daemon/daemon_test.go
+2 -2
@@ -9,7 +9,7 @@ import (
9 config "github.com/jbenet/go-ipfs/config"
10 core "github.com/jbenet/go-ipfs/core"
11 ci "github.com/jbenet/go-ipfs/crypto"
12 - spipe "github.com/jbenet/go-ipfs/crypto/spipe"
12 + peer "github.com/jbenet/go-ipfs/peer"
13 )
14
15 func TestInitializeDaemonListener(t *testing.T) {
@@ -23,7 +23,7 @@ func TestInitializeDaemonListener(t *testing.T) {
23 t.Fatal(err)
24 }
25
26 - ident, _ := spipe.IDFromPubKey(pub)
26 + ident, _ := peer.IDFromPubKey(pub)
27 privKey := base64.StdEncoding.EncodeToString(prbytes)
28 pID := ident.Pretty()
29
peer/peer.go
+10
@@ -36,6 +36,16 @@ func DecodePrettyID(s string) ID {
36 return b58.Decode(s)
37 }
38
39 +// IDFromPubKey retrieves a Public Key from the peer given by pk
40 +func IDFromPubKey(pk ic.PubKey) (ID, error) {
41 + b, err := pk.Bytes()
42 + if err != nil {
43 + return nil, err
44 + }
45 + hash := u.Hash(b)
46 + return ID(hash), nil
47 +}
48 +
49 // Map maps Key (string) : *Peer (slices are not comparable).
50 type Map map[u.Key]*Peer
51
routing/dht/dht_test.go
+1 -2
@@ -10,7 +10,6 @@ import (
10 ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
11
12 ci "github.com/jbenet/go-ipfs/crypto"
13 - spipe "github.com/jbenet/go-ipfs/crypto/spipe"
13 inet "github.com/jbenet/go-ipfs/net"
14 mux "github.com/jbenet/go-ipfs/net/mux"
15 netservice "github.com/jbenet/go-ipfs/net/service"
@@ -74,7 +73,7 @@ func makePeer(addr ma.Multiaddr) *peer.Peer {
73 }
74 p.PrivKey = sk
75 p.PubKey = pk
77 - id, err := spipe.IDFromPubKey(pk)
76 + id, err := peer.IDFromPubKey(pk)
77 if err != nil {
78 panic(err)
79 }