lite

package module
v0.0.0-...-0aaf757 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2020 License: Apache-2.0 Imports: 77 Imported by: 0

README

lite

go get gitlab.com/remmer.wilts/lite

go mod vendor go mod tidy

set GO111MODULE=off

gomobile bind -o lite.aar -v -androidapi=24 -target=android gitlab.com/remmer.wilts/lite

Documentation

Index

Constants

View Source
const (
	// TFile is a regular file.
	TFile = 2
	// TDirectory is a directory.
	TDirectory = 1
	// TSymlink is a symlink.
	TSymlink = 4
)
View Source
const DefaultRecordEOL = 24 * time.Hour
View Source
const (
	MaxSize = 1024
)

Variables

View Source
var ErrClosed = errors.New("datastore closed")
View Source
var (
	ProtocolBitswap protocol.ID = "/ipfs/lite/1.0.0"
)
View Source
var (
	ProtocolPush protocol.ID = "/ipfs/push/1.0.0"
)

Functions

func DecodePrivateKey

func DecodePrivateKey(privKey string) (ci.PrivKey, error)

func GetPublished

func GetPublished(ctx context.Context, routing routing.ValueStore, datastore ds.Datastore, id peer.ID, checkRouting bool) (*pb.IpnsEntry, error)

GetPublished returns the record this node has published corresponding to the given peer ID.

If `checkRouting` is true and we have no existing record, this method will check the routing system for any existing records.

func IpnsDsKey

func IpnsDsKey(id peer.ID) ds.Key

func NewLiteHost

func NewLiteHost(host host.Host, listener Listener) bsmnet.BitSwapNetwork

NewMoinHost returns a BitSwapNetwork supported by underlying IPFS host.

func PkKeyForID

func PkKeyForID(id peer.ID) string

PkKeyForID returns the public key routing key for the given peer ID.

func PublishEntry

func PublishEntry(ctx context.Context, r routing.ValueStore, ipnskey string, rec *pb.IpnsEntry) error

func PublishPublicKey

func PublishPublicKey(ctx context.Context, r routing.ValueStore, k string, pubk ci.PubKey) error

func PublishWithEOL

func PublishWithEOL(ctx context.Context, routing routing.ValueStore, ds ds.Datastore,
	k ci.PrivKey, value path.Path, eol time.Time, sequence Sequence) error

PublishWithEOL is a temporary stand in for the ipns records implementation see here for more details: https://github.com/ipfs/specs/tree/master/records

func PutRecordToRouting

func PutRecordToRouting(ctx context.Context, r routing.ValueStore, k ci.PubKey, entry *pb.IpnsEntry) error

func ResolveNode

func ResolveNode(ctx context.Context, dag ipld.NodeGetter, p path.Path) (ipld.Node, error)

func ResolvePath

func ResolvePath(ctx context.Context, dag ipld.NodeGetter, p path.Path) (path.Resolved, error)

func UpdateRecord

func UpdateRecord(ctx context.Context, routing routing.ValueStore, ds ds.Datastore,
	k ci.PrivKey, value path.Path, eol time.Time, sequence Sequence) (*pb.IpnsEntry, error)

Types

type Adder

type Adder struct {
	Trickle   bool
	RawLeaves bool
	NoCopy    bool
	Chunker   string

	CidBuilder cid.Builder
	// contains filtered or unexported fields
}

Adder holds the switches passed to the `add` command.

func NewAdder

func NewAdder(ctx context.Context, ds ipld.DAGService) (*Adder, error)

NewAdder Returns a new Adder used for a file add operation.

func (*Adder) Add

func (adder *Adder) Add(reader io.Reader) (ipld.Node, error)

Constructs a node from reader's data, and adds it. Doesn't pin.

func (*Adder) AddFileNode

func (adder *Adder) AddFileNode(file files.Node) (ipld.Node, error)

AddAllAndPin adds the given request's files and pin them.

func (*Adder) AddLinkToDir

func (adder *Adder) AddLinkToDir(node ipld.Node, name string, link ipld.Node) (ipld.Node, error)

func (*Adder) CreateDir

func (adder *Adder) CreateDir(node ipld.Node) (ipld.Node, error)

func (*Adder) CreateEmptyDir

func (adder *Adder) CreateEmptyDir() (ipld.Node, error)

func (*Adder) RemoveLinkFromDir

func (adder *Adder) RemoveLinkFromDir(node ipld.Node, name string) (ipld.Node, error)

type BS

type BS struct {
	blockstore.Blockstore
}

func (*BS) Get

func (bs *BS) Get(c cid.Cid) (blocks.Block, error)

func (*BS) Put

func (bs *BS) Put(b blocks.Block) error

func (*BS) PutMany

func (bs *BS) PutMany(blks []blocks.Block) error

type ConnectionListener

type ConnectionListener interface {
	PeerConnected(peer.ID)
	PeerDisconnected(peer.ID)
}

type Datastore

type Datastore struct {
	DB *badger.DB
	// contains filtered or unexported fields
}

func Create

func Create(path string) (*Datastore, error)

func NewDatastore

func NewDatastore(path string, opt badger.Options) (*Datastore, error)

NewDatastore creates a new badger datastore.

DO NOT set the Dir and/or ValuePath fields of opt, they will be set for you.

func (*Datastore) Batch

func (d *Datastore) Batch() (ds.Batch, error)

func (*Datastore) Close

func (d *Datastore) Close() error

func (*Datastore) Delete

func (d *Datastore) Delete(key ds.Key) error

func (*Datastore) DiskUsage

func (d *Datastore) DiskUsage() (uint64, error)

DiskUsage implements the PersistentDatastore interface. It returns the sum of lsm and value log files sizes in bytes.

func (*Datastore) Get

func (d *Datastore) Get(key ds.Key) (value []byte, err error)

func (*Datastore) GetExpiration

func (d *Datastore) GetExpiration(key ds.Key) (time.Time, error)

func (*Datastore) GetSize

func (d *Datastore) GetSize(key ds.Key) (size int, err error)

func (*Datastore) Has

func (d *Datastore) Has(key ds.Key) (bool, error)

func (*Datastore) NewTransaction

func (d *Datastore) NewTransaction(readOnly bool) (ds.Txn, error)

NewTransaction starts a new transaction. The resulting transaction object can be mutated without incurring changes to the underlying DataStore until the transaction is Committed.

func (*Datastore) Put

func (d *Datastore) Put(key ds.Key, value []byte) error

func (*Datastore) PutWithTTL

func (d *Datastore) PutWithTTL(key ds.Key, value []byte, ttl time.Duration) error

func (*Datastore) Query

func (d *Datastore) Query(q dsq.Query) (dsq.Results, error)

func (*Datastore) SetTTL

func (d *Datastore) SetTTL(key ds.Key, ttl time.Duration) error

func (*Datastore) Sync

func (d *Datastore) Sync(prefix ds.Key) error

type DhtClose

type DhtClose interface {
	Close() bool
}

type DirEntry

type DirEntry struct {
	Name string
	Cid  cid.Cid

	// Only filled when asked to resolve the directory entry.
	Size uint64 // The size of the file in bytes (or the size of the symlink).
	Type int32  // The type of the file.

	Err error
}

DirEntry is a directory entry returned by `Ls`.

type Link struct {
	Name, Hash string
	Size       uint64
}

type Listener

type Listener interface {
	Error(Message string)
	Info(Message string)
	Verbose(Message string)
	ReachableUnknown()
	ReachablePublic()
	ReachablePrivate()
	Seeding(int)
	Leeching(int)
	ShouldConnect(string) bool
	ShouldGate(string) bool
	Push([]byte, string)
}

type Loader

type Loader struct {
	DagReader uio.DagReader
	Size      int64
	Data      []byte
	Read      int
}

func (*Loader) Close

func (fd *Loader) Close() error

func (*Loader) Load

func (fd *Loader) Load(size int64, close LoaderClose) error

func (*Loader) Seek

func (fd *Loader) Seek(position int64, close LoaderClose) error

type LoaderClose

type LoaderClose interface {
	Close() bool
}

type LsInfoClose

type LsInfoClose interface {
	LsInfo(NAME string, HASH string, SIZE int, TYPE int32)
	Close() bool
}

type Node

type Node struct {
	GracePeriod string
	LowWater    int
	HighWater   int
	Port        int

	PeerID     string
	PrivateKey string
	PublicKey  string
	RepoPath   string
	Agent      string

	EnablePrivateNetwork bool
	SwarmKey             []byte

	Running           bool
	Shutdown          bool
	PrivateNetwork    bool
	Pushing           bool
	Listener          Listener
	Badger            *badger.DB
	DataStore         ds.Batching
	PeerStore         peerstore.Peerstore
	RecordValidator   record.Validator
	BlockStore        blockstore.Blockstore
	BlockService      blockservice.BlockService
	DagService        format.DAGService
	Host              host.Host
	ConnectionManager connmgr.ConnManager
	Routing           routing.Routing
}

func NewNode

func NewNode(listener Listener, repoPath string) *Node

func (*Node) AddFile

func (n *Node) AddFile(fpath string) (string, error)

func (*Node) AddLinkToDir

func (n *Node) AddLinkToDir(dir string, name string, link string) (string, error)

func (*Node) Base32

func (n *Node) Base32(pid string) (string, error)

func (*Node) Base58

func (n *Node) Base58(pid string) (string, error)

func (*Node) CheckSwarmKey

func (n *Node) CheckSwarmKey(key string) error

func (*Node) CidCheck

func (n *Node) CidCheck(multihash string) error

func (*Node) Connect

func (n *Node) Connect(ctx context.Context, pi peer.AddrInfo) error

func (*Node) CreateEmptyDir

func (n *Node) CreateEmptyDir() (string, error)

func (*Node) Daemon

func (n *Node) Daemon(EnablePrivateSharing bool) error

func (*Node) DhtFindProvs

func (n *Node) DhtFindProvs(mcid string, provider Provider, numProviders int, close DhtClose) error

func (*Node) DhtFindProvsTimeout

func (n *Node) DhtFindProvsTimeout(mcid string, provider Provider, numProviders int, timeout int32) error

func (*Node) DhtProvide

func (n *Node) DhtProvide(mcid string, close DhtClose) error

func (*Node) DhtProvideTimeout

func (n *Node) DhtProvideTimeout(mcid string, timeout int32) error

func (*Node) Disconnect

func (n *Node) Disconnect(addr ma.Multiaddr) error

func (*Node) FindPeer

func (n *Node) FindPeer(ctx context.Context, p peer.ID) (peer.AddrInfo, error)

func (*Node) FindProviders

func (n *Node) FindProviders(ctx context.Context, p path.Path, numProviders int) (<-chan peer.AddrInfo, error)

func (*Node) GetLoader

func (n *Node) GetLoader(paths string, close LoaderClose) (*Loader, error)

func (*Node) GetRawPrivateKey

func (n *Node) GetRawPrivateKey() (string, error)

func (*Node) GetReader

func (n *Node) GetReader(paths string) (*Reader, error)

func (*Node) Id

func (n *Node) Id() (*PeerInfo, error)

func (*Node) Identity

func (n *Node) Identity() error

func (*Node) IsConnected

func (n *Node) IsConnected(pid string) (bool, error)

func (*Node) KnownAddrs

func (n *Node) KnownAddrs() (map[peer.ID][]ma.Multiaddr, error)

func (*Node) ListenAddrs

func (n *Node) ListenAddrs(context.Context) ([]ma.Multiaddr, error)

func (*Node) LocalAddrs

func (n *Node) LocalAddrs() ([]ma.Multiaddr, error)

func (*Node) Ls

func (n *Node) Ls(paths string, info LsInfoClose) error

func (*Node) Lss

func (n *Node) Lss(ctx context.Context, p path.Path, resolveChildren bool) (<-chan DirEntry, error)

func (*Node) NumSwarmPeers

func (n *Node) NumSwarmPeers() int

func (*Node) OpenDatabase

func (n *Node) OpenDatabase() error

func (*Node) PidCheck

func (n *Node) PidCheck(pid string) error

func (*Node) PidInfo

func (n *Node) PidInfo(pid string) (*PeerInfo, error)

func (*Node) Provide

func (n *Node) Provide(ctx context.Context, path path.Path) error

func (*Node) PublishName

func (n *Node) PublishName(p string, close PublisherClose, sequence Sequence) error

func (*Node) Push

func (n *Node) Push(pid string, msg []byte) (int, error)

func (*Node) RemoveLinkFromDir

func (n *Node) RemoveLinkFromDir(dir string, linkName string) (string, error)

func (*Node) RepoGC

func (n *Node) RepoGC() error

