api

package
v1.8.15 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2018 License: GPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultHTTPListenAddr = "127.0.0.1"
	DefaultHTTPPort       = "8500"
)
View Source
const (
	ManifestType        = "application/bzz-manifest+json"
	ResourceContentType = "application/bzz-resource"
)

Variables

View Source
var ErrSkipManifest = errors.New("skip this manifest")

ErrSkipManifest is used as a return value from WalkFn to indicate that the manifest should be skipped

Functions

func RegularSlashes

func RegularSlashes(path string) (res string)

file system manifest always contains regularized paths no leading or trailing slashes, only single slashes inside

Types

type API added in v1.8.15

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

API implements webserver/file system related content storage and retrieval on top of the FileStore it is the public interface of the FileStore which is included in the ethereum stack

func NewAPI added in v1.8.15

func NewAPI(fileStore *storage.FileStore, dns Resolver, resourceHandler *mru.Handler) (self *API)

NewAPI the api constructor initialises a new API instance.

func (*API) AddFile added in v1.8.15

func (a *API) AddFile(mhash, path, fname string, content []byte, nameresolver bool) (storage.Address, string, error)

AddFile creates a new manifest entry, adds it to swarm, then adds a file to swarm.

func (*API) AppendFile added in v1.8.15

func (a *API) AppendFile(mhash, path, fname string, existingSize int64, content []byte, oldAddr storage.Address, offset int64, addSize int64, nameresolver bool) (storage.Address, string, error)

AppendFile removes old manifest, appends file entry to new manifest and adds it to Swarm.

func (*API) BuildDirectoryTree added in v1.8.15

func (a *API) BuildDirectoryTree(mhash string, nameresolver bool) (addr storage.Address, manifestEntryMap map[string]*manifestTrieEntry, err error)

BuildDirectoryTree used by swarmfs_unix

func (*API) Get added in v1.8.15

func (a *API) Get(manifestAddr storage.Address, path string) (reader storage.LazySectionReader, mimeType string, status int, contentAddr storage.Address, err error)

Get uses iterative manifest retrieval and prefix matching to resolve basePath to content using FileStore retrieve it returns a section reader, mimeType, status, the key of the actual content and an error

func (*API) Modify added in v1.8.15

func (a *API) Modify(addr storage.Address, path, contentHash, contentType string) (storage.Address, error)

Modify loads manifest and checks the content hash before recalculating and storing the manifest.

func (*API) NewManifest added in v1.8.15

func (a *API) NewManifest(toEncrypt bool) (storage.Address, error)

NewManifest creates and stores a new, empty manifest

func (*API) NewManifestWalker added in v1.8.15

func (a *API) NewManifestWalker(addr storage.Address, quitC chan bool) (*ManifestWalker, error)

func (*API) NewManifestWriter added in v1.8.15

func (a *API) NewManifestWriter(addr storage.Address, quitC chan bool) (*ManifestWriter, error)

func (*API) NewResourceManifest added in v1.8.15

func (a *API) NewResourceManifest(resourceAddr string) (storage.Address, error)

Manifest hack for supporting Mutable Resource Updates from the bzz: scheme see swarm/api/api.go:API.Get() for more information

func (*API) Put added in v1.8.15

func (a *API) Put(content, contentType string, toEncrypt bool) (k storage.Address, wait func(), err error)

Put provides singleton manifest creation on top of FileStore store

func (*API) RemoveFile added in v1.8.15

func (a *API) RemoveFile(mhash, path, fname string, nameresolver bool) (string, error)

RemoveFile removes a file entry in a manifest.

func (*API) Resolve added in v1.8.15

func (a *API) Resolve(uri *URI) (storage.Address, error)

Resolve resolves a URI to an Address using the MultiResolver.

func (*API) ResolveResourceManifest added in v1.8.15

func (a *API) ResolveResourceManifest(addr storage.Address) (storage.Address, error)

ResolveResourceManifest retrieves the Mutable Resource manifest for the given address, and returns the address of the metadata chunk.

func (*API) ResourceCreate added in v1.8.15

