interface.go 3.11 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*
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
*/
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

Dirk McCormick's avatar
Dirk McCormick committed
38
	opts "github.com/ipfs/go-ipfs/namesys/opts"
Steven Allen's avatar
Steven Allen committed
39
	path "gx/ipfs/QmPqCBrmkm7jNfYi7xFS7mUZsrN6DEumBMrxLnL7axNJx1/go-path"
Łukasz Magiera's avatar
Łukasz Magiera committed
40

Steven Allen's avatar
Steven Allen committed
41
	ci "gx/ipfs/QmPvyPwuCgJ7pDmrKDxRtsScJgBaM5h4EpRL2qQJsmXf4n/go-libp2p-crypto"
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
42 43 44
)

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

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

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

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

// Resolver is an object capable of resolving names.
type Resolver interface {

69 70 71 72 73 74 75 76 77 78 79 80 81
	// 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
82
	// adjust the limit you can specify it as an option.
Dirk McCormick's avatar
Dirk McCormick committed
83
	Resolve(ctx context.Context, name string, options ...opts.ResolveOpt) (value path.Path, err error)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
84 85 86 87 88 89 90
}

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

	// Publish establishes a name-value mapping.
	// TODO make this not PrivKey specific.
91
	Publish(ctx context.Context, name ci.PrivKey, value path.Path) error
92 93 94 95

	// 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
96
}