mapstate

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package mapstate implements the State interface for IPFS Cluster by using a map to keep track of the consensus-shared state.

Index

Constants

View Source
const Version = 4

Version is the map state Version. States with old versions should perform an upgrade before.

Variables

This section is empty.

Functions

This section is empty.

Types

type MapState

type MapState struct {
	PinMap  map[string]api.PinSerial
	Version int
	// contains filtered or unexported fields
}

MapState is a very simple database to store the state of the system using a Go map. It is thread safe. It implements the State interface.

func NewMapState

func NewMapState() *MapState

NewMapState initializes the internal map and returns a new MapState object.

func (*MapState) Add

func (st *MapState) Add(c api.Pin) error

Add adds a Pin to the internal map.

func (*MapState) Get

func (st *MapState) Get(c *cid.Cid) api.Pin

Get returns Pin information for a CID. The returned object has its Cid and Allocations fields initialized, regardless of the presence of the provided Cid in the state. To check the presence, use MapState.Has(*cid.Cid).

func (*MapState) GetVersion added in v0.3.1

func (st *MapState) GetVersion() int

GetVersion returns the current version of this state object. It is not necessarily up to date

func (*MapState) Has

func (st *MapState) Has(c *cid.Cid) bool

Has returns true if the Cid belongs to the State.

func (*MapState) List

func (st *MapState) List() []api.Pin

List provides the list of tracked Pins.

func (*MapState) Marshal added in v0.3.1

func (st *MapState) Marshal() ([]byte, error)

Marshal encodes the state using msgpack

func (*MapState) Migrate added in v0.3.2

func (st *MapState) Migrate(r io.Reader) error

Migrate restores a snapshot from the state's internal bytes and if necessary migrates the format to the current version.

func (*MapState) Rm

func (st *MapState) Rm(c *cid.Cid) error

Rm removes a Cid from the internal map.

func (*MapState) Unmarshal added in v0.3.1

func (st *MapState) Unmarshal(bs []byte) error

Unmarshal decodes the state using msgpack. It first decodes just the version number. If this is not the current version the bytes are stored within the state's internal reader, which can be migrated to the current version in a later call to restore. Note: Out of date version is not an error

Jump to

Keyboard shortcuts

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