Skip to content

Commit

Permalink
Merge pull request ipfs#65 from libp2p/feat/pubkey-extract
Browse files Browse the repository at this point in the history
Feat/pubkey extract
  • Loading branch information
whyrusleeping committed Jul 12, 2017
2 parents c311095 + 95a3e5d commit 5a05448
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 23 deletions.
44 changes: 22 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -60,9 +60,9 @@
},
{
"author": "whyrusleeping",
"hash": "QmXZSd1qR5BxZkPyuwfT5jpqQFScZccoZvDneXsKzCNHWX",
"hash": "QmPgDWmTmuzvP7QE5zwo1TmjbJme9pmZHNujB2453jkCTr",
"name": "go-libp2p-peerstore",
"version": "1.4.8"
"version": "1.4.9"
},
{
"author": "whyrusleeping",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
8 changes: 7 additions & 1 deletion records.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
34 changes: 34 additions & 0 deletions records_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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")
}
}

0 comments on commit 5a05448

Please sign in to comment.