When using the HTTP API for IPNS publishing, you have the option to set a ttl
and lifetime
value. Yesterday I was poking around the internals of the IPNS system within go-ipfs
and noticed that there is only one concept of ātime durationā and that is a TTL.
There are functions that can be used to publish records within the namesys
system. Here is the interface
// Publisher is an object capable of publishing particular names.
type Publisher interface {
// Publish establishes a name-value mapping.
// TODO make this not PrivKey specific.
Publish(ctx context.Context, name ci.PrivKey, value path.Path) error
// TODO: to be replaced by a more generic 'PublishWithValidity' type
// call once the records spec is implemented
PublishWithEOL(ctx context.Context, name ci.PrivKey, value path.Path, eol time.Time) error
}
When poking around further, the only difference between Publish
and PublishWithEOL
is that Publish
uses a default EOL value, and feeds that into PublishEOL
func (ns *mpns) PublishWithEOL(ctx context.Context, name ci.PrivKey, value path.Path, eol time.Time) error {
id, err := peer.IDFromPrivateKey(name)
if err != nil {
return err
}
if err := ns.ipnsPublisher.PublishWithEOL(ctx, name, value, eol); err != nil {
return err
}
ttl := DefaultResolverCacheTTL
if ttEol := eol.Sub(time.Now()); ttEol < ttl {
ttl = ttEol
}
ns.cacheSet(peer.IDB58Encode(id), value, ttl)
return nil
}
Publish
looks like the following
// Publish implements Publisher
func (ns *mpns) Publish(ctx context.Context, name ci.PrivKey, value path.Path) error {
return ns.PublishWithEOL(ctx, name, value, time.Now().Add(DefaultRecordTTL))
}
where DefaultRecordTTL
is const DefaultRecordTTL = 24 * time.Hour
From what I can gather, there is no lifetime
value anywhere, and instead the only time expiration value is TTL
.
So my question(s):
- What is the difference between
ttl
andlifetime
- Why does the namesys system not have 2 time expiration values, like the API which has concepts of
ttl
andlifetime