mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-10 09:52:20 +08:00
put pubkey and ipns entry to dht in parallel
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
@ -146,12 +146,22 @@ func PutRecordToRouting(ctx context.Context, k ci.PrivKey, value path.Path, seqn
|
|||||||
entry.Ttl = proto.Uint64(uint64(ttl.Nanoseconds()))
|
entry.Ttl = proto.Uint64(uint64(ttl.Nanoseconds()))
|
||||||
}
|
}
|
||||||
|
|
||||||
err = PublishEntry(ctx, r, ipnskey, entry)
|
errs := make(chan error)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
errs <- PublishEntry(ctx, r, ipnskey, entry)
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
errs <- PublishPublicKey(ctx, r, namekey, k.GetPublic())
|
||||||
|
}()
|
||||||
|
|
||||||
|
err = waitOnErrChan(ctx, errs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = PublishPublicKey(ctx, r, namekey, k.GetPublic())
|
err = waitOnErrChan(ctx, errs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -159,6 +169,19 @@ func PutRecordToRouting(ctx context.Context, k ci.PrivKey, value path.Path, seqn
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func waitOnErrChan(ctx context.Context, errs chan error) error {
|
||||||
|
select {
|
||||||
|
case err := <-errs:
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case <-ctx.Done():
|
||||||
|
return ctx.Err()
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func PublishPublicKey(ctx context.Context, r routing.IpfsRouting, k key.Key, pubk ci.PubKey) error {
|
func PublishPublicKey(ctx context.Context, r routing.IpfsRouting, k key.Key, pubk ci.PubKey) error {
|
||||||
log.Debugf("Storing pubkey at: %s", k)
|
log.Debugf("Storing pubkey at: %s", k)
|
||||||
pkbytes, err := pubk.Bytes()
|
pkbytes, err := pubk.Bytes()
|
||||||
|
Reference in New Issue
Block a user