holochain

package module
v0.0.0-...-5d3b5b6 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2017 License: GPL-3.0 Imports: 42 Imported by: 0

README

Holochain

Code Status Travis Go Report Card Gitter In Progress

Holographic storage for distributed applications. A holochain is a monotonic distributed hash table (DHT) where every node enforces validation rules on data before publishing that data against the signed chains where the data originated.

In other words, a holochain functions very much like a blockchain without bottlenecks when it comes to enforcing validation rules, but is designed to be fully distributed with each node only needing to hold a small portion of the data instead of everything needing a full copy of a global ledger. This makes it feasible to run blockchain-like applications on devices as lightweight as mobile phones.

Code Status: Active development for proof-of-concept stage. Pre-alpha. Not for production use. We still expect to destructively restructure data chains at this time. These instructions are really for developers who want to build distributed apps on holochains, not so much for end users who should probably use a nice packaged installation.

Holochain Links: FAQ Developer Wiki White Paper GoDocs

Table of Contents

Installation

  1. Make sure you have a working environment set up for the Go language version 1.7 or later. See the installation instructions for Go.
  2. Follow their instructions on the above doc page for exporting your $GOPATH and adding your $GOPATH/bin directory to your search PATH for programs. (Almost all installation problems that have been reported stem from skipping one of these path related steps.)
  3. Install the gx package manager:
$ go get -u github.com/whyrusleeping/gx
  1. Then you can install the holochain command line interface with:
$ go get -d github.com/metacurrency/holochain
$ cd $GOPATH/src/github.com/metacurrency/holochain
$ make

Make sure your PATH includes the $GOPATH/bin directory so the program it builds can be easily called:

$ export PATH=$PATH:$GOPATH/bin

Since holochain is essentially a data integrity engine intended to be used by distributed applications, you will normally only do some basic setup and maintenance through the command line.

Once you've gotten everything working as described above you can execute some basic holochain commands from the command line like this: hc help

And you can get help on specific sub commands with hc <cmd> help. For example: hc gen help

Installation on Windows
  1. Install Go 1.7.5.
  2. Install Windows git. Be sure to select the appropriate options so that git is accessible from the Windows command line.
  3. Install GnuWin32 make.Add C:\Program Files (x86)\GnuWin32\bin to your PATHS directory. (Make sure C:\go\bin is in your PATHS directory already, too)
  4. Click Start, type "System" and press Enter. Click "Advanced system settings" in the sidebar. Click "Environment Variables...". Under System Variables, click New..., and put GOPATH as the name, and the path to your Go installation in the value (usually C:\go).
  5. Now, double-click PATH under System Variables, and click New in the window that pops up. Add the path to go's bin directory as the value (usually C:\go\bin). This will allow you to run compiled executables from anywhere in the Windows command line.
  6. Now click New again time and add the path to your GnuWin32 make bin directory (usually C:\Program Files (x86)\GnuWin32\bin).
  7. Follow the remaining instructions starting at step 2 above. You should be able to use 'go' and 'make' from the Windows command line. (Add -x to the Go 'get' command to see verbose output as the packages download.)## Usage
Setting up a Holochain

You've installed and built the distributed data integrity engine, but you haven't set up an application running on it yet. The basic flow involved in getting a chain running looks like this:

  1. hc init
  2. hc clone
  3. hc test
  4. hc gen chain
  5. hc serve

Instructions for each of these steps are below...

1. Initializing Holochain Service for the First Time

The first time the holochain service is run, you need to create your default public/private keys, set up config files and directories, and set a default identity token for your participation on chains. As a general user, you should only need to do this once, but as a developer, you will need to do this if you remove your .holochain directory during testing and such.

Here's a full example of the initialization command, just substitute your own email address.

hc init 'pebbles@flintstone.com'
2. Getting Application DNA

You can use a pre-existing holochain application configuration by replacing SOURCE with path for loading existing application files. You can source from files anywhere such as from a git repo you've cloned, from a live chain you're already running in your .holochain directory, or one of the examples included in the holochain repository.

hc clone <SOURCE_PATH> <NAME_FOR_NEW_HOLOCHAIN>

For example: hc clone ./examples/sample sample

Before you launch your chain, this is the chance for you to customize the application settings like the NAME, and the UUID

3. Testing your Application

We have designed holochains to function around test-driven development, so each developer should have tests to confirm that you've built a functioning chain. Run the tests with;

hc test <HOLOCHAIN_NAME>

If the tests fail, then you know your application DNA is broken and you should not proceed thinking that your system is going to work. If you're a developer, you should be running this command as you make changes to your holochain DNA files to leverage test-driven development. And obviously, please do not send out applications that don't pass their own tests.

4. Generate New Chain

After you have cloned and/or completed development for your chain, you need to generate the genesis entries which start your new chain. The first entry is the DNA which is the hash of all the application code. This confirms every person's chain starts with the the same code/DNA. The second block registers your keys so you have an address, identity, and signing keys for communicating on the chain.

hc gen chain <HOLOCHAIN_NAME>
5. Launching the Holochain Server

Holochains service function requests via local web sockets. This let's interface developers have a lot of freedom to build html / javascript files and drop them in that chain's UI directory. You launch the service to listen on the socket on localhost with:

hc serve <HOLOCHAIN_NAME> [<PORT>]

In a web browser you can go to localhost:3141 (or whatever PORT you served it under) to access UI files and send and receive JSON with exposed application functions

Other Useful Commands
  • hc status to view all the chains on your system and their status
  • hc dump <HOLOCHAIN_NAME> to can inspect the contents of your local chain
File Locations

By default hc stores all holochain data and configuration files to the ~/.holochain directory. You can override this with the -path flag or by setting the HOLOPATH environment variable, e.g.:

hc -path ~/mychains init '<my@other.identity>'
HOLOPATH=~/mychains hc

You can use the form: hc -path=/your/path/here but you must use the absolute path, as shell substitutions will not happen