func (*Node) ResolveName

func (n *Node) ResolveName(info ResolveInfo, name string, offline bool, dhtRecords int) error

func (*Node) ResolveNode

func (n *Node) ResolveNode(ctx context.Context, dag ipld.DAGService, p path.Path) (ipld.Node, error)

func (*Node) ResolvePath

func (n *Node) ResolvePath(ctx context.Context, dag ipld.DAGService, p path.Path) (path.Resolved, error)

ResolvePath resolves the path `p` using Unixfs resolver, returns the resolved path.

func (*Node) Rm

func (n *Node) Rm(paths string, recursive bool) error

func (*Node) RmBlocks

func (n *Node) RmBlocks(blocks blockstore.GCBlockstore, cids []cid.Cid) error

RmBlocks removes the blocks provided in the cids slice. It returns a channel where objects of type RemovedBlock are placed, when not using the Quiet option. Block removal is asynchronous and will skip any pinned blocks.

func (*Node) Stream

func (n *Node) Stream(stream WriterStream) (string, error)

func (*Node) SwarmConnect

func (n *Node) SwarmConnect(addr string, timeout int32) (bool, error)

func (*Node) SwarmDisconnect

func (n *Node) SwarmDisconnect(addr string) (bool, error)

func (*Node) SwarmPeer

func (n *Node) SwarmPeer(pid string) (*Peer, error)

func (*Node) SwarmPeers

func (n *Node) SwarmPeers(stream PeerStream) error

type Peer

type Peer struct {
	Address string
	ID      string
}

type PeerInfo

type PeerInfo struct {
	ID              string
	PublicKey       string
	AgentVersion    string
	ProtocolVersion string
}

type PeerStream

type PeerStream interface {
	Peer(ID string)
}

type Provider

type Provider interface {
	Pid(Message string)
}

type PublisherClose

type PublisherClose interface {
	Close() bool
}

type Reader

type Reader struct {
	DagReader uio.DagReader
	Size      int64
	Data      []byte
	Read      int
}

func (*Reader) Close

func (fd *Reader) Close() error

func (*Reader) Load

func (fd *Reader) Load(size int64) error

func (*Reader) ReadAt

func (fd *Reader) ReadAt(position int64, size int64) error

func (*Reader) Seek

func (fd *Reader) Seek(position int64) error

type RefWriter

type RefWriter struct {
	DAG      ipld.DAGService
	Ctx      context.Context
	Paths    []string
	Unique   bool
	MaxDepth int
	PrintFmt string
	// contains filtered or unexported fields
}

func (*RefWriter) EvalRefs

func (rw *RefWriter) EvalRefs(n ipld.Node, enc cidenc.Encoder) (int, error)

WriteRefs writes refs of the given object to the underlying writer.

type ResolveInfo

type ResolveInfo interface {
	Resolved(NAME string, Seq int64)
	Close() bool
}

type Result

type Result struct {
	Path string
	Seq  uint64
	Err  error
}

type Sequence

type Sequence interface {
	Value(int64)
}

type UnknownUserError

type UnknownUserError string

func (UnknownUserError) Error

func (err UnknownUserError) Error() string

type VerifBS

type VerifBS struct {
	bstore.Blockstore
	Listener Listener
}

func (*VerifBS) Get

func (bs *VerifBS) Get(c cid.Cid) (blocks.Block, error)

func (*VerifBS) Put

func (bs *VerifBS) Put(b blocks.Block) error

func (*VerifBS) PutMany

func (bs *VerifBS) PutMany(blks []blocks.Block) error

type VerifBSGC

type VerifBSGC struct {
	bstore.GCBlockstore
}

func (*VerifBSGC) Get

func (bs *VerifBSGC) Get(c cid.Cid) (blocks.Block, error)

func (*VerifBSGC) Put

func (bs *VerifBSGC) Put(b blocks.Block) error

func (*VerifBSGC) PutMany

func (bs *VerifBSGC) PutMany(blks []blocks.Block) error

type Writer

type Writer struct {
	Writer WriterStream
}

func (*Writer) Read

func (fd *Writer) Read(p []byte) (n int, err error)

type WriterStream

type WriterStream interface {
	Read() (n int, err error)
	Data() []byte
	Close() bool
}

Jump to

Keyboard shortcuts

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