namesys

package
v0.13.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2023 License: Apache-2.0, MIT Imports: 28 Imported by: 35

Documentation

Overview

Package namesys implements resolvers and publishers for the IPFS naming system (IPNS).

The core of IPFS is an immutable, content-addressable Merkle graph. That works well for many use cases, but doesn't allow you to answer questions like "what is Alice's current homepage?". The mutable name system allows Alice to publish information like:

The current homepage for alice.example.com is
/ipfs/Qmcqtw8FfrVSBaRmbWwHxt3AuySBhJLcvmFYi3Lbc4xnwj

or:

The current homepage for node
QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
is
/ipfs/Qmcqtw8FfrVSBaRmbWwHxt3AuySBhJLcvmFYi3Lbc4xnwj

The mutable name system also allows users to resolve those references to find the immutable IPFS object currently referenced by a given mutable name.

For command-line bindings to this functionality, see:

ipfs name
ipfs dns
ipfs resolve

Package namesys defines Resolver and Publisher interfaces for IPNS paths, that is, IPFS paths in the form of /ipns/<name_to_be_resolved>. A "resolved" IPNS path becomes an /ipfs/<cid> path.

Traditionally, these paths would be in the form of /ipns/peer_id, which references an IPNS record in a distributed ValueStore (usually the IPFS DHT).

Additionally, the /ipns/ namespace can also be used with domain names that use DNSLink (/ipns/<dnslink_name>, https://docs.ipfs.io/concepts/dnslink/)

The package provides implementations for all three resolvers.

Index

Constants

View Source
const DefaultResolverCacheTTL = time.Minute

DefaultResolverCacheTTL defines max ttl of a record placed in namesys cache.

Variables

View Source
var ErrPublishFailed = errors.New("could not publish name")

ErrPublishFailed signals an error when attempting to publish.

View Source
var ErrResolveFailed = errors.New("could not resolve name")

ErrResolveFailed signals an error when attempting to resolve.

View Source
var ErrResolveRecursion = errors.New(
	"could not resolve name (recursion limit exceeded)")

ErrResolveRecursion signals a recursion-depth limit.

Functions

func IpnsDsKey

func IpnsDsKey(id peer.ID) ds.Key

IpnsDsKey returns a datastore key given an IPNS identifier (peer ID). Defines the storage key for IPNS records in the local datastore.

func PkKeyForID

func PkKeyForID(id peer.ID) string

PkKeyForID returns the public key routing key for the given peer ID.

func PublishEntry

func PublishEntry(ctx context.Context, r routing.ValueStore, ipnskey string, rec *ipns.Record) error

PublishEntry stores the given IpnsEntry in the ValueStore with the given ipnskey.

func PublishPublicKey

func PublishPublicKey(ctx context.Context, r routing.ValueStore, k string, pubk crypto.PubKey) error

PublishPublicKey stores the given public key in the ValueStore with the given key.

func PutRecordToRouting

func PutRecordToRouting(ctx context.Context, r routing.ValueStore, k crypto.PubKey, rec *ipns.Record) error

PutRecordToRouting publishes the given entry using the provided ValueStore, keyed on the ID associated with the provided public key. The public key is also made available to the routing system so that entries can be verified.

func StartSpan

func StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)

Types

type DNSResolver

type DNSResolver struct {
	// contains filtered or unexported fields
}

DNSResolver implements a Resolver on DNS domains

func NewDNSResolver

func NewDNSResolver(lookup LookupTXTFunc) *DNSResolver

NewDNSResolver constructs a name resolver using DNS TXT records.

func (*DNSResolver) Resolve

func (r *DNSResolver) Resolve(ctx context.Context, name string, options ...opts.ResolveOpt) (path.Path, error)

Resolve implements Resolver.

func (*DNSResolver) ResolveAsync

func (r *DNSResolver) ResolveAsync(ctx context.Context, name string, options ...opts.ResolveOpt) <-chan Result

ResolveAsync implements Resolver.

type IpnsPublisher

type IpnsPublisher struct {
	// contains filtered or unexported fields
}

IpnsPublisher is capable of publishing and resolving names to the IPFS routing system.

func NewIpnsPublisher

func NewIpnsPublisher(route routing.ValueStore, ds ds.Datastore) *IpnsPublisher

NewIpnsPublisher constructs a publisher for the IPFS Routing name system.

func (*IpnsPublisher) GetPublished

