Commit 71f6e255 authored by Jeromy's avatar Jeromy

fix fuse mounting issues

this time, without loading the private key on every startup
parent 9cc5c86e
......@@ -10,6 +10,7 @@ import (
"sync"
"time"
ci "github.com/jbenet/go-ipfs/p2p/crypto"
host "github.com/jbenet/go-ipfs/p2p/host"
peer "github.com/jbenet/go-ipfs/p2p/peer"
protocol "github.com/jbenet/go-ipfs/p2p/protocol"
......@@ -234,9 +235,23 @@ func (dht *IpfsDHT) getLocal(key u.Key) ([]byte, error) {
return rec.GetValue(), nil
}
func (dht *IpfsDHT) getOwnPrivateKey() (ci.PrivKey, error) {
sk := dht.peerstore.PrivKey(dht.self)
if sk == nil {
log.Errorf("%s dht cannot get own private key!", dht.self)
return nil, fmt.Errorf("cannot get private key to sign record!")
}
return sk, nil
}
// putLocal stores the key value pair in the datastore
func (dht *IpfsDHT) putLocal(key u.Key, value []byte) error {
rec, err := dht.makePutRecord(key, value)
sk, err := dht.getOwnPrivateKey()
if err != nil {
return err
}
rec, err := MakePutRecord(sk, key, value)
if err != nil {
return err
}
......
......@@ -98,7 +98,13 @@ func TestGetFailures(t *testing.T) {
{
typ := pb.Message_GET_VALUE
str := "hello"
rec, err := d.makePutRecord(u.Key(str), []byte("blah"))
sk, err := d.getOwnPrivateKey()
if err != nil {
t.Fatal(err)
}
rec, err := MakePutRecord(sk, u.Key(str), []byte("blah"))
if err != nil {
t.Fatal(err)
}
......
......@@ -43,20 +43,20 @@ func RecordBlobForSig(r *pb.Record) []byte {
}
// creates and signs a dht record for the given key/value pair
func (dht *IpfsDHT) makePutRecord(key u.Key, value []byte) (*pb.Record, error) {
func MakePutRecord(sk ci.PrivKey, key u.Key, value []byte) (*pb.Record, error) {
record := new(pb.Record)
record.Key = proto.String(string(key))
record.Value = value
record.Author = proto.String(string(dht.self))
blob := RecordBlobForSig(record)
sk := dht.peerstore.PrivKey(dht.self)
if sk == nil {
log.Errorf("%s dht cannot get own private key!", dht.self)
return nil, fmt.Errorf("cannot get private key to sign record!")
pkh, err := sk.GetPublic().Hash()
if err != nil {
return nil, err
}
record.Author = proto.String(string(pkh))
blob := RecordBlobForSig(record)
sig, err := sk.Sign(blob)
if err != nil {
return nil, err
......
......@@ -36,7 +36,12 @@ func (dht *IpfsDHT) PutValue(ctx context.Context, key u.Key, value []byte) error
return err
}
rec, err := dht.makePutRecord(key, value)
sk, err := dht.getOwnPrivateKey()
if err != nil {
return err
}
rec, err := MakePutRecord(sk, key, value)
if err != nil {
log.Error("Creation of record failed!")
return err
......@@ -75,6 +80,8 @@ func (dht *IpfsDHT) GetValue(ctx context.Context, key u.Key) ([]byte, error) {
if err == nil {
log.Debug("have it locally")
return val, nil
} else {
log.Debug("failed to get value locally: %s", err)
}
// get closest peers in the routing table
......
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