func (a *API) ResourceCreate(ctx context.Context, name string, frequency uint64) (storage.Address, error)

ResourceCreate creates Resource and returns its key

func (*API) ResourceHashSize added in v1.8.15

func (a *API) ResourceHashSize() int

ResourceHashSize returned the size of the digest produced by the Mutable Resource hashing function

func (*API) ResourceIsValidated added in v1.8.15

func (a *API) ResourceIsValidated() bool

ResourceIsValidated checks if the Mutable Resource has an active content validator.

func (*API) ResourceLookup added in v1.8.15

func (a *API) ResourceLookup(ctx context.Context, addr storage.Address, period uint32, version uint32, maxLookup *mru.LookupParams) (string, []byte, error)

ResourceLookup Looks up mutable resource updates at specific periods and versions

func (*API) ResourceUpdate added in v1.8.15

func (a *API) ResourceUpdate(ctx context.Context, name string, data []byte) (storage.Address, uint32, uint32, error)

ResourceUpdate updates a Mutable Resource with arbitrary data. Upon retrieval the update will be retrieved verbatim as bytes.

func (*API) ResourceUpdateMultihash added in v1.8.15

func (a *API) ResourceUpdateMultihash(ctx context.Context, name string, data []byte) (storage.Address, uint32, uint32, error)

ResourceUpdateMultihash updates a Mutable Resource and marks the update's content to be of multihash type, which will be recognized upon retrieval. It will fail if the data is not a valid multihash.

func (*API) Retrieve added in v1.8.15

func (a *API) Retrieve(addr storage.Address) (reader storage.LazySectionReader, isEncrypted bool)

Retrieve FileStore reader API

func (*API) Store added in v1.8.15

func (a *API) Store(data io.Reader, size int64, toEncrypt bool) (addr storage.Address, wait func(), err error)

Store wraps the Store API call of the embedded FileStore

func (*API) Upload added in v1.8.15

func (a *API) Upload(uploadDir, index string, toEncrypt bool) (hash string, err error)

Upload to be used only in TEST

type Config

type Config struct {
	// serialised/persisted fields
	*storage.FileStoreParams
	*storage.LocalStoreParams
	*network.HiveParams
	Swap *swap.LocalProfile
	Pss  *pss.PssParams
	//*network.SyncParams
	Contract          common.Address
	EnsRoot           common.Address
	EnsAPIs           []string
	Path              string
	ListenAddr        string
	Port              string
	PublicKey         string
	BzzKey            string
	NodeID            string
	NetworkID         uint64
	SwapEnabled       bool
	SyncEnabled       bool
	DeliverySkipCheck bool
	SyncUpdateDelay   time.Duration
	SwapAPI           string
	Cors              string
	BzzAccount        string
	BootNodes         string
	// contains filtered or unexported fields
}

separate bzz directories allow several bzz nodes running in parallel

func NewConfig added in v1.8.15

func NewConfig() (c *Config)

create a default config with all parameters to set to defaults

func (*Config) Init

func (c *Config) Init(prvKey *ecdsa.PrivateKey)

some config params need to be initialized after the complete config building phase is completed (e.g. due to overriding flags)

func (*Config) ShiftPrivateKey added in v1.8.15

func (c *Config) ShiftPrivateKey() (privKey *ecdsa.PrivateKey)

type Control

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

func NewControl

func NewControl(api *API, hive *network.Hive) *Control

func (*Control) Hive

func (c *Control) Hive() string
func (self *Control) BlockNetworkRead(on bool) {
	self.hive.BlockNetworkRead(on)
}
func (self *Control) SyncEnabled(on bool) {
	self.hive.SyncEnabled(on)
}
func (self *Control) SwapEnabled(on bool) {
	self.hive.SwapEnabled(on)
}

type ErrResolve

type ErrResolve error

ErrResolve is returned when an URI cannot be resolved from ENS.

type FileSystem

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

func NewFileSystem

func NewFileSystem(api *API) *FileSystem

func (*FileSystem) Download

func (fs *FileSystem) Download(bzzpath, localpath string) error

Download replicates the manifest basePath structure on the local filesystem under localpath

