api

package
v2.1.92+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2018 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

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

Variables

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

SkipManifest 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

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

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

func NewApi

func NewApi(dpa *storage.DPA, dns Resolver) (self *Api)

the api constructor initialises

func (*Api) AddFile

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

func (*Api) AppendFile

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

func (*Api) BuildDirectoryTree

func (a *Api) BuildDirectoryTree(mhash string, nameresolver bool) (key storage.Key, manifestEntryMap map[string]*manifestTrieEntry, err error)

func (*Api) Get

func (a *Api) Get(key storage.Key, path string) (reader storage.LazySectionReader, mimeType string, status int, err error)

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

func (*Api) Modify

func (a *Api) Modify(key storage.Key, path, contentHash, contentType string) (storage.Key, error)

func (*Api) NewManifest

func (a *Api) NewManifest() (storage.Key, error)

NewManifest creates and stores a new, empty manifest

func (*Api) NewManifestWalker

func (a *Api) NewManifestWalker(key storage.Key, quitC chan bool) (*ManifestWalker, error)

func (*Api) NewManifestWriter

func (a *Api) NewManifestWriter(key storage.Key, quitC chan bool) (*ManifestWriter, error)

func (*Api) Put

func (a *Api) Put(content, contentType string) (storage.Key, error)

Put provides singleton manifest creation on top of dpa store

func (*Api) RemoveFile

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

func (*Api) Resolve

func (a *Api) Resolve(uri *URI) (storage.Key, error)

DNS Resolver

func (*Api) Retrieve

func (a *Api) Retrieve(key storage.Key) storage.LazySectionReader

DPA reader API

func (*Api) Store

func (a *Api) Store(data io.Reader, size int64, wg *sync.WaitGroup) (key storage.Key, err error)

func (*Api) Upload

func (a *Api) Upload(uploadDir, index string) (hash string, err error)

to be used only in TEST

type Config

type Config struct {
	// serialised/persisted fields
	*storage.StoreParams
	*storage.ChunkerParams
	*network.HiveParams
	Swap *swap.SwapParams
	*network.SyncParams
	Contract    common.Address
	EnsRoot     common.Address
	EnsApi      string
	Path        string
	ListenAddr  string
	Port        string
	PublicKey   string
	BzzKey      string
	NetworkId   uint64
	SwapEnabled bool
	SyncEnabled bool
	SwapApi     string
	Cors        string
	BzzAccount  string
	BootNodes   string
}

separate bzz directories allow several bzz nodes running in parallel

func NewDefaultConfig

func NewDefaultConfig() (self *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)

type Control

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

func NewControl

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

func (*Control) BlockNetworkRead

func (c *Control) BlockNetworkRead(on bool)

func (*Control) Hive

func (c *Control) Hive() string

func (*Control) SwapEnabled

func (c *Control) SwapEnabled(on bool)

func (*Control) SyncEnabled

func (c *Control) SyncEnabled(on bool)

type ErrResolve

type ErrResolve error

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) (string, error)

Upload replicates a local directory as a manifest file and uploads it using dpa store 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.Key, 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.Key, error)

Store stores the manifest, returning the resulting storage key

type Resolver

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

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) (string, 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
	//
	// Deprecated Schemes:
	// * bzzr - raw swarm content
	// * bzzi - immutable URI of an entry in a swarm manifest
	//          (address is not resolved)
	// * bzz-hash - hash of swarm content
	//
	Scheme string

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

	// Path is the path to the content within a swarm manifest
	Path string
}

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 or deprecated ones bzzr and bzzi

func (*URI) DeprecatedImmutable

func (u *URI) DeprecatedImmutable() bool

func (*URI) DeprecatedRaw

func (u *URI) DeprecatedRaw() bool

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) 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