mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-29 09:34:03 +08:00
some comments
This commit is contained in:
@ -355,6 +355,9 @@ func (n *IpfsNode) loadPrivateKey() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetupOfflineRouting loads the local nodes private key and
|
||||||
|
// uses it to instantiate a routing system in offline mode.
|
||||||
|
// This is primarily used for offline ipns modifications.
|
||||||
func (n *IpfsNode) SetupOfflineRouting() error {
|
func (n *IpfsNode) SetupOfflineRouting() error {
|
||||||
err := n.loadPrivateKey()
|
err := n.loadPrivateKey()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -33,6 +33,8 @@ var (
|
|||||||
longRepublishTimeout = time.Millisecond * 500
|
longRepublishTimeout = time.Millisecond * 500
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// InitializeKeyspace sets the ipns record for the given key to
|
||||||
|
// point to an empty directory.
|
||||||
func InitializeKeyspace(n *core.IpfsNode, key ci.PrivKey) error {
|
func InitializeKeyspace(n *core.IpfsNode, key ci.PrivKey) error {
|
||||||
emptyDir := &mdag.Node{Data: ft.FolderPBData()}
|
emptyDir := &mdag.Node{Data: ft.FolderPBData()}
|
||||||
k, err := n.DAG.Add(emptyDir)
|
k, err := n.DAG.Add(emptyDir)
|
||||||
|
@ -235,6 +235,8 @@ func (dht *IpfsDHT) getLocal(key u.Key) ([]byte, error) {
|
|||||||
return rec.GetValue(), nil
|
return rec.GetValue(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getOwnPrivateKey attempts to load the local peers private
|
||||||
|
// key from the peerstore.
|
||||||
func (dht *IpfsDHT) getOwnPrivateKey() (ci.PrivKey, error) {
|
func (dht *IpfsDHT) getOwnPrivateKey() (ci.PrivKey, error) {
|
||||||
sk := dht.peerstore.PrivKey(dht.self)
|
sk := dht.peerstore.PrivKey(dht.self)
|
||||||
if sk == nil {
|
if sk == nil {
|
||||||
|
@ -42,7 +42,7 @@ func RecordBlobForSig(r *pb.Record) []byte {
|
|||||||
return bytes.Join([][]byte{k, v, a}, []byte{})
|
return bytes.Join([][]byte{k, v, a}, []byte{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// creates and signs a dht record for the given key/value pair
|
// MakePutRecord creates and signs a dht record for the given key/value pair
|
||||||
func MakePutRecord(sk ci.PrivKey, 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 := new(pb.Record)
|
||||||
|
|
||||||
@ -175,6 +175,8 @@ func (dht *IpfsDHT) verifyRecordOnline(ctx context.Context, r *pb.Record) error
|
|||||||
return dht.verifyRecord(r, pk)
|
return dht.verifyRecord(r, pk)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: make this an independent exported function.
|
||||||
|
// it might be useful for users to have access to.
|
||||||
func (dht *IpfsDHT) verifyRecord(r *pb.Record, pk ci.PubKey) error {
|
func (dht *IpfsDHT) verifyRecord(r *pb.Record, pk ci.PubKey) error {
|
||||||
// First, validate the signature
|
// First, validate the signature
|
||||||
blob := RecordBlobForSig(r)
|
blob := RecordBlobForSig(r)
|
||||||
|
@ -27,6 +27,9 @@ func NewOfflineRouter(dstore ds.Datastore, privkey ci.PrivKey) routing.IpfsRouti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// offlineRouting implements the IpfsRouting interface,
|
||||||
|
// but only provides the capability to Put and Get signed dht
|
||||||
|
// records to and from the local datastore.
|
||||||
type offlineRouting struct {
|
type offlineRouting struct {
|
||||||
datastore ds.Datastore
|
datastore ds.Datastore
|
||||||
sk ci.PrivKey
|
sk ci.PrivKey
|
||||||
@ -86,4 +89,5 @@ func (c *offlineRouting) Ping(ctx context.Context, p peer.ID) (time.Duration, er
|
|||||||
return 0, ErrOffline
|
return 0, ErrOffline
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ensure offlineRouting matches the IpfsRouting interface
|
||||||
var _ routing.IpfsRouting = &offlineRouting{}
|
var _ routing.IpfsRouting = &offlineRouting{}
|
||||||
|
Reference in New Issue
Block a user