name.go 1.49 KB
Newer Older
1 2 3 4
package iface

import (
	"context"
5
	"errors"
Łukasz Magiera's avatar
Łukasz Magiera committed
6
	path "github.com/ipfs/interface-go-ipfs-core/path"
7

Łukasz Magiera's avatar
Łukasz Magiera committed
8
	"github.com/ipfs/interface-go-ipfs-core/options"
9 10
)

11 12
var ErrResolveFailed = errors.New("could not resolve name")

13 14 15 16 17
// IpnsEntry specifies the interface to IpnsEntries
type IpnsEntry interface {
	// Name returns IpnsEntry name
	Name() string
	// Value returns IpnsEntry value
Łukasz Magiera's avatar
Łukasz Magiera committed
18
	Value() path.Path
19 20
}

21
type IpnsResult struct {
Łukasz Magiera's avatar
Łukasz Magiera committed
22
	path.Path
23 24 25
	Err error
}

26 27 28 29 30 31 32 33 34 35
// NameAPI specifies the interface to IPNS.
//
// IPNS is a PKI namespace, where names are the hashes of public keys, and the
// private key enables publishing new (signed) values. In both publish and
// resolve, the default name used is the node's own PeerID, which is the hash of
// its public key.
//
// You can use .Key API to list and generate more names and their respective keys.
type NameAPI interface {
	// Publish announces new IPNS name
Łukasz Magiera's avatar
Łukasz Magiera committed
36
	Publish(ctx context.Context, path path.Path, opts ...options.NamePublishOption) (IpnsEntry, error)
37 38

	// Resolve attempts to resolve the newest version of the specified name
Łukasz Magiera's avatar
Łukasz Magiera committed
39
	Resolve(ctx context.Context, name string, opts ...options.NameResolveOption) (path.Path, error)
40 41 42 43

	// Search is a version of Resolve which outputs paths as they are discovered,
	// reducing the time to first entry
	//
Łukasz Magiera's avatar
Łukasz Magiera committed
44 45
	// Note: by default, all paths read from the channel are considered unsafe,
	// except the latest (last path in channel read buffer).
46
	Search(ctx context.Context, name string, opts ...options.NameResolveOption) (<-chan IpnsResult, error)
47
}