Commit fdf7dbf6 authored by Jeromy's avatar Jeromy

cache public keys and use better method for fetching

parent 64d49feb
......@@ -18,7 +18,7 @@ func KeyForPublicKey(id peer.ID) u.Key {
return u.Key("/pk/" + string(id))
}
func (dht *IpfsDHT) getPublicKeyOnline(ctx context.Context, p peer.ID) (ci.PubKey, error) {
func (dht *IpfsDHT) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey, error) {
log.Debugf("getPublicKey for: %s", p)
// check locally.
......@@ -42,7 +42,6 @@ func (dht *IpfsDHT) getPublicKeyOnline(ctx context.Context, p peer.ID) (ci.PubKe
log.Debugf("pk for %s not in peerstore, and peer failed. trying dht.", p)
pkkey := KeyForPublicKey(p)
// ok, now try the dht. Anyone who has previously fetched the key should have it
val, err := dht.GetValue(ctxT, pkkey)
if err != nil {
log.Warning("Failed to find requested public key.")
......@@ -132,7 +131,7 @@ func (dht *IpfsDHT) verifyRecordOnline(ctx context.Context, r *pb.Record) error
if len(r.Signature) > 0 {
// get the public key, search for it if necessary.
p := peer.ID(r.GetAuthor())
pk, err := dht.getPublicKeyOnline(ctx, p)
pk, err := dht.GetPublicKey(ctx, p)
if err != nil {
return err
}
......
......@@ -6,6 +6,7 @@ import (
"time"
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
ci "github.com/ipfs/go-ipfs/p2p/crypto"
peer "github.com/ipfs/go-ipfs/p2p/peer"
u "github.com/ipfs/go-ipfs/util"
)
......@@ -46,3 +47,7 @@ type IpfsRouting interface {
// TODO expose io.Closer or plain-old Close error
}
type PubKeyFetcher interface {
GetPublicKey(context.Context, peer.ID) (ci.PubKey, error)
}
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