mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-09 19:32:24 +08:00
cache ipns entries to speed things up a little
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
@ -121,6 +121,19 @@ func (p *ipnsPublisher) getPreviousSeqNo(ctx context.Context, ipnskey key.Key) (
|
||||
return e.GetSequence(), nil
|
||||
}
|
||||
|
||||
// setting the TTL on published records is an experimental feature.
|
||||
// as such, i'm using the context to wire it through to avoid changing too
|
||||
// much code along the way.
|
||||
func checkCtxTTL(ctx context.Context) (time.Duration, bool) {
|
||||
v := ctx.Value("ipns-publish-ttl")
|
||||
if v == nil {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
d, ok := v.(time.Duration)
|
||||
return d, ok
|
||||
}
|
||||
|
||||
func PutRecordToRouting(ctx context.Context, k ci.PrivKey, value path.Path, seqnum uint64, eol time.Time, r routing.IpfsRouting, id peer.ID) error {
|
||||
namekey, ipnskey := IpnsKeysForID(id)
|
||||
entry, err := CreateRoutingEntryData(k, value, seqnum, eol)
|
||||
@ -128,6 +141,11 @@ func PutRecordToRouting(ctx context.Context, k ci.PrivKey, value path.Path, seqn
|
||||
return err
|
||||
}
|
||||
|
||||
ttl, ok := checkCtxTTL(ctx)
|
||||
if ok {
|
||||
entry.Ttl = proto.Uint64(uint64(ttl.Nanoseconds()))
|
||||
}
|
||||
|
||||
err = PublishEntry(ctx, r, ipnskey, entry)
|
||||
if err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user