DEPRECATED: Use the HTTP API instead

func (*FileSystem) Upload

func (fs *FileSystem) Upload(lpath, index string, toEncrypt bool) (string, error)

Upload replicates a local directory as a manifest file and uploads it using FileStore store This function waits the chunks to be stored. TODO: localpath should point to a manifest

DEPRECATED: Use the HTTP API instead

type Manifest

type Manifest struct {
	Entries []ManifestEntry `json:"entries,omitempty"`
}

Manifest represents a swarm manifest

type ManifestEntry

type ManifestEntry struct {
	Hash        string    `json:"hash,omitempty"`
	Path        string    `json:"path,omitempty"`
	ContentType string    `json:"contentType,omitempty"`
	Mode        int64     `json:"mode,omitempty"`
	Size        int64     `json:"size,omitempty"`
	ModTime     time.Time `json:"mod_time,omitempty"`
	Status      int       `json:"status,omitempty"`
}

ManifestEntry represents an entry in a swarm manifest

type ManifestList

type ManifestList struct {
	CommonPrefixes []string         `json:"common_prefixes,omitempty"`
	Entries        []*ManifestEntry `json:"entries,omitempty"`
}

ManifestList represents the result of listing files in a manifest

type ManifestWalker

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

ManifestWalker is used to recursively walk the entries in the manifest and all of its submanifests

func (*ManifestWalker) Walk

func (m *ManifestWalker) Walk(walkFn WalkFn) error

Walk recursively walks the manifest calling walkFn for each entry in the manifest, including submanifests

type ManifestWriter

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

ManifestWriter is used to add and remove entries from an underlying manifest

func (*ManifestWriter) AddEntry

func (m *ManifestWriter) AddEntry(data io.Reader, e *ManifestEntry) (storage.Address, error)

AddEntry stores the given data and adds the resulting key to the manifest

func (*ManifestWriter) RemoveEntry

func (m *ManifestWriter) RemoveEntry(path string) error

RemoveEntry removes the given path from the manifest

func (*ManifestWriter) Store

func (m *ManifestWriter) Store() (storage.Address, error)

Store stores the manifest, returning the resulting storage key

type MultiResolver

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

MultiResolver is used to resolve URL addresses based on their TLDs. Each TLD can have multiple resolvers, and the resoluton from the first one in the sequence will be returned.

func NewMultiResolver

func NewMultiResolver(opts ...MultiResolverOption) (m *MultiResolver)

NewMultiResolver creates a new instance of MultiResolver.

func (*MultiResolver) HeaderByNumber added in v1.8.15

func (m *MultiResolver) HeaderByNumber(ctx context.Context, name string, blockNr *big.Int) (*types.Header, error)

HeaderByNumber uses the validator of the given domainname and retrieves the header for the given block number

func (*MultiResolver) Resolve

func (m *MultiResolver) Resolve(addr string) (h common.Hash, err error)

Resolve resolves address by choosing a Resolver by TLD. If there are more default Resolvers, or for a specific TLD, the Hash from the the first one which does not return error will be returned.

func (*MultiResolver) SetNameHash added in v1.8.15

func (m *MultiResolver) SetNameHash(nameHash func(string) common.Hash)

SetNameHash sets the hasher function that hashes the domain into a name hash that ENS uses

func (*MultiResolver) ValidateOwner added in v1.8.15

func (m *MultiResolver) ValidateOwner(name string, address common.Address) (bool, error)

ValidateOwner checks the ENS to validate that the owner of the given domain is the given eth address

type MultiResolverOption

type MultiResolverOption func(*MultiResolver)

MultiResolverOption sets options for MultiResolver and is used as arguments for its constructor.

func MultiResolverOptionWithNameHash added in v1.8.15

func MultiResolverOptionWithNameHash(nameHash func(string) common.Hash) MultiResolverOption

MultiResolverOptionWithNameHash is unused at the time of this writing

func MultiResolverOptionWithResolver

func MultiResolverOptionWithResolver(r ResolveValidator, tld string) MultiResolverOption