Logging

The -debug flag will turn on a number of different kinds of debugging. You can also control exactly which of these logging types you wish to see in the chain's config.json file. You can also set the DEBUG environment variable to 0 or 1 to temporarily override your settings to turn everything on or off.

Architecture Overview and Documentation

Start in the Holochain Wiki, and hopefully it will keep growing with good development resources.

You can also find the auto-generated Reference API for Holochain on GoDocs

Development -- In Progress

We accept Pull Requests and welcome your participation.

Throughput Graph

Dependencies

This project depends on various parts of libp2p, which uses the gx package manager. This means that installation doesn't follow the normal "go get" process but instead also requires a make step. Thus, to install the code and dependencies run:

go get github.com/metacurrency/holochain/
make deps

If you already installed the hc command line interface the dependencies will have been installed, and this step is unnecessary.

Note that make and make deps have a side-effect of re-writing some of the imports in various files. This is how gx handles dependencies on specific versions of go imports. But this means that when you are ready to make commits to your repo, you must undo these re-writes so they don't get committed to the repo. You can do this with:

make publish

After you have made your commit and are ready to continue working, you can redo those rewrites without re-running the full dependency install with:

make work
Tests

To compile and run all the tests:

cd $GOPATH/github.com/metacurrency/holochain
make test

Or if you have already done the initial make or make deps step, you can simply use go test as usual.

Contributor Guidelines
Tech
  • We use test driven development. Adding a new function or feature, should mean you've added the tests that make sure it works.
  • Set your editor to automatically use gofmt on save so there's no wasted discussion on proper indentation of brace style!
  • Contact us to set up a pair coding session with one of our developers to learn the lay of the land
  • join our dev documentation calls twice weekly on Tuesdays and Fridays.
Social -- Twitter Follow

We are committed to foster a vibrant thriving community, including growing a culture that breaks cycles of marginalization and dominance behavior. In support of this, some open source communities adopt Codes of Conduct. We are still working on our social protocols, and empower each team to describe its own Protocols for Inclusion. Until our teams have published their guidelines, please use the link above as a general guideline.

License

Copyright (C) 2017, The MetaCurrency Project (Eric Harris-Braun, Arthur Brock, et. al.)

This program is free software: you can redistribute it and/or modify it under the terms of the license provided in the LICENSE file (GPLv3). This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Note: We are considering other 'looser' licensing options (like MIT license) but at this stage are using GPL while we're getting the matter sorted out.

Acknowledgements

  • MetaCurrency & Ceptr: Holochains are a sub-project of Ceptr which is a semantic, distributed computing platform under development by the MetaCurrency Project.  
  • Ian Grigg: Some of our initial plans for this architecture were inspired in 2006 by his paper about Triple Entry Accounting and his work on Ricardian Contracts.  
  • Juan Benet: For all his work on IPFS and being a generally cool guy. Various functions like multihash, multiaddress, and such come from IPFS as well as the libP2P library which helped get peered node communications up and running.  
  • Crypto Pioneers And of course the people who paved the road before us by writing good crypto libraries and preaching the blockchain gospel. Back in 2008, nobody understood what we were talking about when we started sharing our designs. The main reason people want it now, is because blockchains have opened their eyes to the power of decentralized architectures.

Documentation

Overview

Holographic storage for distributed applications. A holochain is a monotonic distributed hash table (DHT) where every node enforces validation rules on data before publishing that data against the signed chains where the data originated.

In other words, a holochain functions very much like a blockchain without bottlenecks when it comes to enforcing validation rules, but is designed to be fully distributed with each node only needing to hold a small portion of the data instead of everything needing a full copy of a global ledger. This makes it feasible to run blockchain-like applications on devices as lightweight as mobile phones.

Two Subsystems

There are two modes to participate in a holochain: as a **chain author**, and as a **DHT node**. We expect most installations will be doing both things and acting as full peers in a P2P data system. However, each could be run in a separate container, communicating only by network interface.

Authoring your Local Chain

Your chain is your signed, sequential record of the data you create to share on the holochain. Depending on the holochain's validation rules, this data may also be immutable and non-repudiable. Your local chain/data-store follows this pattern:

  1. Validates your new data
  2. Stores the data in a new chain entry
  3. Signs it to your chain
  4. Indexes the content
  5. Shares it to the DHT
  6. Responds to validation requests from DHT nodes

DHT Node -- Validating and Publishing

For serving data shared across the network. When your node receives a request from another node to publish DHT data, it will first validate the signatures, chain links, and any other application specific data integrity in the entity's source chain who is publishing the data.

Installation and Usage

See http://github.com/metacurrency/holochain for installation instructions, project status, and developer information.

Holochains are a distributed data store: DHT tightly bound to signed hash chains for provenance and data integrity.

Index

Constants

View Source
const (
	SampleHTML = `` /* 678-byte string literal not displayed */

	SampleJS = `` /* 440-byte string literal not displayed */

)
View Source
const (
	PutNew = iota
	PutUpdate
	PutDelete
	PutUndelete
)
View Source
const (
	LIVE = iota
	REJECTED
	DELETED
	UPDATED
)
View Source
const (
	DNAEntryType = "_dna"
	KeyEntryType = "_key"
)
View Source
const (
	DataFormatJSON    = "json"
	DataFormatString  = "string"
	DataFormatRawJS   = "js"
	DataFormatRawZygo = "zygo"
)
View Source
const (
	DHTProtocol    = protocol.ID("/holochain-dht/0.0.0")
	SourceProtocol = protocol.ID("/holochain-src/0.0.0")
)
View Source
const (
	ID_PROPERTY         = "_id"
	AGENT_ID_PROPERTY   = "_agent_id"
	AGENT_NAME_PROPERTY = "_agent_name"
)
View Source
const (
	IDMetaKey  = "id"
	TopMetaKey = "top"

	MetaBucket   = "M"
	HeaderBucket = "H"
	EntryBucket  = "E"
)
View Source
const (
	DefaultDirectoryName string = ".holochain"  // Directory for storing config data
	DNAFileName          string = "dna"         // Definition of the Holochain
	ConfigFileName       string = "config"      // Settings of the Holochain
	SysFileName          string = "system.conf" // Server & System settings
	AgentFileName        string = "agent.txt"   // User ID info
	PrivKeyFileName      string = "priv.key"    // Signing key - private
	StoreFileName        string = "chain"       // Filename for local data store
	DNAHashFileName      string = "dna.hash"    // Filename for storing the hash of the holochain

	DefaultPort = 6283
)

