namesys

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2021 License: Apache-2.0, MIT, Apache-2.0, + 1 more Imports: 28 Imported by: 0

Documentation

Overview

Package namesys implements resolvers and publishers for the DMS3 naming system (DMS3NS).

The core of DMS3 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
/dms3/Qmcqtw8FfrVSBaRmbWwHxt3AuySBhJLcvmFYi3Lbc4xnwj

or:

The current homepage for node
QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
is
/dms3/Qmcqtw8FfrVSBaRmbWwHxt3AuySBhJLcvmFYi3Lbc4xnwj

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

For command-line bindings to this functionality, see:

dms3 name
dms3 dns
dms3 resolve

Index

Constants

View Source
const DefaultRecordEOL = 24 * time.Hour
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 Dms3NsDsKey

func Dms3NsDsKey(id peer.ID) ds.Key

func InitializeKeyspace

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

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

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, dms3nskey string, rec *pb.Dms3NsEntry) error

func PublishPublicKey

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

func PutRecordToRouting

func PutRecordToRouting(ctx context.Context, r routing.ValueStore, k ci.PubKey, entry *pb.Dms3NsEntry) error

Types

type DNSResolver

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

DNSResolver implements a Resolver on DNS domains

func NewDNSResolver

func NewDNSResolver() *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 Dms3NsPublisher

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

Dms3NsPublisher is capable of publishing and resolving names to the DMS3 routing system.

func NewDms3NsPublisher

func NewDms3NsPublisher(route routing.ValueStore, ds ds.Datastore) *Dms3NsPublisher

NewDms3NsPublisher constructs a publisher for the DMS3 Routing name system.

func (*Dms3NsPublisher) GetPublished

func (p *Dms3NsPublisher) GetPublished(ctx context.Context, id peer.ID, checkRouting bool) (*pb.Dms3NsEntry, 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 (*Dms3NsPublisher) ListPublished

func (p *Dms3NsPublisher) ListPublished(ctx context.Context) (map[peer.ID]*pb.Dms3NsEntry, error)

PublishedNames returns the latest DMS3NS records published by this node and their expiration times.

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

func (*Dms3NsPublisher) Publish

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

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

func (*Dms3NsPublisher) PublishWithEOL

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

PublishWithEOL is a temporary stand in for the dms3ns records implementation see here for more details: https://gitlab.dms3.io/dms3/specs/tree/master/records

type Dms3NsResolver

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

Dms3NsResolver implements NSResolver for the main DMS3 SFS-like naming

func NewDms3NsResolver

func NewDms3NsResolver(route routing.ValueStore) *Dms3NsResolver

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

func (*Dms3NsResolver) Resolve

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

Resolve implements Resolver.

func (*Dms3NsResolver) ResolveAsync

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

ResolveAsync implements Resolver.

type LookupTXTFunc

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

type NameSystem

type NameSystem interface {
	Resolver
	Publisher
}

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 DMS3 naming system based on Routing

type ProquintResolver

type ProquintResolver struct{}

func (*ProquintResolver) Resolve

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

Resolve 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 Resolver

type Resolver interface {

	// Resolve performs a recursive lookup, returning the dereferenced
	// path.  For example, if dms3.io has a DNS TXT record pointing to
	//   /dms3ns/QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
	// and there is a DHT DMS3NS entry for
	//   QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
	//   -> /dms3/Qmcqtw8FfrVSBaRmbWwHxt3AuySBhJLcvmFYi3Lbc4xnwj
	// then
	//   Resolve(ctx, "/dms3ns/dms3.io")
	// will resolve both names, returning
	//   /dms3/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

Jump to

Keyboard shortcuts

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