some comments
Jeromy committed
Jan 16, 2015 at 23:53 UTC
a5233faeae5e86241e435a5753a53816a766d733
5 files changed
+14
-1
core/core.go
+3
@@ -355,6 +355,9 @@ func (n *IpfsNode) loadPrivateKey() error {
355
return nil
356
}
357
358
+// SetupOfflineRouting loads the local nodes private key and
359
+// uses it to instantiate a routing system in offline mode.
360
+// This is primarily used for offline ipns modifications.
361
func (n *IpfsNode) SetupOfflineRouting() error {
362
err := n.loadPrivateKey()
363
if err != nil {
fuse/ipns/ipns_unix.go
+2
@@ -33,6 +33,8 @@ var (
33
longRepublishTimeout = time.Millisecond * 500
34
)
35
36
+// InitializeKeyspace sets the ipns record for the given key to
37
+// point to an empty directory.
38
func InitializeKeyspace(n *core.IpfsNode, key ci.PrivKey) error {
39
emptyDir := &mdag.Node{Data: ft.FolderPBData()}
40
k, err := n.DAG.Add(emptyDir)
routing/dht/dht.go
+2
@@ -235,6 +235,8 @@ func (dht *IpfsDHT) getLocal(key u.Key) ([]byte, error) {
235
return rec.GetValue(), nil
236
}
237
238
+// getOwnPrivateKey attempts to load the local peers private
239
+// key from the peerstore.
240
func (dht *IpfsDHT) getOwnPrivateKey() (ci.PrivKey, error) {
241
sk := dht.peerstore.PrivKey(dht.self)
242
if sk == nil {
routing/dht/records.go
+3
-1
@@ -42,7 +42,7 @@ func RecordBlobForSig(r *pb.Record) []byte {
42
return bytes.Join([][]byte{k, v, a}, []byte{})
43
}
44
45
-// creates and signs a dht record for the given key/value pair
45
+// MakePutRecord creates and signs a dht record for the given key/value pair
46
func MakePutRecord(sk ci.PrivKey, key u.Key, value []byte) (*pb.Record, error) {
47
record := new(pb.Record)
48
@@ -175,6 +175,8 @@ func (dht *IpfsDHT) verifyRecordOnline(ctx context.Context, r *pb.Record) error
175
return dht.verifyRecord(r, pk)
176
}
177
178
+// TODO: make this an independent exported function.
179
+// it might be useful for users to have access to.
180
func (dht *IpfsDHT) verifyRecord(r *pb.Record, pk ci.PubKey) error {
181
// First, validate the signature
182
blob := RecordBlobForSig(r)
routing/offline/offline.go
+4
@@ -27,6 +27,9 @@ func NewOfflineRouter(dstore ds.Datastore, privkey ci.PrivKey) routing.IpfsRouti
27
}
28
}
29
30
+// offlineRouting implements the IpfsRouting interface,
31
+// but only provides the capability to Put and Get signed dht
32
+// records to and from the local datastore.
33
type offlineRouting struct {
34
datastore ds.Datastore
35
sk ci.PrivKey
@@ -86,4 +89,5 @@ func (c *offlineRouting) Ping(ctx context.Context, p peer.ID) (time.Duration, er
89
return 0, ErrOffline
90
}
91
92
+// ensure offlineRouting matches the IpfsRouting interface
93
var _ routing.IpfsRouting = &offlineRouting{}