System settings, directory, and file names

View Source
const (
	BoltPersisterName = "bolt"
)
View Source
const (
	IPFS = iota
)
View Source
const (
	JSLibrary = `var HC={STRING:0,JSON:1};version=` + `"` + VersionStr + `";`
)
View Source
const (
	JSNucleusType = "js"
)
View Source
const Version int = 2
View Source
const VersionStr string = "2"
View Source
const (
	ZygoLibrary = `(def STRING 0) (def JSON 1)`
)

These are the zygo implementations of the library functions that must available in all Nucleii implementations.

View Source
const (
	ZygoNucleusType = "zygo"
)

Variables

View Source
var ChangeAppProperty = Change{
	Type:    Deprecation,
	Message: "Getting special properties via property() is deprecated as of %d",
	AsOf:    2,
}
View Source
var ChangeRequires = Change{
	Type:    Warning,
	Message: "Zomes must define 'requires' function as of version %d, assuming no requirements.",
	AsOf:    2,
}
View Source
var Crash bool
View Source
var DEBUG bool
View Source
var ErrDHTErrNoGossipersAvailable error = errors.New("no gossipers available")
View Source
var ErrDHTExpectedGetReqInBody error = errors.New("expected get request")
View Source
var ErrDHTExpectedGossipReqInBody error = errors.New("expected gossip request")
View Source
var ErrDHTExpectedMetaQueryInBody error = errors.New("expected meta query")
View Source
var ErrDHTExpectedMetaReqInBody error = errors.New("expected meta request")
View Source
var ErrDHTExpectedPutReqInBody error = errors.New("expected put request")
View Source
var ErrHashNotFound error = errors.New("hash not found")
View Source
var SampleUI = map[string]string{
	"index.html": SampleHTML,
	"hc.js":      SampleJS,
}

Functions

func ByteDecoder

func ByteDecoder(b []byte, to interface{}) (err error)

ByteEncoder decodes data encoded by ByteEncoder

func ByteEncoder

func ByteEncoder(data interface{}) (b []byte, err error)

ByteEncoder encodes anything using gob

func CopyDir

func CopyDir(source string, dest string) (err error)

CopyDir recursively copies a directory tree, attempting to preserve permissions. Source directory must exist, destination directory must *not* exist.

func CopyFile

func CopyFile(source string, dest string) (err error)

CopyFile copies file source to destination dest.

func DHTReceiver

func DHTReceiver(h *Holochain, m *Message) (response interface{}, err error)

DHTReceiver handles messages on the dht protocol

func Debug

func Debug(m string)

func Debugf

func Debugf(m string, args ...interface{})

func Decode

func Decode(reader io.Reader, format string, data interface{}) (err error)

Decode extracts data from the reader according to the type

func Encode

func Encode(writer io.Writer, format string, data interface{}) (err error)

Encode encodes data to the writer according to the given format

func Info

func Info(m string)

func Infof

func Infof(m string, args ...interface{})

func IsInitialized

func IsInitialized(root string) bool

IsInitialized checks a path for a correctly set up .holochain directory

func LoadTestData

func LoadTestData(path string) (map[string][]TestData, error)

func MarshalEntry

func MarshalEntry(writer io.Writer, e Entry) (err error)

MarshalEntry serializes an entry to a writer

func MarshalHeader

func MarshalHeader(writer io.Writer, hd *Header) (err error)

MarshalHeader writes a header to a binary stream

func MarshalSignature

func MarshalSignature(writer io.Writer, s *Signature) (err error)

MarshalSignature writes a signature to a binary stream

func Panix

func Panix(on string)

func Register

func Register()

Register function that must be called once at startup by any client app

func RegisterBultinNucleii

func RegisterBultinNucleii()

RegisterBultinNucleii adds the built in nucleus types to the factory hash

func RegisterBultinPersisters

func RegisterBultinPersisters()

RegisterBultinPersisters adds the built in persister types to the factory hash

func RegisterNucleus

func RegisterNucleus(name string, factory NucleusFactory)

RegisterNucleus sets up a Nucleus to be used by the CreateNucleus function

func RegisterPersister

func RegisterPersister(name string, factory PersisterFactory)

RegisterPersister sets up a Persister to be used by the CreatePersister function

func SaveAgent

func SaveAgent(path string, agent Agent) (err error)

SaveAgent saves out the keys and agent name to the given directory

func ShouldLog

func ShouldLog(log *Logger, message string, fn func())

func SrcReceiver

func SrcReceiver(h *Holochain, m *Message) (response interface{}, err error)

SrcReceiver handles messages on the Source protocol

func ToString

func ToString(input interface{}) string

func UnmarshalHeader

func UnmarshalHeader(reader io.Reader, hd *Header, hashSize int) (err error)

UnmarshalHeader reads a Header from a binary stream

func UnmarshalSignature

func UnmarshalSignature(reader io.Reader, s *Signature) (err error)

UnmarshalSignature reads a Signature from a binary stream

Types

type Agent

type Agent interface {
	Name() AgentName
	KeyType() KeytypeType
	GenKeys() error
	PrivKey() ic.PrivKey
	PubKey() ic.PubKey
}

func LoadAgent

func LoadAgent(path string) (agent Agent, err error)

LoadAgent gets the agent and signing key from the specified directory

func NewAgent

func NewAgent(keyType KeytypeType, name AgentName) (agent Agent, err error)

