namesys

package
v0.4.14-rc1 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2018 License: MIT Imports: 31 Imported by: 0

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

Index

Constants

View Source
const (
	// DefaultDepthLimit is the default depth limit used by Resolve.
	DefaultDepthLimit = 32

	// UnlimitedDepth allows infinite recursion in ResolveN.  You
	// probably don't want to use this, but it's here if you absolutely
	// trust resolution to eventually complete and can't put an upper
	// limit on how many steps it will take.
	UnlimitedDepth = 0
)
View Source
const DefaultRecordTTL = 24 * time.Hour
View Source
const DefaultResolverCacheTTL = time.Minute
View Source
const PublishPutValTimeout = time.Minute

Variables

View Source
var ErrBadRecord = errors.New("record could not be unmarshalled")

ErrBadRecord should be returned when an ipns record cannot be unmarshalled

View Source
var ErrExpiredRecord = errors.New("expired record")

ErrExpiredRecord should be returned when an ipns record is invalid due to being too old

View Source
var ErrInvalidPath = errors.New("record path invalid")

ErrInvalidPath should be returned when an ipns record path is not in a valid format

View Source
var ErrKeyFormat = errors.New("record key could not be parsed into peer ID")

ErrKeyFormat should be returned when an ipns record key is incorrectly formatted (not a peer ID)

View Source
var ErrPublicKeyNotFound = errors.New("public key not found in peer store")

ErrPublicKeyNotFound should be returned when the public key corresponding to the ipns record path cannot be retrieved from the peer store

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.

View Source
var ErrSignature = errors.New("record signature verification failed")

ErrSignature should be returned when an ipns record fails signature verification

View Source
var ErrUnrecognizedValidity = errors.New("unrecognized validity type")

ErrUnrecognizedValidity is returned when an IpnsRecord has an unknown validity type.

Functions

func AddPubsubNameSystem added in v0.4.14

func AddPubsubNameSystem(ctx context.Context, ns NameSystem, host p2phost.Host, r routing.IpfsRouting, ds ds.Datastore, ps *floodsub.PubSub) error

AddPubsubNameSystem adds the pubsub publisher and resolver to the namesystem

func CreateRoutingEntryData added in v0.3.8

func CreateRoutingEntryData(pk ci.PrivKey, val path.Path, seq uint64, eol time.Time) (*pb.IpnsEntry, error)

func InitializeKeyspace added in v0.3.2

func InitializeKeyspace(ctx context.Context, pub Publisher, pins pin.Pinner, key ci.PrivKey) error

InitializeKeyspace sets the ipns record for the given key to point to an empty directory. TODO: this doesnt feel like it belongs here

func IpnsKeysForID added in v0.3.8

func IpnsKeysForID(id peer.ID) (name, ipns string)

func IpnsSelectorFunc added in v0.3.8

func IpnsSelectorFunc(k string, vals [][]byte) (int, error)

IpnsSelectorFunc selects the best record by checking which has the highest sequence number and latest EOL

func NewIpnsRecordValidator added in v0.4.14

func NewIpnsRecordValidator(kbook pstore.KeyBook) *record.ValidChecker

NewIpnsRecordValidator returns a ValidChecker for IPNS records. The validator function will get a public key from the KeyBook to verify the record's signature. Note that the public key must already have been fetched from the network and put into the KeyBook by the caller.

func NewRoutingPublisher

func NewRoutingPublisher(route routing.ValueStore, ds ds.Datastore) *ipnsPublisher

NewRoutingPublisher constructs a publisher for the IPFS Routing name system.

func NewRoutingResolver

func NewRoutingResolver(route routing.ValueStore, cachesize int) *routingResolver

NewRoutingResolver constructs a name resolver using the IPFS Routing system to implement SFS-like naming on top. cachesize is the limit of the number of entries in the lru cache. Setting it to '0' will disable caching.

func PublishEntry added in v0.3.8

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

func PublishPublicKey added in v0.3.8

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

func PutRecordToRouting added in v0.3.8

func PutRecordToRouting(ctx context.Context, k ci.PrivKey, value path.Path, seqnum uint64, eol time.Time, r routing.ValueStore, id peer.ID) error

Types

type DNSResolver

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

DNSResolver implements a Resolver on DNS domains

func (*DNSResolver) Resolve

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

