api

package
v1.8.28 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2020 License: GPL-3.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultHTTPListenAddr = "127.0.0.1"
	DefaultHTTPPort       = "8500"
)
View Source
const (
	ManifestType    = "application/bzz-manifest+json"
	FeedContentType = "application/bzz-feed"
)
View Source
const AccessTypeACT = AccessType("act")
View Source
const AccessTypePK = AccessType("pk")
View Source
const AccessTypePass = AccessType("pass")
View Source
const EMPTY_CREDENTIALS = ""
View Source
const MimeOctetStream = "application/octet-stream"

MimeOctetStream default value of http Content-Type header

Variables

View Source
var (
	ErrDecrypt                = errors.New("cant decrypt - forbidden")
	ErrUnknownAccessType      = errors.New("unknown access type (or not implemented)")
	ErrDecryptDomainForbidden = errors.New("decryption request domain forbidden - can only decrypt on localhost")
	AllowedDecryptDomains     = []string{
		"localhost",
		"127.0.0.1",
	}
)
View Source
var DefaultKdfParams = NewKdfParams(262144, 1, 8)
View Source
var ErrCannotLoadFeedManifest = errors.New("Cannot load feed manifest")

ErrCannotLoadFeedManifest is returned when looking up a feeds manifest fails

View Source
var ErrCannotResolveFeed = errors.New("Cannot resolve Feed")

ErrCannotResolveFeed is returned when values provided are not enough or invalid to recreate a feed out of them.

View Source
var ErrCannotResolveFeedURI = errors.New("Cannot resolve Feed URI")

ErrCannotResolveFeedURI is returned when the ENS resolver is not able to translate a name to a Swarm feed

View Source
var ErrNotAFeedManifest = errors.New("Not a feed manifest")

ErrNotAFeedManifest is returned when the address provided returned something other than a valid manifest

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 DetectContentType added in v1.8.17

func DetectContentType(fileName string, f io.ReadSeeker) (string, error)

DetectContentType by file file extension, or fallback to content sniff

func DoACT added in v1.8.16

func DoACT(ctx *cli.Context, privateKey *ecdsa.PrivateKey, salt []byte, grantees []string, encryptPasswords []string) (accessKey []byte, ae *AccessEntry, actManifest *Manifest, err error)

DoACT is a helper function to the CLI API that handles the entire business logic for creating a access key, access entry and ACT manifest (including uploading it) given the cli context, ec keys, password grantees and salt

func NOOPDecrypt added in v1.8.14

func NOOPDecrypt(*ManifestEntry) error

NOOPDecrypt is a generic decrypt function that is passed into the API in places where real ACT decryption capabilities are either unwanted, or alternatively, cannot be implemented in the immediate scope

func NewSessionKeyPK added in v1.8.14

func NewSessionKeyPK(private *ecdsa.PrivateKey, public *ecdsa.PublicKey, salt []byte) ([]byte, error)

NewSessionKeyPK creates a new ACT Session Key using an ECDH shared secret for the given key pair and the given salt value

func NewSessionKeyPassword added in v1.8.14

func NewSessionKeyPassword(password string, accessEntry *AccessEntry) ([]byte, error)

NewSessionKeyPassword creates a session key based on a shared secret (password) and the given salt and kdf parameters in the access entry

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.12

