interface.go 3.49 KB
Newer Older
1
/*
tavit ohanian's avatar
tavit ohanian committed
2 3
Package namesys implements resolvers and publishers for the DMS3
naming system (DMS3NS).
4

tavit ohanian's avatar
tavit ohanian committed
5
The core of DMS3 is an immutable, content-addressable Merkle graph.
6 7 8 9 10
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
tavit ohanian's avatar
tavit ohanian committed
11
  /dms3/Qmcqtw8FfrVSBaRmbWwHxt3AuySBhJLcvmFYi3Lbc4xnwj
12 13 14 15 16 17

or:

  The current homepage for node
  QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
  is
tavit ohanian's avatar
tavit ohanian committed
18
  /dms3/Qmcqtw8FfrVSBaRmbWwHxt3AuySBhJLcvmFYi3Lbc4xnwj
19 20

The mutable name system also allows users to resolve those references
tavit ohanian's avatar
tavit ohanian committed
21
to find the immutable DMS3 object currently referenced by a given
22 23 24 25
mutable name.

For command-line bindings to this functionality, see:

tavit ohanian's avatar
tavit ohanian committed
26 27 28
  dms3 name
  dms3 dns
  dms3 resolve
29
*/
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
30 31 32 33
package namesys

import (
	"errors"
34
	"time"
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
35

36
	context "context"
Jan Winkelmann's avatar
Jan Winkelmann committed
37

tavit ohanian's avatar
tavit ohanian committed
38 39 40
	path "gitlab.dms3.io/dms3/go-path"
	opts "gitlab.dms3.io/dms3/interface-go-dms3-core/options/namesys"
	ci "gitlab.dms3.io/p2p/go-p2p-core/crypto"
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
41 42 43
)

// ErrResolveFailed signals an error when attempting to resolve.
Łukasz Magiera's avatar
Łukasz Magiera committed
44
var ErrResolveFailed = errors.New("could not resolve name")
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
45

46 47
// ErrResolveRecursion signals a recursion-depth limit.
var ErrResolveRecursion = errors.New(
Łukasz Magiera's avatar
Łukasz Magiera committed
48
	"could not resolve name (recursion limit exceeded)")
49

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
50
// ErrPublishFailed signals an error when attempting to publish.
Łukasz Magiera's avatar
Łukasz Magiera committed
51
var ErrPublishFailed = errors.New("could not publish name")
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
52 53 54 55 56 57 58 59 60 61 62 63 64

// 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).
type NameSystem interface {
	Resolver
	Publisher
}

65 66
// Result is the return type for Resolver.ResolveAsync.
type Result struct {
Łukasz Magiera's avatar
Łukasz Magiera committed
67 68
	Path path.Path
	Err  error
69 70
}

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
71 72 73
// Resolver is an object capable of resolving names.
type Resolver interface {

74
	// Resolve performs a recursive lookup, returning the dereferenced
tavit ohanian's avatar
tavit ohanian committed
75 76 77
	// path.  For example, if dms3.io has a DNS TXT record pointing to
	//   /dms3ns/QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
	// and there is a DHT DMS3NS entry for
78
	//   QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
tavit ohanian's avatar
tavit ohanian committed
79
	//   -> /dms3/Qmcqtw8FfrVSBaRmbWwHxt3AuySBhJLcvmFYi3Lbc4xnwj
80
	// then
tavit ohanian's avatar
tavit ohanian committed
81
	//   Resolve(ctx, "/dms3ns/dms3.io")
82
	// will resolve both names, returning
tavit ohanian's avatar
tavit ohanian committed
83
	//   /dms3/Qmcqtw8FfrVSBaRmbWwHxt3AuySBhJLcvmFYi3Lbc4xnwj
84 85 86
	//
	// There is a default depth-limit to avoid infinite recursion.  Most
	// users will be fine with this default limit, but if you need to
87
	// adjust the limit you can specify it as an option.
Dirk McCormick's avatar
Dirk McCormick committed
88
	Resolve(ctx context.Context, name string, options ...opts.ResolveOpt) (value path.Path, err error)
89 90 91 92 93

	// 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
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
94 95 96 97 98 99 100
}

// Publisher is an object capable of publishing particular names.
type Publisher interface {

	// Publish establishes a name-value mapping.
	// TODO make this not PrivKey specific.
101
	Publish(ctx context.Context, name ci.PrivKey, value path.Path) error
102 103 104 105

	// 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
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
106
}