MultiResolverOptionWithResolver adds a Resolver to a list of resolvers for a specific TLD. If TLD is an empty string, the resolver will be added to the list of default resolver, the ones that will be used for resolution of addresses which do not have their TLD resolver specified.

type NoResolverError

type NoResolverError struct {
	TLD string
}

NoResolverError is returned by MultiResolver.Resolve if no resolver can be found for the address.

func NewNoResolverError

func NewNoResolverError(tld string) *NoResolverError

NewNoResolverError creates a NoResolverError for the given top level domain

func (*NoResolverError) Error

func (e *NoResolverError) Error() string

Error NoResolverError implements error

type ResolveValidator added in v1.8.15

type ResolveValidator interface {
	Resolver
	Owner(node [32]byte) (common.Address, error)
	HeaderByNumber(context.Context, *big.Int) (*types.Header, error)
}

ResolveValidator is used to validate the contained Resolver

type Resolver

type Resolver interface {
	Resolve(string) (common.Hash, error)
}

Resolver interface resolve a domain name to a hash using ENS

type Response

type Response struct {
	MimeType string
	Status   int
	Size     int64
	// Content  []byte
	Content string
}

type Storage

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

implements a service

DEPRECATED: Use the HTTP API instead

func NewStorage

func NewStorage(api *API) *Storage

func (*Storage) Get

func (s *Storage) Get(bzzpath string) (*Response, error)

Get retrieves the content from bzzpath and reads the response in full It returns the Response object, which serialises containing the response body as the value of the Content field NOTE: if error is non-nil, sResponse may still have partial content the actual size of which is given in len(resp.Content), while the expected size is resp.Size

DEPRECATED: Use the HTTP API instead

func (*Storage) Modify

func (s *Storage) Modify(rootHash, path, contentHash, contentType string) (newRootHash string, err error)

Modify(rootHash, basePath, contentHash, contentType) takes th e manifest trie rooted in rootHash, and merge on to it. creating an entry w conentType (mime)

DEPRECATED: Use the HTTP API instead

func (*Storage) Put

func (s *Storage) Put(content, contentType string, toEncrypt bool) (storage.Address, func(), error)

Put uploads the content to the swarm with a simple manifest speficying its content type

DEPRECATED: Use the HTTP API instead

type URI

type URI struct {
	// Scheme has one of the following values:
	//
	// * bzz           - an entry in a swarm manifest
	// * bzz-raw       - raw swarm content
	// * bzz-immutable - immutable URI of an entry in a swarm manifest
	//                   (address is not resolved)
	// * bzz-list      -  list of all files contained in a swarm manifest
	//
	Scheme string

	// Addr is either a hexadecimal storage address or it an address which
	// resolves to a storage address
	Addr string

	// Path is the path to the content within a swarm manifest
	Path string
	// contains filtered or unexported fields
}

URI is a reference to content stored in swarm.

func Parse

func Parse(rawuri string) (*URI, error)

Parse parses rawuri into a URI struct, where rawuri is expected to have one of the following formats:

* <scheme>:/ * <scheme>:/<addr> * <scheme>:/<addr>/<path> * <scheme>:// * <scheme>://<addr> * <scheme>://<addr>/<path>

with scheme one of bzz, bzz-raw, bzz-immutable, bzz-list or bzz-hash

func (*URI) Address added in v1.8.15

func (u *URI) Address() storage.Address

func (*URI) Hash

func (u *URI) Hash() bool

func (*URI) Immutable

func (u *URI) Immutable() bool

func (*URI) List

func (u *URI) List() bool

func (*URI) Raw

func (u *URI) Raw() bool

func (*URI) Resource added in v1.8.15

func (u *URI) Resource() bool

func (*URI) String

func (u *URI) String() string

type WalkFn

type WalkFn func(entry *ManifestEntry) error

WalkFn is the type of function called for each entry visited by a recursive manifest walk

Directories

Path Synopsis
Show nicely (but simple) formatted HTML error pages (or respond with JSON if the appropriate `Accept` header is set)) for the http package.
Show nicely (but simple) formatted HTML error pages (or respond with JSON if the appropriate `Accept` header is set)) for the http package.

Jump to

Keyboard shortcuts

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