Resolve implements Resolver.

func (*DNSResolver) ResolveN added in v0.3.5

func (r *DNSResolver) ResolveN(ctx context.Context, name string, depth int) (path.Path, error)

ResolveN implements Resolver.

type LookupTXTFunc added in v0.3.5

type LookupTXTFunc func(name string) (txt []string, err error)

type NameSystem

type NameSystem interface {
	Resolver
	Publisher
	ResolverLookup
}

Namesys 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, ds ds.Datastore, cachesize int) NameSystem

NewNameSystem will construct the IPFS naming system based on Routing

type ProquintResolver

type ProquintResolver struct{}

func (*ProquintResolver) Resolve

func (r *ProquintResolver) Resolve(ctx context.Context, name string) (path.Path, error)

Resolve implements Resolver.

func (*ProquintResolver) ResolveN added in v0.3.5

func (r *ProquintResolver) ResolveN(ctx context.Context, name string, depth int) (path.Path, error)

ResolveN implements Resolver.

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) 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
}

Publisher is an object capable of publishing particular names.

type PubsubPublisher added in v0.4.14

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

PubsubPublisher is a publisher that distributes IPNS records through pubsub

func NewPubsubPublisher added in v0.4.14

func NewPubsubPublisher(ctx context.Context, host p2phost.Host, ds ds.Datastore, cr routing.ContentRouting, ps *floodsub.PubSub) *PubsubPublisher

NewPubsubPublisher constructs a new Publisher that publishes IPNS records through pubsub. The constructor interface is complicated by the need to bootstrap the pubsub topic. This could be greatly simplified if the pubsub implementation handled bootstrap itself

func (*PubsubPublisher) Publish added in v0.4.14

func (p *PubsubPublisher) Publish(ctx context.Context, k ci.PrivKey, value path.Path) error

Publish publishes an IPNS record through pubsub with default TTL

func (*PubsubPublisher) PublishWithEOL added in v0.4.14

func (p *PubsubPublisher) PublishWithEOL(ctx context.Context, k ci.PrivKey, value path.Path, eol time.Time) error

PublishWithEOL publishes an IPNS record through pubsub

type PubsubResolver added in v0.4.14

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

PubsubResolver is a resolver that receives IPNS records through pubsub

func NewPubsubResolver added in v0.4.14

NewPubsubResolver constructs a new Resolver that resolves IPNS records through pubsub. same as above for pubsub bootstrap dependencies

func (*PubsubResolver) Cancel added in v0.4.14

func (r *PubsubResolver) Cancel(name string) bool

Cancel cancels a topic subscription; returns true if an active subscription was canceled

func (*PubsubResolver) GetSubscriptions added in v0.4.14

func (r *PubsubResolver) GetSubscriptions() []string

GetSubscriptions retrieves a list of active topic subscriptions

func (*PubsubResolver) Resolve added in v0.4.14

func (r *PubsubResolver) Resolve(ctx context.Context, name string) (path.Path, error)

Resolve resolves a name through pubsub and default depth limit

func (*PubsubResolver) ResolveN added in v0.4.14

func (r *PubsubResolver) ResolveN(ctx context.Context, name string, depth int) (path.Path, error)

ResolveN resolves a name through pubsub with the specified depth limit

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 use ResolveN.
	Resolve(ctx context.Context, name string) (value path.Path, err error)

	// ResolveN performs a recursive lookup, returning the dereferenced
	// path.  The only difference from Resolve is that the depth limit
	// is configurable.  You can use DefaultDepthLimit, UnlimitedDepth,
	// or a depth limit of your own choosing.
	//
	// Most users should use Resolve, since the default limit works well
	// in most real-world situations.
	ResolveN(ctx context.Context, name string, depth int) (value path.Path, err error)
}

Resolver is an object capable of resolving names.

func NewDNSResolver added in v0.3.5

func NewDNSResolver() Resolver

NewDNSResolver constructs a name resolver using DNS TXT records.

type ResolverLookup added in v0.4.14

type ResolverLookup interface {

	// GetResolver retrieves a resolver associated with a subsystem
	GetResolver(subs string) (Resolver, bool)
}

ResolverLookup is an object capable of finding resolvers for a subsystem

Directories

Path Synopsis
Package namesys_pb is a generated protocol buffer package.
Package namesys_pb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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