type API struct {
	Decryptor func(context.Context, string) DecryptFunc
	// 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.12

func NewAPI(fileStore *storage.FileStore, dns Resolver, feedHandler *feed.Handler, pk *ecdsa.PrivateKey) (self *API)

NewAPI the api constructor initialises a new API instance.

func (*API) AddFile added in v1.8.12

func (a *API) AddFile(ctx context.Context, 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.12

func (a *API) AppendFile(ctx context.Context, 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.12

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

BuildDirectoryTree used by swarmfs_unix

func (*API) Delete added in v1.8.13

func (a *API) Delete(ctx context.Context, addr string, path string) (storage.Address, error)

func (*API) FeedsLookup added in v1.8.17

func (a *API) FeedsLookup(ctx context.Context, query *feed.Query) ([]byte, error)

FeedsLookup finds Swarm feeds updates at specific points in time, or the latest update

func (*API) FeedsNewRequest added in v1.8.17

func (a *API) FeedsNewRequest(ctx context.Context, feed *feed.Feed) (*feed.Request, error)

FeedsNewRequest creates a Request object to update a specific feed

func (*API) FeedsUpdate added in v1.8.17

func (a *API) FeedsUpdate(ctx context.Context, request *feed.Request) (storage.Address, error)

FeedsUpdate publishes a new update on the given feed

func (*API) Get added in v1.8.12

func (a *API) Get(ctx context.Context, decrypt DecryptFunc, 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) GetDirectoryTar added in v1.8.13

func (a *API) GetDirectoryTar(ctx context.Context, decrypt DecryptFunc, uri *URI) (io.ReadCloser, error)

GetDirectoryTar fetches a requested directory as a tarstream it returns an io.Reader and an error. Do not forget to Close() the returned ReadCloser

func (*API) GetManifestList added in v1.8.13

func (a *API) GetManifestList(ctx context.Context, decryptor DecryptFunc, addr storage.Address, prefix string) (list ManifestList, err error)

GetManifestList lists the manifest entries for the specified address and prefix and returns it as a ManifestList

func (*API) Modify added in v1.8.12

func (a *API) Modify(ctx context.Context, 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) NewFeedManifest added in v1.8.17

func (a *API) NewFeedManifest(ctx context.Context, feed *feed.Feed) (storage.Address, error)

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

func (*API) NewManifest added in v1.8.12

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

NewManifest creates and stores a new, empty manifest

func (*API) NewManifestWalker added in v1.8.12

func (a *API) NewManifestWalker(ctx context.Context, addr storage.Address, decrypt DecryptFunc, quitC chan bool) (*ManifestWalker, error)

func (*API) NewManifestWriter added in v1.8.12

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

func (*API) Put added in v1.8.12

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

Put provides singleton manifest creation on top of FileStore store

func (*API) RemoveFile added in v1.8.12

func (a *API) RemoveFile(ctx context.Context, mhash string, path string, fname string, nameresolver bool) (string, error)

RemoveFile removes a file entry in a manifest.

func (*API) Resolve added in v1.8.12

func (a *API) Resolve(ctx context.Context, address string) (storage.Address, error)

Resolve a name into a content-addressed hash where address could be an ENS name, or a content addressed hash

func (*API) ResolveFeed added in v1.8.17

func (a *API) ResolveFeed(ctx context.Context, uri *URI, values feed.Values) (*feed.Feed, error)

ResolveFeed attempts to extract feed information out of the manifest, if provided If not, it attempts to extract the feed out of a set of key-value pairs

func (*API) ResolveFeedManifest added in v1.8.17

func (a *API) ResolveFeedManifest(ctx context.Context, addr storage.Address) (*feed.Feed, error)

ResolveFeedManifest retrieves the Swarm feed manifest for the given address, and returns the referenced Feed.

func (*API) ResolveURI added in v1.8.14

func (a *API) ResolveURI(ctx context.Context, uri *URI, credentials string) (storage.Address, error)

Resolve resolves a URI to an Address using the MultiResolver.

func (*API) Retrieve added in v1.8.12

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

Retrieve FileStore reader API

func (*API) Store added in v1.8.12

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

Store wraps the Store API call of the embedded FileStore

func (*API) UpdateManifest added in v1.8.13

func (a *API) UpdateManifest(ctx context.Context, addr storage.Address, update func(mw *ManifestWriter) error) (storage.Address, error)

func (*API) UploadTar added in v1.8.13

func (a *API) UploadTar(ctx context.Context, bodyReader io.ReadCloser, manifestPath, defaultPath string, mw *ManifestWriter) (storage.Address, error)

type AccessEntry added in v1.8.14

type AccessEntry struct {
	Type      AccessType
	Publisher string
	Salt      []byte
	Act       string
	KdfParams *KdfParams
}

func DoPK added in v1.8.16

func DoPK(ctx *cli.Context, privateKey *ecdsa.PrivateKey, granteePublicKey string, salt []byte) (sessionKey []byte, ae *AccessEntry, err error)

DoPK is a helper function to the CLI API that handles the entire business logic for creating a session key and access entry given the cli context, ec keys and salt

func DoPassword added in v1.8.16

func DoPassword(ctx *cli.Context, password string, salt []byte) (sessionKey []byte, ae *AccessEntry, err error)

DoPassword is a helper function to the CLI API that handles the entire business logic for creating a session key and an access entry given the cli context, password and salt. By default - DefaultKdfParams are used as the scrypt params

func NewAccessEntryACT added in v1.8.14

func NewAccessEntryACT(publisher string, salt []byte, act string) (*AccessEntry, error)

NewAccessEntryACT creates a manifest AccessEntry in order to create an ACT protected by a combination of EC keys and passwords

func NewAccessEntryPK added in v1.8.14

func NewAccessEntryPK(publisher string, salt []byte) (*AccessEntry, error)

NewAccessEntryPK creates a manifest AccessEntry in order to create an ACT protected by a pair of Elliptic Curve keys

func NewAccessEntryPassword added in v1.8.14

func NewAccessEntryPassword(salt []byte, kdfParams *KdfParams) (*AccessEntry, error)

NewAccessEntryPassword creates a manifest AccessEntry in order to create an ACT protected by a password

func (*AccessEntry) MarshalJSON added in v1.8.14

func (a *AccessEntry) MarshalJSON() (out []byte, err error)

func (*AccessEntry) UnmarshalJSON added in v1.8.14

func (a *AccessEntry) UnmarshalJSON(value []byte) error

type AccessType added in v1.8.14

type AccessType string

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
	SyncingSkipCheck     bool
	DeliverySkipCheck    bool
	MaxStreamPeerServers int
	LightNodeEnabled     bool
	BootnodeMode         bool
	SyncUpdateDelay      time.Duration
	SwapAPI              string
	Cors                 string
	BzzAccount           string
	GlobalStoreAPI       string
	// contains filtered or unexported fields
}

separate bzz directories allow several bzz nodes running in parallel

func NewConfig

func NewConfig() (c *Config)

create a default config with all parameters to set to defaults

func (*Config) Init added in v1.8.0

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.12

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

type DecryptFunc added in v1.8.14

type DecryptFunc func(*ManifestEntry) 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, 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 HasInfo added in v1.8.26

type HasInfo struct {
	Addr string `json:"address"`
	Has  bool   `json:"has"`
}

type Inspector added in v1.8.26

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

func NewInspector added in v1.8.26

func NewInspector(api *API, hive *network.Hive, netStore *storage.NetStore) *Inspector

func (*Inspector) Has added in v1.8.26

func (inspector *Inspector) Has(chunkAddresses []storage.Address) []HasInfo

Has checks whether each chunk address is present in the underlying datastore, the bool in the returned structs indicates if the underlying datastore has the chunk stored with the given address (true), or not (false)

func (*Inspector) Hive added in v1.8.26

func (inspector *Inspector) Hive() string

Hive prints the kademlia table

type KdfParams added in v1.8.14

type KdfParams struct {
	N int `json:"n"`
	P int `json:"p"`
	R int `json:"r"`
}

func NewKdfParams added in v1.8.14

func NewKdfParams(n, p, r int) *KdfParams

NewKdfParams returns a KdfParams struct with the given scrypt params

type Manifest added in v1.6.0

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

Manifest represents a swarm manifest

func GenerateAccessControlManifest added in v1.8.14

func GenerateAccessControlManifest(ctx *cli.Context, ref string, accessKey []byte, ae *AccessEntry) (*Manifest, error)

type ManifestEntry added in v1.6.0

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"`
	Access      *AccessEntry `json:"access,omitempty"`
	Feed        *feed.Feed   `json:"feed,omitempty"`
}

ManifestEntry represents an entry in a swarm manifest

type ManifestList added in v1.6.0

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 added in v1.6.0

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 added in v1.6.0

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

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

type ManifestWriter added in v1.6.0

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

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

func (*ManifestWriter) AddEntry added in v1.6.0

func (m *ManifestWriter) AddEntry(ctx context.Context, data io.Reader, e *ManifestEntry) (addr storage.Address, err error)

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

func (*ManifestWriter) RemoveEntry added in v1.6.0

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

RemoveEntry removes the given path from the manifest

func (*ManifestWriter) Store added in v1.6.0

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

Store stores the manifest, returning the resulting storage address

type MultiResolver added in v1.8.2

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 resolution from the first one in the sequence will be returned.

func NewMultiResolver added in v1.8.2

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

NewMultiResolver creates a new instance of MultiResolver.

func (*MultiResolver) Resolve added in v1.8.2

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 first one which does not return error will be returned.

type MultiResolverOption added in v1.8.2

type MultiResolverOption func(*MultiResolver)

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

func MultiResolverOptionWithResolver added in v1.8.2

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 added in v1.8.2

type NoResolverError struct {
	TLD string
}

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

func NewNoResolverError added in v1.8.2

func NewNoResolverError(tld string) *NoResolverError

NewNoResolverError creates a NoResolverError for the given top level domain

func (*NoResolverError) Error added in v1.8.2

func (e *NoResolverError) Error() string

Error NoResolverError implements error

type RefEncryption added in v1.8.14

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

func NewRefEncryption added in v1.8.14

func NewRefEncryption(refSize int) *RefEncryption

func (*RefEncryption) Decrypt added in v1.8.14

func (re *RefEncryption) Decrypt(ref []byte, key []byte) ([]byte, error)

func (*RefEncryption) Encrypt added in v1.8.14

func (re *RefEncryption) Encrypt(ref []byte, key []byte) ([]byte, error)

type ResolveValidator added in v1.8.12

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(ctx context.Context, 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) Put

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

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

DEPRECATED: Use the HTTP API instead

type URI added in v1.6.0

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 added in v1.5.8

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.12

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

func (*URI) Feed added in v1.8.17

func (u *URI) Feed() bool

func (*URI) Hash added in v1.8.0

func (u *URI) Hash() bool

func (*URI) Immutable added in v1.6.0

func (u *URI) Immutable() bool

func (*URI) List added in v1.8.0

func (u *URI) List() bool

func (*URI) MarshalJSON added in v1.8.14

func (u *URI) MarshalJSON() (out []byte, err error)

func (*URI) Raw added in v1.6.0

func (u *URI) Raw() bool

func (*URI) String added in v1.6.0

func (u *URI) String() string

func (*URI) UnmarshalJSON added in v1.8.14

func (u *URI) UnmarshalJSON(value []byte) error

type WalkFn added in v1.6.0

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
A simple http server interface to Swarm
A simple http server interface to Swarm

Jump to

Keyboard shortcuts

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