mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-25 12:27:43 +08:00
move IDFromPubKey to peer pkg
This commit is contained in:
parent
18cfe02d38
commit
e989d6febe
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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()
|
||||
|
||||
|
||||
10
peer/peer.go
10
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
|
||||
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user