NewAgent creates an agent structure of the given type Note: currently only IPFS agents are implemented

type AgentName

type AgentName string

Unique user identifier in context of this holochain

type BSReq

type BSReq struct {
	Version  int
	NodeID   string
	NodeAddr string
}

type BSResp

type BSResp struct {
	Req    BSReq
	Remote string
}

type BoltPersister

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

func (*BoltPersister) Close

func (bp *BoltPersister) Close()

Close closes the data store

func (*BoltPersister) DB

func (bp *BoltPersister) DB() *bolt.DB

DB returns the bolt db to give clients direct accesses to the bolt store

func (*BoltPersister) Get

func (bp *BoltPersister) Get(hash Hash, getEntry bool) (header Header, entry interface{}, e error)

Get returns a header, and (optionally) it's entry if getEntry is true

func (*BoltPersister) GetEntry

func (bp *BoltPersister) GetEntry(hash Hash) (entry interface{}, err error)

func (*BoltPersister) GetMeta

func (bp *BoltPersister) GetMeta(key string) (data []byte, err error)

GetMeta returns meta data

func (*BoltPersister) Init

func (bp *BoltPersister) Init() (err error)

Init opens the store (if it isn't already open) and initializes buckets

func (*BoltPersister) Name

func (bp *BoltPersister) Name() string

Name returns the data store name

func (*BoltPersister) Open

func (bp *BoltPersister) Open() (err error)

Open opens the data store

func (*BoltPersister) Put

func (bp *BoltPersister) Put(entryType string, headerHash Hash, header []byte, entryHash Hash, entry []byte) (err error)

Put stores an entry and its header N.B. this function does not confirm that the hashes match the values. That must be done external to the persister!

func (*BoltPersister) PutMeta

func (bp *BoltPersister) PutMeta(key string, value []byte) (err error)

PutMeta sets meta data

func (*BoltPersister) Remove

func (bp *BoltPersister) Remove() (err error)

Remove deletes all data in the datastore

type Chain

type Chain struct {
	Hashes   []Hash
	Headers  []*Header
	Entries  []Entry
	TypeTops map[string]int // pointer to index of top of a given type
	Hmap     map[string]int // map header hashes to index number
	Emap     map[string]int // map entry hashes to index number
	// contains filtered or unexported fields
}

Chain structure for providing in-memory access to chain data, entries headers and hashes

func NewChain

func NewChain() (chain *Chain)

NewChain creates and empty chain

func NewChainFromFile

func NewChainFromFile(h HashSpec, path string) (c *Chain, err error)

Creates a chain from a file, loading any data there, and setting it to be persisted to if no file exists it will be created

func UnmarshalChain

func UnmarshalChain(reader io.Reader) (c *Chain, err error)

UnmarshalChain unserializes a chain from a reader

func (*Chain) AddEntry

func (c *Chain) AddEntry(h HashSpec, now time.Time, entryType string, e Entry, key ic.PrivKey) (hash Hash, err error)

AddEntry creates a new header and adds it to a chain

func (*Chain) Get

func (c *Chain) Get(h Hash) (header *Header, err error)

Get returns the header of a given hash

func (*Chain) GetEntry

func (c *Chain) GetEntry(h Hash) (entry Entry, entryType string, err error)

GetEntry returns the entry of a given entry hash

func (*Chain) GetEntryHeader

func (c *Chain) GetEntryHeader(h Hash) (header *Header, err error)

GetEntryHeader returns the header of a given entry hash

func (*Chain) MarshalChain

func (c *Chain) MarshalChain(writer io.Writer) (err error)

MarshalChain serializes a chain data to a writer

func (*Chain) PrepareHeader

func (c *Chain) PrepareHeader(h HashSpec, now time.Time, entryType string, e Entry, key ic.PrivKey) (entryIdx int, hash Hash, header *Header, err error)

func (*Chain) String

func (c *Chain) String() string

String converts a chain to a textual dump of the headers and entries

func (*Chain) Top

func (c *Chain) Top() (header *Header)

Top returns the latest header

func (*Chain) TopType

func (c *Chain) TopType(entryType string) (hash *Hash, header *Header)

TopType returns the latest header of a given type

func (*Chain) Validate

func (c *Chain) Validate(h HashSpec) (err error)

Validate traverses chain confirming the hashes @TODO confirm that TypeLinks are also correct @TODO confirm signatures

func (*Chain) Walk

func (c *Chain) Walk(fn WalkerFn) (err error)

Walk traverses chain from most recent to first entry calling fn on each one

type Change

type Change struct {
	Type    ChangeType
	Message string
	AsOf    int
}

Change represents a semantic change that needs to be reported

func (*Change) Log

func (c *Change) Log()

type ChangeType

type ChangeType int8
const (
	Deprecation ChangeType = iota
	Warning
)

type Config

type Config struct {
	Port            int
	PeerModeAuthor  bool
	PeerModeDHTNode bool
	BootstrapServer string
	Loggers         Loggers
}

Config holds the non-DNA configuration for a holo-chain

type DHT

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

DHT struct holds the data necessary to run the distributed hash table

func NewDHT

func NewDHT(h *Holochain) *DHT

NewDHT creates a new DHT structure

func (*DHT) FindGossiper

func (dht *DHT) FindGossiper() (g *Gossiper, err error)

FindGossiper picks a random DHT node to gossip with

func (*DHT) FindNodeForHash

func (dht *DHT) FindNodeForHash(key Hash) (n *Node, err error)

FindNodeForHash gets the nearest node to the neighborhood of the hash

func (*DHT) GetGossiper

func (dht *DHT) GetGossiper(id peer.ID) (idx int, err error)

GetGossiper picks a random DHT node to gossip with

func (*DHT) GetIdx

func (dht *DHT) GetIdx() (idx int, err error)

GetIdx returns the current put index for gossip

func (*DHT) GetPuts

func (dht *DHT) GetPuts(since int) (puts []Put, err error)

GetPuts returns a list of puts after the given index

func (*DHT) Gossip

func (dht *DHT) Gossip(interval time.Duration)

Gossip gossips every interval

func (*DHT) HandlePutReqs

func (dht *DHT) HandlePutReqs() (err error)

HandlePutReqs waits on a chanel for messages to handle

func (*DHT) SendGet

func (dht *DHT) SendGet(key Hash) (response interface{}, err error)

SendGet initiates retrieving a value from the DHT

func (*DHT) SendGetMeta

func (dht *DHT) SendGetMeta(query MetaQuery) (response interface{}, err error)

SendGetMeta initiates retrieving meta data from the DHT

func (*DHT) SendPut

func (dht *DHT) SendPut(key Hash) (err error)

SendPut initiates publishing a particular Hash to the DHT. This command only sends the hash, because the expectation is that DHT nodes will start to communicate back to Source node (the node that makes this call) to get the data for validation

func (*DHT) SendPutMeta

func (dht *DHT) SendPutMeta(req MetaReq) (err error)

SendPutMeta initiates associating Meta data with particular Hash on the DHT. This command assumes that the data has been committed to your local chain, and the hash of that data is what get's sent in the MetaReq

func (*DHT) SetupDHT

func (dht *DHT) SetupDHT() (err error)

SetupDHT prepares a DHT for use by adding the holochain's ID

func (*DHT) StartDHT

func (dht *DHT) StartDHT() (err error)

StartDHT initiates listening for DHT protocol messages on the node

func (*DHT) UpdateGossiper

func (dht *DHT) UpdateGossiper(id peer.ID, count int) (err error)

UpdateGossiper updates a gossiper

type Entry

type Entry interface {
	Marshal() ([]byte, error)
	Unmarshal([]byte) error
	Content() interface{}
	Sum(s HashSpec) (hash Hash, err error)
}

Entry describes serialization and deserialziation of entry data

func UnmarshalEntry

func UnmarshalEntry(reader io.Reader) (e Entry, err error)

UnmarshalEntry unserializes an entry from a reader

type EntryDef

type EntryDef struct {
	Name       string
	DataFormat string
	Schema     string // file name of schema or language schema directive
	SchemaHash Hash
	// contains filtered or unexported fields
}

EntryDef struct holds an entry definition

func (*EntryDef) BuildJSONSchemaValidator

func (d *EntryDef) BuildJSONSchemaValidator(path string) (err error)

BuildJSONSchemaValidator builds a validator in an EntryDef

type GetReq

type GetReq struct {
	H Hash
}

GetReq holds the data of a put request

type GobEntry

type GobEntry struct {
	C interface{}
}

GobEntry is a structure for implementing Gob encoding of Entry content

func (*GobEntry) Content

func (e *GobEntry) Content() interface{}

func (*GobEntry) Marshal

func (e *GobEntry) Marshal() (b []byte, err error)

func (*GobEntry) Sum

func (e *GobEntry) Sum(s HashSpec) (h Hash, err error)

func (*GobEntry) Unmarshal

func (e *GobEntry) Unmarshal(b []byte) (err error)

type Gossip

type Gossip struct {
	Puts []Put
}

Gossip holds a gossip message

type GossipReq

type GossipReq struct {
	MyIdx   int
	YourIdx int
}

GossipReq holds a gossip request

type Gossiper

type Gossiper struct {
	Id       peer.ID
	Idx      int
	LastSeen time.Time
}

Gossiper holds data about a gossiper

type Hash

type Hash struct {
	H mh.Multihash
}

Hash of Entry's Content

func NewHash

func NewHash(s string) (h Hash, err error)

NewHash builds a Hash from a b58 string encoded hash

func NullHash

func NullHash() (h Hash)

NullHash builds a null valued hash

func (*Hash) Clone

func (h *Hash) Clone() (hash Hash)

Clone returns a copy of a hash

func (*Hash) Equal

func (h1 *Hash) Equal(h2 *Hash) bool

Equal checks to see if two hashes have the same value

func (*Hash) IsNullHash

func (h *Hash) IsNullHash() bool

IsNullHash checks to see if this hash's value is the null hash

func (*Hash) MarshalHash

func (h *Hash) MarshalHash(writer io.Writer) (err error)

MarshalHash writes a hash to a binary stream

func (Hash) String

func (h Hash) String() string

String encodes a hash to a human readable string

func (*Hash) Sum

func (h *Hash) Sum(hc HashSpec, data []byte) (err error)

Sum builds a digest according to the specs in the Holochain

func (*Hash) UnmarshalHash

func (h *Hash) UnmarshalHash(reader io.Reader) (err error)

UnmarshalHash reads a hash from a binary stream

type HashSpec

type HashSpec struct {
	Code   uint64
	Length int
}

HashSpec holds the info that tells what kind of hash this is

type Header struct {
	Type       string
	Time       time.Time
	HeaderLink Hash // link to previous header
	EntryLink  Hash // link to entry
	TypeLink   Hash // link to header of previous header of this type
	Sig        Signature
}

Header holds chain links, type, timestamp and signature

func (*Header) Marshal

func (hd *Header) Marshal() (b []byte, err error)

Marshal writes a header to bytes

func (*Header) Sum

func (hd *Header) Sum(spec HashSpec) (hash Hash, b []byte, err error)

Sum encodes and creates a hash digest of the header

func (*Header) Unmarshal

func (hd *Header) Unmarshal(b []byte, hashSize int) (err error)

Unmarshal reads a header from bytes

type Holochain

type Holochain struct {
	Version          int
	Id               uuid.UUID
	Name             string
	Properties       map[string]string
	PropertiesSchema string
	HashType         string
	BasedOn          Hash // holochain hash for base schemas and code
	Zomes            map[string]*Zome
	// contains filtered or unexported fields
}

Holochain struct holds the full "DNA" of the holochain

func DecodeDNA

func DecodeDNA(reader io.Reader, format string) (hP *Holochain, err error)

DecodeDNA decodes a Holochain structure from an io.Reader

func NewHolochain

func NewHolochain(agent Agent, path string, format string, zomes ...Zome) Holochain

NewHolochain creates a new holochain structure with a randomly generated ID and default values

func (*Holochain) Activate

func (h *Holochain) Activate() (err error)

Activate fires up the holochain node

func (*Holochain) Agent

func (h *Holochain) Agent() Agent

Agent exposes the agent element

func (*Holochain) BSget

func (h *Holochain) BSget() (err error)

func (*Holochain) BSpost

func (h *Holochain) BSpost() (err error)

func (*Holochain) Call

func (h *Holochain) Call(zomeType string, function string, arguments interface{}) (result interface{}, err error)

Call executes an exposed function

func (*Holochain) DHT

func (h *Holochain) DHT() *DHT

DHT exposes the DHT structure

func (*Holochain) DNAhash

func (h *Holochain) DNAhash() (id Hash)

DNAhash returns the hash of the DNA entry which is also the holochain ID

func (*Holochain) EncodeDNA

func (h *Holochain) EncodeDNA(writer io.Writer) (err error)

EncodeDNA encodes a holochain's DNA to an io.Writer

func (*Holochain) GenChain

func (h *Holochain) GenChain() (keyHash Hash, err error)

GenChain establishes a holochain instance by creating the initial genesis entries in the chain It assumes a properly set up .holochain sub-directory with a config file and keys for signing. See GenDev()

func (*Holochain) GenDNAHashes

func (h *Holochain) GenDNAHashes() (err error)

GenDNAHashes generates hashes for all the definition files in the DNA. This function should only be called by developer tools at the end of the process of finalizing DNA development or versioning

func (*Holochain) GetEntryDef

func (h *Holochain) GetEntryDef(t string) (zome *Zome, d *EntryDef, err error)

GetEntryDef returns an EntryDef of the given name

func (*Holochain) GetProperty

func (h *Holochain) GetProperty(prop string) (property string, err error)

GetProperty returns the value of a DNA property

func (*Holochain) HashSpec

func (h *Holochain) HashSpec() HashSpec

HashSpec exposes the hashSpec structure

func (*Holochain) MakeNucleus

func (h *Holochain) MakeNucleus(t string) (n Nucleus, err error)

MakeNucleus creates a Nucleus object based on the zome type

func (*Holochain) NewEntry

func (h *Holochain) NewEntry(now time.Time, entryType string, entry Entry) (hash Hash, header *Header, err error)

NewEntry adds an entry and it's header to the chain and returns the header and it's hash

func (*Holochain) Path

func (h *Holochain) Path() string

Path returns a holochain path

func (*Holochain) Prepare

func (h *Holochain) Prepare() (err error)

Prepare sets up a holochain to run by: validating the DNA, loading the schema validators, setting up a Network node and setting up the DHT

func (*Holochain) PrepareHashType

func (h *Holochain) PrepareHashType() (err error)

PrepareHashType makes sure the given string is a correct multi-hash and stores the code and length to the Holochain struct

func (*Holochain) Reset

func (h *Holochain) Reset() (err error)

Reset deletes all chain and dht data and resets data structures

func (*Holochain) SaveDNA

func (h *Holochain) SaveDNA(overwrite bool) (err error)

SaveDNA writes the holochain DNA to a file

func (*Holochain) Send

func (h *Holochain) Send(proto protocol.ID, to peer.ID, t MsgType, body interface{}, receiver ReceiverFn) (response interface{}, err error)

Send builds a message and either delivers it locally or via node.Send

func (*Holochain) Started

func (h *Holochain) Started() bool

Started returns true if the chain has been gened

func (*Holochain) Test

func (h *Holochain) Test() []error

Test loops through each of the test files calling the functions specified This function is useful only in the context of developing a holochain and will return an error if the chain has already been started (i.e. has genesis entries)

func (*Holochain) TestStringReplacements

func (h *Holochain) TestStringReplacements(input, r1, r2, r3 string) string

func (*Holochain) Top

func (h *Holochain) Top() (top Hash, err error)

Top returns a hash of top header or err if not yet defined

func (*Holochain) Validate

func (h *Holochain) Validate(entriesToo bool) (valid bool, err error)

Validate scans back through a chain to the beginning confirming that the last header points to DNA This is actually kind of bogus on your own chain, because theoretically you put it there! But if the holochain file was copied from somewhere you can consider this a self-check

func (*Holochain) ValidateEntry

func (h *Holochain) ValidateEntry(entryType string, entry Entry, props *ValidationProps) (err error)

ValidateEntry passes an entry data to the chain's validation routine If the entry is valid err will be nil, otherwise it will contain some information about why the validation failed (or, possibly, some other system error)

func (*Holochain) Walk

func (h *Holochain) Walk(fn WalkerFn, entriesToo bool) (err error)

func(key *Hash, h *Header, entry interface{}) error

type HolochainRouter

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

func (*HolochainRouter) FindPeer

func (r *HolochainRouter) FindPeer(context.Context, peer.ID) (peer pstore.PeerInfo, err error)

type IPFSAgent

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

func (*IPFSAgent) GenKeys

func (a *IPFSAgent) GenKeys() (err error)

func (*IPFSAgent) KeyType

func (a *IPFSAgent) KeyType() KeytypeType

func (*IPFSAgent) Name

func (a *IPFSAgent) Name() AgentName

func (*IPFSAgent) PrivKey

func (a *IPFSAgent) PrivKey() ic.PrivKey

func (*IPFSAgent) PubKey

func (a *IPFSAgent) PubKey() ic.PubKey

type Interface

type Interface struct {
	Name   string
	Schema InterfaceSchemaType
}

Interface holds the name and schema of an DNA exposed function

type InterfaceSchemaType

type InterfaceSchemaType int
const (
	STRING InterfaceSchemaType = iota
	JSON
)

func InterfaceSchema

func InterfaceSchema(n Nucleus, name string) (InterfaceSchemaType, error)

InterfaceSchema returns a functions schema type

type JSNucleus

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

func (*JSNucleus) Call

func (z *JSNucleus) Call(iface string, params interface{}) (result interface{}, err error)

Call calls the zygo function that was registered with expose

func (*JSNucleus) ChainGenesis

func (z *JSNucleus) ChainGenesis() (err error)

ChainGenesis runs the application genesis function this function gets called after the genesis entries are added to the chain

func (*JSNucleus) ChainRequires

func (z *JSNucleus) ChainRequires() (err error)

ChainReqires runs the application requires function this function gets called so that the holochain library can confirm that it is capable of servicing the needs of the application.

func (*JSNucleus) GetInterface

func (z *JSNucleus) GetInterface(iface string) (i *Interface, err error)

GetInterface returns an Interface of the given name

func (*JSNucleus) Interfaces

func (z *JSNucleus) Interfaces() (i []Interface)

Interfaces returns the list of application exposed functions the nucleus

func (*JSNucleus) Run

func (z *JSNucleus) Run(code string) (result *otto.Value, err error)

Run executes javascript code

func (*JSNucleus) Type

func (z *JSNucleus) Type() string

Name returns the string value under which this nucleus is registered

func (*JSNucleus) ValidateEntry

func (z *JSNucleus) ValidateEntry(d *EntryDef, entry Entry, props *ValidationProps) (err error)

ValidateEntry checks the contents of an entry against the validation rules this is the zgo implementation

type JSONEntry

type JSONEntry struct {
	C interface{}
}

JSONEntry is a structure for implementing JSON encoding of Entry content

func (*JSONEntry) Content

func (e *JSONEntry) Content() interface{}

func (*JSONEntry) Marshal

func (e *JSONEntry) Marshal() (b []byte, err error)

func (*JSONEntry) Unmarshal

func (e *JSONEntry) Unmarshal(b []byte) (err error)

type JSONSchemaValidator

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

func (*JSONSchemaValidator) Validate

func (v *JSONSchemaValidator) Validate(entry interface{}) (err error)

type KeyEntry

type KeyEntry struct {
	Name    AgentName
	KeyType KeytypeType
	Key     []byte // marshaled public key
}

KeyEntry structure for building KeyEntryType entries

type KeytypeType

type KeytypeType int

type Logger

type Logger struct {
	Enabled bool
	Format  string
	// contains filtered or unexported fields
}

Logger holds logger configuration

func (*Logger) Log

func (l *Logger) Log(m interface{})

func (*Logger) Logf

func (l *Logger) Logf(m string, args ...interface{})

func (*Logger) New

func (l *Logger) New(w io.Writer) (err error)

type Loggers

type Loggers struct {
	App        Logger
	DHT        Logger
	Gossip     Logger
	TestPassed Logger
	TestFailed Logger
	TestInfo   Logger
}

Loggers holds the logging structures for the different parts of the system

type Message

type Message struct {
	Type MsgType
	Time time.Time
	From peer.ID
	Body interface{}
}

Message represents data that can be sent to node in the network

func (*Message) Decode

func (m *Message) Decode(r io.Reader) (err error)

Decode converts a message from gob format @TODO generalize for other message encoding formats

func (*Message) Encode

func (m *Message) Encode() (data []byte, err error)

Encode codes a message to gob format @TODO generalize for other message encoding formats

type Meta

type Meta struct {
	H Hash   // hash of meta-data associated
	T string // meta-data type identifier
	V []byte // meta-data
}

Meta holds data that can be associated with a hash @todo, we should also be storing the meta-data source

type MetaEntry

type MetaEntry struct {
	E Entry
	H string
}

MetaEntry holds associated entries

type MetaQuery

type MetaQuery struct {
	H Hash
	T string
}

MetaQuery holds a getMeta query

type MetaQueryResp

type MetaQueryResp struct {
	Entries []MetaEntry
}

MetaQueryResp holds response to getMeta query

type MetaReq

type MetaReq struct {
	O Hash   // original data on which to put the meta
	M Hash   // hash of the meta-data
	T string // type of the meta-data
}

MetaReq holds a putMeta request

type MsgType

type MsgType int8
const (
	ERROR_RESPONSE MsgType = iota
	OK_RESPONSE

	PUT_REQUEST
	GET_REQUEST
	PUTMETA_REQUEST
	GETMETA_REQUEST
	GOSSIP_REQUEST
	GOSSIP

	SRC_VALIDATE
)

type Node

type Node struct {
	HashAddr peer.ID
	NetAddr  ma.Multiaddr
	Host     *rhost.RoutedHost
}

Node represents a node in the network

func NewNode

func NewNode(listenAddr string, id peer.ID, priv ic.PrivKey) (node *Node, err error)

NewNode creates a new ipfs basichost node with given identity

func (*Node) Close

func (node *Node) Close() error

Close shuts down the node

func (*Node) NewMessage

func (node *Node) NewMessage(t MsgType, body interface{}) (msg *Message)

NewMessage creates a message from the node with a new current timestamp

func (*Node) Send

func (node *Node) Send(proto protocol.ID, addr peer.ID, m *Message) (response Message, err error)

Send delivers a message to a node via the given protocol

func (*Node) StartProtocol

func (node *Node) StartProtocol(h *Holochain, proto protocol.ID, receiver ReceiverFn) (err error)

StartProtocol initiates listening for a protocol on the node

func (*Node) StartSrc

func (node *Node) StartSrc(h *Holochain) (err error)

StartSrc initiates listening for Source protocol messages on the node

type Nucleus

type Nucleus interface {
	Type() string
	ValidateEntry(def *EntryDef, entry Entry, props *ValidationProps) error
	ChainGenesis() error
	ChainRequires() error

	Interfaces() (i []Interface)
	Call(iface string, params interface{}) (interface{}, error)
	// contains filtered or unexported methods
}

Nucleus type abstracts the functions of code execution environments

func CreateNucleus

func CreateNucleus(h *Holochain, nucleusType string, code string) (Nucleus, error)

CreateNucleus returns a new Nucleus of the given type

func NewJSNucleus

func NewJSNucleus(h *Holochain, code string) (n Nucleus, err error)

NewJSNucleus builds a javascript execution environment with user specified code

func NewZygoNucleus

func NewZygoNucleus(h *Holochain, code string) (n Nucleus, err error)

NewZygoNucleus builds an zygo execution environment with user specified code

type NucleusFactory

type NucleusFactory func(h *Holochain, code string) (Nucleus, error)

type Persister

type Persister interface {
	Open() error
	Close()
	Init() error
	GetMeta(string) ([]byte, error)
	PutMeta(key string, value []byte) (err error)
	Put(entryType string, headerHash Hash, header []byte, entryHash Hash, entry []byte) (err error)
	Get(hash Hash, getEntry bool) (header Header, entry interface{}, err error)
	GetEntry(hash Hash) (entry interface{}, err error)
	Remove() error
	Name() string
}

func CreatePersister

func CreatePersister(ptype string, config string) (Persister, error)

CreatePersister returns a new Persister of the given type

func NewBoltPersister

func NewBoltPersister(path string) (p Persister, err error)

NewBoltPersister returns a Bolt implementation of the Persister type always return no error because in this case any errors would happen at Init or Open time

type PersisterFactory

type PersisterFactory func(config string) (Persister, error)

type Put

type Put struct {
	M Message
}

Put holds a put or putmeta for gossiping

type PutReq

type PutReq struct {
	H Hash
	S int
	D interface{}
}

PutReq holds the data of a put request

type ReceiverFn

type ReceiverFn func(h *Holochain, m *Message) (response interface{}, err error)

type SchemaValidator

type SchemaValidator interface {
	Validate(interface{}) error
}

SchemaValidator interface for schema validation

type Service

type Service struct {
	Settings     ServiceConfig
	DefaultAgent Agent
	Path         string
}

Holochain service data structure

func Init

func Init(root string, agent AgentName) (service *Service, err error)

Init initializes service defaults including a signing key pair for an agent and writes them out to configuration files in the root path (making the directory if necessary)

func LoadService

func LoadService(path string) (service *Service, err error)

LoadService creates a service object from a configuration file

func (*Service) Clone

func (s *Service) Clone(srcPath string, path string, new bool) (hP *Holochain, err error)

Clone copies DNA files from a source

func (*Service) ConfiguredChains

func (s *Service) ConfiguredChains() (chains map[string]*Holochain, err error)

ConfiguredChains returns a list of the configured chains for the given service

func (*Service) GenDev

func (s *Service) GenDev(path string, format string) (hP *Holochain, err error)

GenDev generates starter holochain DNA files from which to develop a chain

func (*Service) IsConfigured

func (s *Service) IsConfigured(name string) (f string, err error)

IsConfigured checks a directory for correctly set up holochain configuration files

func (*Service) Load

func (s *Service) Load(name string) (h *Holochain, err error)

Load instantiates a Holochain instance

type ServiceConfig

type ServiceConfig struct {
	DefaultPeerModeAuthor  bool
	DefaultPeerModeDHTNode bool
	DefaultBootstrapServer string
}

ServiceConfig holds the service settings

type Signature

type Signature struct {
	S []byte
}

type TestData

type TestData struct {
	Zome   string
	FnName string
	Input  string
	Output string
	Err    string
	Regexp string
}

TestData holds a test entry for a chain

type ValidateResponse

type ValidateResponse struct {
	Entry Entry
	Type  string
}

type ValidationProps

type ValidationProps struct {
	Sources  []string // B58 encoded peer
	Hash     string
	MetaTag  string // if validating a putMeta this will have the meta type set
	MetaHash string
}

ValidationProps holds the properties passed to the application validation routine This includes the Headers and Sources

type WalkerFn

type WalkerFn func(key *Hash, header *Header, entry Entry) error

WalkerFn a function type for call Walk

type Zome

type Zome struct {
	Name        string
	Description string
	Code        string // file name of DNA code
	CodeHash    Hash
	Entries     map[string]EntryDef
	NucleusType string
}

Zome struct encapsulates logically related code, from "chromosome"

type ZygoNucleus

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

func (*ZygoNucleus) Call

func (z *ZygoNucleus) Call(iface string, params interface{}) (result interface{}, err error)

Call calls the zygo function that was registered with expose

func (*ZygoNucleus) ChainGenesis

func (z *ZygoNucleus) ChainGenesis() (err error)

ChainGenesis runs the application genesis function this function gets called after the genesis entries are added to the chain

func (*ZygoNucleus) ChainRequires

func (z *ZygoNucleus) ChainRequires() (err error)

ChainReqires runs the application requires function this function gets called so that the holochain library can confirm that it is capable of servicing the needs of the application.

func (*ZygoNucleus) GetInterface

func (z *ZygoNucleus) GetInterface(iface string) (i *Interface, err error)

GetInterface returns an Interface of the given name

func (*ZygoNucleus) Interfaces

func (z *ZygoNucleus) Interfaces() (i []Interface)

Interfaces returns the list of application exposed functions the nucleus

func (*ZygoNucleus) Run

func (z *ZygoNucleus) Run(code string) (result zygo.Sexp, err error)

Run executes zygo code

func (*ZygoNucleus) Type

func (z *ZygoNucleus) Type() string

Name returns the string value under which this nucleus is registered

func (*ZygoNucleus) ValidateEntry

func (z *ZygoNucleus) ValidateEntry(d *EntryDef, entry Entry, props *ValidationProps) (err error)

ValidateEntry checks the contents of an entry against the validation rules

Directories

Path Synopsis
cmd
bs
hc

Jump to

Keyboard shortcuts

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