Commit 5a05448e authored by Jeromy Johnson's avatar Jeromy Johnson Committed by GitHub

Merge pull request #65 from libp2p/feat/pubkey-extract

Feat/pubkey extract
parents c3110959 95a3e5da
......@@ -14,15 +14,15 @@
},
{
"author": "whyrusleeping",
"hash": "QmP1DfoUjiWH2ZBo1PBH6FupdBucbDepx3HpWmEY6JMUpY",
"hash": "QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo",
"name": "go-libp2p-crypto",
"version": "1.4.2"
"version": "1.5.0"
},
{
"author": "whyrusleeping",
"hash": "QmdS9KpbDyPrieswibZhkod1oXqRwZJrUPzxCofAMWpFGq",
"hash": "QmXYjuNuxVzXKJCfWasQk1RqkhVLDM9jtUKhqc2WPQmFSB",
"name": "go-libp2p-peer",
"version": "2.1.7"
"version": "2.2.0"
},
{
"hash": "QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP",
......@@ -60,9 +60,9 @@
},
{
"author": "whyrusleeping",
"hash": "QmXZSd1qR5BxZkPyuwfT5jpqQFScZccoZvDneXsKzCNHWX",
"hash": "QmPgDWmTmuzvP7QE5zwo1TmjbJme9pmZHNujB2453jkCTr",
"name": "go-libp2p-peerstore",
"version": "1.4.8"
"version": "1.4.9"
},
{
"author": "whyrusleeping",
......@@ -84,27 +84,27 @@
},
{
"author": "whyrusleeping",
"hash": "QmdVnYKahrvndXhyreWhY8YT3a5chJoWv8b4wVyH9JG2KB",
"hash": "QmSXpwmggGd8fe7e9abqRuST7SqaZjrz3Cg5avMJbdmKGe",
"name": "go-testutil",
"version": "1.1.7"
"version": "1.1.8"
},
{
"author": "whyrusleeping",
"hash": "QmWYCqr6UDqqD1bfRybaAPtbAqcN3TSJpveaBXMwbQ3ePZ",
"hash": "QmbxkgUceEcuSZ4ZdBA3x74VUDSSYjHYmmeEqkjxbtZ6Jg",
"name": "go-libp2p-record",
"version": "2.1.4"
"version": "2.1.5"
},
{
"author": "whyrusleeping",
"hash": "QmaQG6fJdzn2532WHoPdVwKqftXr6iCSr5NtWyGi1BHytT",
"hash": "QmbiCMdwmmhif5axuGSHzYbPFGeKjLAuMY6JrGpVteHFsy",
"name": "go-libp2p-kbucket",
"version": "2.1.9"
"version": "2.1.10"
},
{
"author": "whyrusleeping",
"hash": "QmP1wMAqk6aZYRZirbaAwmrNeqFRgQrwBt3orUtvSa1UYD",
"hash": "QmPjTrrSfE6TzLv6ya6VWhGcCgPrUAdcgrDcQyRDX2VyW1",
"name": "go-libp2p-routing",
"version": "2.2.16"
"version": "2.2.17"
},
{
"author": "whyrusleeping",
......@@ -114,27 +114,27 @@
},
{
"author": "whyrusleeping",
"hash": "Qma4RJSuh7mMeJQYCqMbKzekn6EwBo7HEs5AQYjVRMQATB",
"hash": "QmTprEaAA2A9bst5XH7exuyi5KzNMK3SEDNN8rBDnKWcUS",
"name": "go-cid",
"version": "0.7.16"
"version": "0.7.17"
},
{
"author": "whyrusleeping",
"hash": "QmVesPmqbPp7xRGyY96tnBwzDtVV1nqv4SCVxo5zCqKyH8",
"hash": "QmT4PgCNdv73hnFAqzHqwW44q7M9PWpykSswHDxndquZbc",
"name": "go-libp2p-loggables",
"version": "1.1.7"
"version": "1.1.8"
},
{
"author": "whyrusleeping",
"hash": "QmUywuGNZoUKV8B9iyvup9bPkLiMrhTsyVMkeSXW5VxAfC",
"hash": "QmZy7c24mmkEHpNJndwgsEE3wcVxHd8yB969yTnAJFVw7f",
"name": "go-libp2p-host",
"version": "1.3.14"
"version": "1.3.15"
},
{
"author": "whyrusleeping",
"hash": "QmQA5mdxru8Bh6dpC9PJfSkumqnmHgJX7knxSgBo5Lpime",
"hash": "QmapADMpK4e5kFGBxC2aHreaDqKP9vmMng5f91MA14Ces9",
"name": "go-libp2p",
"version": "4.3.12"
"version": "4.4.1"
}
],
"gxVersion": "0.4.0",
......
......@@ -24,8 +24,14 @@ const MaxRecordAge = time.Hour * 36
func (dht *IpfsDHT) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey, error) {
log.Debugf("getPublicKey for: %s", p)
// try extracting from identity.
pk := p.ExtractPublicKey()
if pk != nil {
return pk, nil
}
// check locally.
pk := dht.peerstore.PubKey(p)
pk = dht.peerstore.PubKey(p)
if pk != nil {
return pk, nil
}
......
package dht
import (
"context"
"crypto/rand"
"testing"
ci "github.com/libp2p/go-libp2p-crypto"
peer "github.com/libp2p/go-libp2p-peer"
)
func TestPubkeyExtract(t *testing.T) {
_, pk, err := ci.GenerateEd25519Key(rand.Reader)
if err != nil {
t.Fatal(err)
}
pid, err := peer.IDFromEd25519PublicKey(pk)
if err != nil {
t.Fatal(err)
}
// no need to actually construct one
d := new(IpfsDHT)
pk_out, err := d.GetPublicKey(context.Background(), pid)
if err != nil {
t.Fatal(err)
}
if !pk_out.Equals(pk) {
t.Fatal("got incorrect public key out")
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment