ipfslog

package module
Version: v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2021 License: Apache-2.0, MIT Imports: 15 Imported by: 9

README


go-ipfs-log

🤝 Go version of append-only log CRDT on IPFS.

Code Factor Go Report Card GitHub version GoDoc

berty.techGitHub

An append-only log on IPFS.

ipfs-log was originally created for orbit-db - a distributed peer-to-peer database on IPFS. This library intends to provide a fully compatible port of the JavaScript version in Go.

The majority of this code was vastly derived from the JavaScript's ipfs-log library.

Usage

See the example package on GoDoc

Licensing

go-ipfs-log is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.

Documentation

Overview

Package ipfslog implements an append-only log CRDT on IPFS

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppendOptions

type AppendOptions = iface.AppendOptions

type CanAppendContext

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

func (*CanAppendContext) GetLogEntries

func (c *CanAppendContext) GetLogEntries() []accesscontroller.LogEntry

type Entry

type Entry = iface.IPFSLogEntry

type FetchOptions

type FetchOptions struct {
	Length       *int
	Exclude      []iface.IPFSLogEntry
	ProgressChan chan iface.IPFSLogEntry
	Timeout      time.Duration
	Concurrency  int
	SortFn       iface.EntrySortFn
}

type IO

type IO = iface.IO

type IPFSLog

type IPFSLog struct {
	Storage          core_iface.CoreAPI
	ID               string
	AccessController accesscontroller.Interface
	SortFn           iface.EntrySortFn
	Identity         *identityprovider.Identity
	Entries          iface.IPFSLogOrderedEntries

	Next  iface.IPFSLogOrderedEntries
	Clock iface.IPFSLogLamportClock
	// contains filtered or unexported fields
}

func NewFromEntry

func NewFromEntry(ctx context.Context, services core_iface.CoreAPI, identity *identityprovider.Identity, sourceEntries []iface.IPFSLogEntry, logOptions *LogOptions, fetchOptions *entry.FetchOptions) (*IPFSLog, error)

NewFromEntry Creates a IPFSLog from an Entry

Creating a log from an entry will retrieve entries from IPFS, thus causing side effects

func NewFromEntryHash

func NewFromEntryHash(ctx context.Context, services core_iface.CoreAPI, identity *identityprovider.Identity, hash cid.Cid, logOptions *LogOptions, fetchOptions *FetchOptions) (*IPFSLog, error)

NewFromEntryHash Creates a IPFSLog from a hash of an Entry

Creating a log from a hash will retrieve entries from IPFS, thus causing side effects

func NewFromJSON

func NewFromJSON(ctx context.Context, services core_iface.CoreAPI, identity *identityprovider.Identity, jsonLog *iface.JSONLog, logOptions *LogOptions, fetchOptions *entry.FetchOptions) (*IPFSLog, error)

NewFromJSON Creates a IPFSLog from a JSON Snapshot

Creating a log from a JSON Snapshot will retrieve entries from IPFS, thus causing side effects

func NewFromMultihash

func NewFromMultihash(ctx context.Context, services core_iface.CoreAPI, identity *identityprovider.Identity, hash cid.Cid, logOptions *LogOptions, fetchOptions *FetchOptions) (*IPFSLog, error)

NewFromMultihash Creates a IPFSLog from a hash

Creating a log from a hash will retrieve entries from IPFS, thus causing side effects

func NewLog

func NewLog(services core_iface.CoreAPI, identity *identityprovider.Identity, options *LogOptions) (*IPFSLog, error)

NewLog Creates creates a new IPFSLog for a given identity

Each IPFSLog gets a unique ID, which can be passed in the options as ID.

Returns a log instance.

ipfs is an instance of IPFS.

identity is an instance of Identity and will be used to sign entries Usually this should be a user id or similar.

options.AccessController is an instance of accesscontroller.Interface, which by default allows anyone to append to the IPFSLog.

func (*IPFSLog) Append

func (l *IPFSLog) Append(ctx context.Context, payload []byte, opts *AppendOptions) (iface.IPFSLogEntry, error)

Append Appends an entry to the log Returns the latest Entry

payload is the data that will be in the Entry

func (*IPFSLog) Get

func (l *IPFSLog) Get(c cid.Cid) (Entry, bool)

func (*IPFSLog) GetEntries

func (l *IPFSLog) GetEntries() iface.IPFSLogOrderedEntries

func (*IPFSLog) GetID

func (l *IPFSLog) GetID() string

func (*IPFSLog) Has

func (l *IPFSLog) Has(c cid.Cid) bool

func (*IPFSLog) Heads

func (l *IPFSLog) Heads() iface.IPFSLogOrderedEntries

Heads Returns the heads of the log

Heads are the entries that are not referenced by other entries in the log

func (*IPFSLog) IO

func (l *IPFSLog) IO() IO

func (*IPFSLog) Iterator

func (l *IPFSLog) Iterator(options *IteratorOptions, output chan<- iface.IPFSLogEntry) error

Iterator Provides entries values on a channel

func (*IPFSLog) Join

func (l *IPFSLog) Join(otherLog iface.IPFSLog, size int) (iface.IPFSLog, error)

Join Joins the log with another log

Returns a log instance.

The size of the joined log can be specified by specifying the size argument, to include all values use -1

func (*IPFSLog) Len

func (l *IPFSLog) Len() int

func (*IPFSLog) RawHeads

func (l *IPFSLog) RawHeads() iface.IPFSLogOrderedEntries

func (*IPFSLog) SetIdentity

func (l *IPFSLog) SetIdentity(identity *identityprovider.Identity)

func (*IPFSLog) ToJSONLog

func (l *IPFSLog) ToJSONLog() *iface.JSONLog

ToJSON Returns a log in a JSON serializable structure

func (*IPFSLog) ToMultihash

func (l *IPFSLog) ToMultihash(ctx context.Context) (cid.Cid, error)

ToMultihash Returns the multihash of the log

Converting the log to a multihash will persist the contents of log.toJSON to IPFS, thus causing side effects

The supported format is defined by the log and a CIDv1 is returned

func (*IPFSLog) ToSnapshot

func (l *IPFSLog) ToSnapshot() *Snapshot

ToSnapshot exports a Snapshot-able version of the log

func (*IPFSLog) ToString

func (l *IPFSLog) ToString(payloadMapper func(iface.IPFSLogEntry) string) string

ToString Returns the log values as a nicely formatted string

payloadMapper is a function to customize text representation, use nil to use the default mapper which convert the payload as a string

func (*IPFSLog) Values

func (l *IPFSLog) Values() iface.IPFSLogOrderedEntries

Values Returns an Array of entries in the log

The values are in linearized order according to their Lamport clocks

type IteratorOptions

type IteratorOptions = iface.IteratorOptions

type JSONLog

type JSONLog = iface.JSONLog

type Log

type Log = iface.IPFSLog

type LogOptions

type LogOptions = iface.LogOptions

type Snapshot

type Snapshot = iface.Snapshot

type SortFn

type SortFn = iface.EntrySortFn

Source Files

Directories

Path Synopsis
Package accesscontroller defines a default access controller for IPFS Log, it won't actually check anything.
Package accesscontroller defines a default access controller for IPFS Log, it won't actually check anything.
Package entry defines the Entry structure for IPFS Log and its associated methods.
Package entry defines the Entry structure for IPFS Log and its associated methods.
sorting
Package sorting includes utilities for ordering slices of Entries.
Package sorting includes utilities for ordering slices of Entries.
Package errmsg defines error messages used by the Go version of IPFS Log.
Package errmsg defines error messages used by the Go version of IPFS Log.
example module
Package identityprovider defines a default identity provider for IPFS Log and OrbitDB.
Package identityprovider defines a default identity provider for IPFS Log and OrbitDB.
io
pb
Package keystore defines a local key manager for OrbitDB and IPFS Log.
Package keystore defines a local key manager for OrbitDB and IPFS Log.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to