textile

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2020 License: Apache-2.0 Imports: 34 Imported by: 0

README

Textile Wrappers

This package contains wrappers around Textile Threads and Buckets.

Usage

Initialization and Startup

Initialize Space's Textile Client by runing

client := textile.NewClient(store)
client.Start(ctx, config)

This will start the Textile connection, try to authenticate to the Hub, create a thread for metadata and a default bucket if there's none.

TODO
  • Separate the initialization logic into a new function that can be called from an imported "wallet". That way the initialized metadata and initial buckets can be pulled from the Hub if they exist.

Internal State

Textile Client holds the following objects:

  • store: A connection to the store. Used to fetch keys and store the meta thread threadID.
  • threads: A connection to Textile's Thread Client, initiated after startup.
  • bucketsClient: A connection to Textile's Bucket Client, initiated after startup.
  • netc: Wraps Textile network operations.
  • isRunning: Boolean that is set to true if the initialization after calling Start finished successfully.
  • Ready: A channel that gets emitted to after startup.
  • cfg: A reference to the config object.
  • isConnectedToHub: A boolean indicating if the initial Hub connection and authorization succeeded. If false, bucket operations will not be replicated on the Hub.

After initialization, Textile Client's state is mainly stored in the "meta thread". This meta thread stores a collection of the buckets the user has created or joined. This meta thread can be synced and joined in case the user wants to go cross-platform. The thread ID of the meta thread is stored in the local store. Operations over the meta thread are done in collections.go.

Creating and joining buckets (bucket_factory.go) adds a bucket instance to the meta thread. Listing and getting buckets query the meta thread to obtain the bucket's threadID and name. Using this info, these methods instantiate a Bucket object (./bucket/bucket.go), which exposes methods to do in bucket operations such as listing and adding files to a bucket.

Hub authentication

Currently, we attempt to connect to the Hub on initialization. In coming releases, we might switch that so that it can be toggled on and off from the API. If the Hub connection succeeds, all bucket operations will include the auth token in the calls to Textile's bucket client. This will trigger Hub replication. The auth token is obtained by signing a challenge received from the Hub using the user private key. If the challenge is signed correctly, the Hub returns a non-expiring auth token that we store so that we don't need to re-authenticate.

The logic for authenticating and prepending the keys before bucket operations can be seen in bucket_factory.go in the method GetBucketContext. It creates a Context instance that includes all the necessary information for accessing the correct thread and include the correct auth token.

TODO

Currently the challenge flow is disabled as it's triggering an error when using the token in GetBucketContext. Instead we authorize the user using embedded Textile Hub API Keys. This is being looked at by Textile team and will be fixed shortly.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IpfsAddr string
View Source
var MaxThreadsConn int
View Source
var MinThreadsConn int
View Source
var MongoHost string
View Source
var MongoPw string
View Source
var MongoRepSet string
View Source
var MongoUsr string

Functions

func NewClient

func NewClient(store db.Store) *textileClient

Creates a new Textile Client

func NotFound

func NotFound(slug string) error

Types

type Buckd

type Buckd interface {
	Stop() error
	Start(ctx context.Context) error
}

type Bucket

type Bucket interface {
	Slug() string
	Key() string
	GetData() bucket.BucketData
	DirExists(ctx context.Context, path string) (bool, error)
	FileExists(ctx context.Context, path string) (bool, error)
	UploadFile(
		ctx context.Context,
		path string,
		reader io.Reader,
	) (result path.Resolved, root path.Path, err error)
	GetFile(
		ctx context.Context,
		path string,
		w io.Writer,
	) error
	CreateDirectory(
		ctx context.Context,
		path string,
	) (result path.Resolved, root path.Path, err error)
	ListDirectory(
		ctx context.Context,
		path string,
	) (*bucket.DirEntries, error)
	DeleteDirOrFile(
		ctx context.Context,
		path string,
	) (path.Resolved, error)
}

type BucketRoot

type BucketRoot buckets_pb.Root

type BucketSchema added in v0.0.10

type BucketSchema struct {
	ID   core.InstanceID `json:"_id"`
	Slug string          `json:"slug"`
	DbID string
}

type Client

type Client interface {
	IsRunning() bool
	GetDefaultBucket(ctx context.Context) (Bucket, error)
	GetBucket(ctx context.Context, slug string) (Bucket, error)
	GetThreadsConnection() (*threadsClient.Client, error)
	GetBucketContext(ctx context.Context, bucketSlug string) (context.Context, *thread.ID, error)
	ListBuckets(ctx context.Context) ([]Bucket, error)
	ShareBucket(ctx context.Context, bucketSlug string) (*tc.DBInfo, error)
	JoinBucket(ctx context.Context, slug string, ti *domain.ThreadInfo) (bool, error)
	CreateBucket(ctx context.Context, bucketSlug string) (Bucket, error)
	Shutdown() error
	WaitForReady() chan bool
	Start(ctx context.Context, cfg config.Config) error
}

type EventHandler

type EventHandler interface {
	OnCreate(bucketData *bucket.BucketData, listenEvent *tc.ListenEvent)
	OnRemove(bucketData *bucket.BucketData, listenEvent *tc.ListenEvent)
	OnSave(bucketData *bucket.BucketData, listenEvent *tc.ListenEvent)
}

EventHandler

type TextileBuckd

type TextileBuckd struct {
	IsRunning bool
	Ready     chan bool
	// contains filtered or unexported fields
}

func NewBuckd

func NewBuckd(cfg config.Config) *TextileBuckd

func (*TextileBuckd) Shutdown

func (tb *TextileBuckd) Shutdown() error

func (*TextileBuckd) Start

func (tb *TextileBuckd) Start(ctx context.Context) error

func (*TextileBuckd) Stop

func (tb *TextileBuckd) Stop() error

func (*TextileBuckd) WaitForReady added in v0.0.11

func (tb *TextileBuckd) WaitForReady() chan bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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