func (p *IpnsPublisher) GetPublished(ctx context.Context, id peer.ID, checkRouting bool) (*ipns.Record, error)

GetPublished returns the record this node has published corresponding to the given peer ID.

If `checkRouting` is true and we have no existing record, this method will check the routing system for any existing records.

func (*IpnsPublisher) ListPublished

func (p *IpnsPublisher) ListPublished(ctx context.Context) (map[peer.ID]*ipns.Record, error)

ListPublished returns the latest IPNS records published by this node and their expiration times.

This method will not search the routing system for records published by other nodes.

func (*IpnsPublisher) Publish

func (p *IpnsPublisher) Publish(ctx context.Context, k crypto.PrivKey, value path.Path, options ...opts.PublishOption) error

Publish implements Publisher. Accepts a keypair and a value, and publishes it out to the routing system

type IpnsResolver

type IpnsResolver struct {
	// contains filtered or unexported fields
}

IpnsResolver implements NSResolver for the main IPFS SFS-like naming

func NewIpnsResolver

func NewIpnsResolver(route routing.ValueStore) *IpnsResolver

NewIpnsResolver constructs a name resolver using the IPFS Routing system to implement SFS-like naming on top.

func (*IpnsResolver) Resolve

func (r *IpnsResolver) Resolve(ctx context.Context, name string, options ...opts.ResolveOpt) (path.Path, error)

Resolve implements Resolver.

func (*IpnsResolver) ResolveAsync

func (r *IpnsResolver) ResolveAsync(ctx context.Context, name string, options ...opts.ResolveOpt) <-chan Result

ResolveAsync implements Resolver.

type LookupTXTFunc

type LookupTXTFunc func(ctx context.Context, name string) (txt []string, err error)

LookupTXTFunc is a function that lookups TXT record values.

type NameSystem

type NameSystem interface {
	Resolver
	Publisher
}

NameSystem represents a cohesive name publishing and resolving system.

Publishing a name is the process of establishing a mapping, a key-value pair, according to naming rules and databases.

Resolving a name is the process of looking up the value associated with the key (name).

func NewNameSystem

func NewNameSystem(r routing.ValueStore, opts ...Option) (NameSystem, error)

NewNameSystem will construct the IPFS naming system based on Routing

type Option

type Option func(*mpns) error

func WithCache

func WithCache(size int) Option

WithCache is an option that instructs the name system to use a (LRU) cache of the given size.

func WithDNSResolver

func WithDNSResolver(rslv madns.BasicResolver) Option

WithDNSResolver is an option that supplies a custom DNS resolver to use instead of the system default.

func WithDatastore

func WithDatastore(ds ds.Datastore) Option

WithDatastore is an option that supplies a datastore to use instead of an in-memory map datastore. The datastore is used to store published IPNS records and make them available for querying.

type Publisher

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, options ...opts.PublishOption) error
}

Publisher is an object capable of publishing particular names.

type Resolver

type Resolver interface {
	// Resolve performs a recursive lookup, returning the dereferenced
	// path.  For example, if ipfs.io has a DNS TXT record pointing to
	//   /ipns/QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
	// and there is a DHT IPNS entry for
	//   QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
	//   -> /ipfs/Qmcqtw8FfrVSBaRmbWwHxt3AuySBhJLcvmFYi3Lbc4xnwj
	// then
	//   Resolve(ctx, "/ipns/ipfs.io")
	// will resolve both names, returning
	//   /ipfs/Qmcqtw8FfrVSBaRmbWwHxt3AuySBhJLcvmFYi3Lbc4xnwj
	//
	// There is a default depth-limit to avoid infinite recursion.  Most
	// users will be fine with this default limit, but if you need to
	// adjust the limit you can specify it as an option.
	Resolve(ctx context.Context, name string, options ...opts.ResolveOpt) (value path.Path, err error)

	// ResolveAsync performs recursive name lookup, like Resolve, but it returns
	// entries as they are discovered in the DHT. Each returned result is guaranteed
	// to be "better" (which usually means newer) than the previous one.
	ResolveAsync(ctx context.Context, name string, options ...opts.ResolveOpt) <-chan Result
}

Resolver is an object capable of resolving names.

type Result

type Result struct {
	Path path.Path
	Err  error
}

Result is the return type for Resolver.ResolveAsync.

Directories

Path Synopsis
Package republisher provides a utility to automatically re-publish IPNS records related to the keys in a Keystore.
Package republisher provides a utility to automatically re-publish IPNS records related to the keys in a Keystore.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL