bcgo

package module
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2021 License: Apache-2.0 Imports: 26 Imported by: 27

README

bcgo

This is a Go implementation of a blockchain using the BC data structures defined in Protobufs.

Build

go build

Documentation

Overview

Package containing utilities for BC in Go

Index

Examples

Constants

View Source
const (
	THRESHOLD_Z = 0
	THRESHOLD_I = 256 // (32 / 64) * 512 // Hash Space: 2 ^ 256 // Usage: General Purpose
	THRESHOLD_H = 272 // (34 / 64) * 512 // Hash Space: 2 ^ 240 // Usage: General Purpose
	THRESHOLD_G = 288 // (36 / 64) * 512 // Hash Space: 2 ^ 224 // Usage: General Purpose, Alias
	THRESHOLD_F = 304 // (38 / 64) * 512 // Hash Space: 2 ^ 208 // Usage: Hour Validation
	THRESHOLD_E = 320 // (40 / 64) * 512 // Hash Space: 2 ^ 192 // Usage: Day Validation
	THRESHOLD_D = 336 // (42 / 64) * 512 // Hash Space: 2 ^ 176 // Usage: Week Validation
	THRESHOLD_C = 352 // (44 / 64) * 512 // Hash Space: 2 ^ 160 // Usage: Year Validation
	THRESHOLD_B = 368 // (46 / 64) * 512 // Hash Space: 2 ^ 144 // Usage: Decade Validation
	THRESHOLD_A = 384 // (48 / 64) * 512 // Hash Space: 2 ^ 128 // Usage: Century Validation

	MAX_BLOCK_SIZE_BYTES   = uint64(2 * 1024 * 1024 * 1024) // 2Gb
	MAX_PAYLOAD_SIZE_BYTES = uint64(10 * 1024 * 1024)       // 10Mb
)
View Source
const (
	BC_HOST      = "bc.aletheiaware.com"
	BC_HOST_TEST = "test-bc.aletheiaware.com"

	BETA_FLAG = "BETA"
	LIVE_FLAG = "LIVE"
)
View Source
const (
	ERROR_CHAIN_INVALID   = "Chain invalid: %s"
	ERROR_CHAIN_TOO_SHORT = "Chain too short to replace current head: %d vs %d"
	ERROR_HASH_INCORRECT  = "Hash doesn't match block hash"
	ERROR_NAME_INCORRECT  = "Name doesn't match channel name: %s vs %s"
	ERROR_NAME_INVALID    = "Name invalid: %s"
)
View Source
const (
	ERROR_BLOCK_NOT_FOUND                   = "Block not found %s"
	ERROR_HEAD_NOT_FOUND                    = "Head not found %s"
	ERROR_RECORD_TO_BLOCK_MAPPING_NOT_FOUND = "Record to Block Mapping not found %s"
)
View Source
const (
	ERROR_NO_ENTRIES_TO_MINE = "No entries to mine for channel: %s"
	ERROR_NO_SUCH_CHANNEL    = "No such channel: %s"
	ERROR_PAYLOAD_TOO_LARGE  = "Payload too large: %s max: %s"
	ERROR_BLOCK_TOO_LARGE    = "Block too large: %s max: %s"
	ERROR_NONCE_WRAP_AROUND  = "Nonce wrapped around before reaching threshold"
)
View Source
const (
	ERROR_MISSING_VALIDATED_BLOCK = "Missing Validated Block %s"

	PERIOD_HOURLY       = time.Hour
	PERIOD_DAILY        = PERIOD_HOURLY * 24
	PERIOD_WEEKLY       = PERIOD_HOURLY * 168    // (24 * 7)
	PERIOD_YEARLY       = PERIOD_HOURLY * 8766   // (24 * 365.25)
	PERIOD_DECENNIALLY  = PERIOD_HOURLY * 87660  // (24 * 365.25 * 10)
	PERIOD_CENTENNIALLY = PERIOD_HOURLY * 876600 // (24 * 365.25 * 100)

	THRESHOLD_PERIOD_HOUR    = THRESHOLD_F
	THRESHOLD_PERIOD_DAY     = THRESHOLD_E
	THRESHOLD_PERIOD_WEEK    = THRESHOLD_D
	THRESHOLD_PERIOD_YEAR    = THRESHOLD_C
	THRESHOLD_PERIOD_DECADE  = THRESHOLD_B
	THRESHOLD_PERIOD_CENTURY = THRESHOLD_A
)
View Source
const (
	MAX_TCP_ERRORS = 10
	TIMEOUT        = 3 * time.Minute
	PORT_CONNECT   = 22022
	PORT_GET_BLOCK = 22222
	PORT_GET_HEAD  = 22322
	PORT_BROADCAST = 23232
)
View Source
const (
	ERROR_DUPLICATE_BLOCK = "Duplicate Block: %s"
	ERROR_DUPLICATE_ENTRY = "Duplicate Entry: %s"
)
View Source
const (
	ERROR_CHANNEL_OUT_OF_DATE = "Channel out of date"
)
View Source
const (
	ERROR_DIFFERENT_LIVE_FLAG = "Different Live Flag; Expected '%s', got '%s'"
)
View Source
const (
	ERROR_HASH_TOO_WEAK = "Hash doesn't meet Proof-of-Work threshold: %d vs %d"
)

Variables

This section is empty.

Functions

func AddPeer

func AddPeer(directory, peer string) error

func BinarySizeToString

func BinarySizeToString(size uint64) string

func CreateRecords

func CreateRecords(creatorAlias string, creatorKey *rsa.PrivateKey, access map[string]*rsa.PublicKey, references []*Reference, reader io.Reader, callback func([]byte, *Record) error) (int, error)

Chunk the data from reader into individual records with their own secret key and access list

func DecimalSizeToString

func DecimalSizeToString(size uint64) string

func DecryptRecord

func DecryptRecord(entry *BlockEntry, access *Record_Access, key *rsa.PrivateKey, callback func(*BlockEntry, []byte, []byte) error) error

func GetAlias

func GetAlias() (string, error)

func GetBCHost

func GetBCHost() string

func GetBCWebsite

func GetBCWebsite() string

func GetBooleanFlag

func GetBooleanFlag(name string) bool

func GetCacheDirectory

func GetCacheDirectory(directory string) (string, error)

func GetCertificateDirectory

func GetCertificateDirectory(directory string) (string, error)

func GetKeyDirectory

func GetKeyDirectory(directory string) (string, error)

func GetPeers

func GetPeers(directory string) ([]string, error)

func GetRootDirectory

func GetRootDirectory() (string, error)

func IsBeta

func IsBeta() bool

func IsLive

func IsLive() bool

func Iterate

func Iterate(channel string, hash []byte, block *Block, cache Cache, network Network, callback func([]byte, *Block) error) error

func IterateChronologically

func IterateChronologically(channel string, hash []byte, block *Block, cache Cache, network Network, callback func([]byte, *Block) error) error

func LoadConfig

func LoadConfig() error

func MoneyToString

func MoneyToString(currency string, amount int64) string

func Ones

func Ones(data []byte) uint64

func PrintBlock

func PrintBlock(output io.Writer, prefix string, hash []byte, block *Block)

func PrintBlockEntry

func PrintBlockEntry(output io.Writer, prefix string, entry *BlockEntry)

func PrintRecord

func PrintRecord(output io.Writer, prefix string, hash []byte, record *Record)

func PrintReference

func PrintReference(output io.Writer, prefix string, reference *Reference)

func Read

func Read(channel string, hash []byte, block *Block, cache Cache, network Network, alias string, key *rsa.PrivateKey, recordHash []byte, callback func(*BlockEntry, []byte, []byte) error) error

func ReadConfig

func ReadConfig(directory string) error

func ReadDelimitedProtobuf

func ReadDelimitedProtobuf(reader *bufio.Reader, destination proto.Message) error

func ReadKey

func ReadKey(channel string, hash []byte, block *Block, cache Cache, network Network, alias string, key *rsa.PrivateKey, recordHash []byte, callback func([]byte) error) error

func SetupLogging

func SetupLogging(directory string) (*os.File, error)

func SplitRemoveEmpty

func SplitRemoveEmpty(s, sep string) []string

func Timestamp

func Timestamp() uint64

func TimestampToString

func TimestampToString(timestamp uint64) string

func WriteDelimitedProtobuf

func WriteDelimitedProtobuf(writer *bufio.Writer, source proto.Message) error

Types

type Block

type Block struct {
	// Timestamp (nanoseconds) when the block was created.
	Timestamp uint64 `protobuf:"fixed64,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
	// Name of the channel.
	ChannelName string `protobuf:"bytes,2,opt,name=channel_name,json=channelName,proto3" json:"channel_name,omitempty"`
	// Length of chain in blocks (inclusive).
	Length uint64 `protobuf:"fixed64,3,opt,name=length,proto3" json:"length,omitempty"`
	// Hash of the previous block in the chain.
	Previous []byte `protobuf:"bytes,4,opt,name=previous,proto3" json:"previous,omitempty"`
	// Alias of the block miner's public key.
	Miner string `protobuf:"bytes,5,opt,name=miner,proto3" json:"miner,omitempty"`
	// The nonce mined to reach threshold.
	Nonce uint64 `protobuf:"fixed64,6,opt,name=nonce,proto3" json:"nonce,omitempty"`
	// The block's entries (list of hash/record pairs).
	Entry                []*BlockEntry `protobuf:"bytes,7,rep,name=entry,proto3" json:"entry,omitempty"`
	XXX_NoUnkeyedLiteral struct{}      `json:"-"`
	XXX_unrecognized     []byte        `json:"-"`
	XXX_sizecache        int32         `json:"-"`
}

func CreateValidationBlock

func CreateValidationBlock(timestamp uint64, channel, alias string, head []byte, block *Block, entries []*BlockEntry) *Block

func GetBlock

func GetBlock(channel string, cache Cache, network Network, hash []byte) (*Block, error)

func GetBlockContainingRecord

func GetBlockContainingRecord(channel string, cache Cache, network Network, hash []byte) (*Block, error)

func (*Block) Descriptor

func (*Block) Descriptor() ([]byte, []int)

func (*Block) GetChannelName

func (m *Block) GetChannelName() string

func (*Block) GetEntry

func (m *Block) GetEntry() []*BlockEntry

func (*Block) GetLength

func (m *Block) GetLength() uint64

func (*Block) GetMiner

func (m *Block) GetMiner() string

func (*Block) GetNonce

func (m *Block) GetNonce() uint64

func (*Block) GetPrevious

func (m *Block) GetPrevious() []byte

func (*Block) GetTimestamp

func (m *Block) GetTimestamp() uint64

func (*Block) ProtoMessage

func (*Block) ProtoMessage()

func (*Block) Reset

func (m *Block) Reset()

func (*Block) String

func (m *Block) String() string

func (*Block) XXX_DiscardUnknown

func (m *Block) XXX_DiscardUnknown()

func (*Block) XXX_Marshal

func (m *Block) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Block) XXX_Merge

func (m *Block) XXX_Merge(src proto.Message)

func (*Block) XXX_Size

func (m *Block) XXX_Size() int

func (*Block) XXX_Unmarshal

func (m *Block) XXX_Unmarshal(b []byte) error

type BlockEntry

type BlockEntry struct {
	// Hash of the record.
	RecordHash           []byte   `protobuf:"bytes,1,opt,name=record_hash,json=recordHash,proto3" json:"record_hash,omitempty"`
	Record               *Record  `protobuf:"bytes,2,opt,name=record,proto3" json:"record,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func CreateValidationEntries

func CreateValidationEntries(timestamp uint64, node *Node) ([]*BlockEntry, error)

func CreateValidationEntry

func CreateValidationEntry(timestamp uint64, node *Node, channel string, updated uint64, head []byte) (*BlockEntry, error)

func (*BlockEntry) Descriptor

func (*BlockEntry) Descriptor() ([]byte, []int)

func (*BlockEntry) GetRecord

func (m *BlockEntry) GetRecord() *Record

func (*BlockEntry) GetRecordHash

func (m *BlockEntry) GetRecordHash() []byte

func (*BlockEntry) ProtoMessage

func (*BlockEntry) ProtoMessage()

func (*BlockEntry) Reset

func (m *BlockEntry) Reset()

func (*BlockEntry) String

func (m *BlockEntry) String() string

func (*BlockEntry) XXX_DiscardUnknown

func (m *BlockEntry) XXX_DiscardUnknown()

func (*BlockEntry) XXX_Marshal

func (m *BlockEntry) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*BlockEntry) XXX_Merge

func (m *BlockEntry) XXX_Merge(src proto.Message)

func (*BlockEntry) XXX_Size

func (m *BlockEntry) XXX_Size() int

func (*BlockEntry) XXX_Unmarshal

func (m *BlockEntry) XXX_Unmarshal(b []byte) error

type Cache

type Cache interface {
	GetHead(channel string) (*Reference, error)
	GetBlock(hash []byte) (*Block, error)
	GetBlockEntries(channel string, timestamp uint64) ([]*BlockEntry, error)
	GetBlockContainingRecord(channel string, hash []byte) (*Block, error)
	PutHead(channel string, reference *Reference) error
	PutBlock(hash []byte, block *Block) error
	PutBlockEntry(channel string, entry *BlockEntry) error
}

type Channel

type Channel struct {
	Name       string
	Head       []byte
	Timestamp  uint64
	Triggers   []func()
	Validators []Validator
	// contains filtered or unexported fields
}

func NewChannel

func NewChannel(name string) *Channel

func OpenPoWChannel

func OpenPoWChannel(name string, threshold uint64) *Channel

func (*Channel) AddTrigger

func (c *Channel) AddTrigger(trigger func())

func (*Channel) AddValidator

func (c *Channel) AddValidator(validator Validator)

func (*Channel) LoadCachedHead

func (c *Channel) LoadCachedHead(cache Cache) error

func (*Channel) LoadHead

func (c *Channel) LoadHead(cache Cache, network Network) error

func (*Channel) Pull

func (c *Channel) Pull(cache Cache, network Network) error

func (*Channel) Push

func (c *Channel) Push(cache Cache, network Network) error

func (*Channel) Refresh

func (c *Channel) Refresh(cache Cache, network Network) error

func (*Channel) String

func (c *Channel) String() string

func (*Channel) Update

func (c *Channel) Update(cache Cache, network Network, head []byte, block *Block) error

func (*Channel) ValidateName

func (c *Channel) ValidateName(name string) error

Validates name matches channel name and all characters are in the set [a-zA-Z0-9.-_]

type FileCache

type FileCache struct {
	Directory string
}

func NewFileCache

func NewFileCache(directory string) (*FileCache, error)

func (*FileCache) GetBlock

func (f *FileCache) GetBlock(hash []byte) (*Block, error)

func (*FileCache) GetBlockContainingRecord

func (f *FileCache) GetBlockContainingRecord(channel string, hash []byte) (*Block, error)

func (*FileCache) GetBlockEntries

func (f *FileCache) GetBlockEntries(channel string, timestamp uint64) ([]*BlockEntry, error)

func (*FileCache) GetHead

func (f *FileCache) GetHead(channel string) (*Reference, error)

func (*FileCache) MeasureStorageUsage

func (f *FileCache) MeasureStorageUsage(prefix string) (map[string]uint64, error)

func (*FileCache) PutBlock

func (f *FileCache) PutBlock(hash []byte, block *Block) error

func (*FileCache) PutBlockEntry

func (f *FileCache) PutBlockEntry(channel string, entry *BlockEntry) error

func (*FileCache) PutHead

func (f *FileCache) PutHead(channel string, reference *Reference) error

type LiveValidator

type LiveValidator struct {
}

func (*LiveValidator) Validate

func (p *LiveValidator) Validate(channel *Channel, cache Cache, network Network, hash []byte, block *Block) error

Validate ensures all records have a live flag in their metadata which matches the environment variable.

type LoggingMiningListener added in v1.1.5

type LoggingMiningListener struct {
}

func (*LoggingMiningListener) OnMiningStarted added in v1.1.5

func (l *LoggingMiningListener) OnMiningStarted(channel *Channel, size uint64)

func (*LoggingMiningListener) OnMiningThresholdReached added in v1.1.5

func (l *LoggingMiningListener) OnMiningThresholdReached(channel *Channel, hash []byte, block *Block)

func (*LoggingMiningListener) OnNewMaxOnes added in v1.1.5

func (l *LoggingMiningListener) OnNewMaxOnes(channel *Channel, nonce, ones uint64)

type MemoryCache

type MemoryCache struct {
	Blocks  map[string]*Block
	Heads   map[string]*Reference
	Entries map[string][]*BlockEntry
	Mapping map[string]*Block
}

func NewMemoryCache

func NewMemoryCache(size int) *MemoryCache

func (*MemoryCache) GetBlock

func (m *MemoryCache) GetBlock(hash []byte) (*Block, error)

func (*MemoryCache) GetBlockContainingRecord

func (m *MemoryCache) GetBlockContainingRecord(channel string, hash []byte) (*Block, error)

func (*MemoryCache) GetBlockEntries

func (m *MemoryCache) GetBlockEntries(channel string, timestamp uint64) ([]*BlockEntry, error)

func (*MemoryCache) GetHead

func (m *MemoryCache) GetHead(channel string) (*Reference, error)

func (*MemoryCache) PutBlock

func (m *MemoryCache) PutBlock(hash []byte, block *Block) error

func (*MemoryCache) PutBlockEntry

func (m *MemoryCache) PutBlockEntry(channel string, entry *BlockEntry) error

func (*MemoryCache) PutHead

func (m *MemoryCache) PutHead(channel string, reference *Reference) error

type MiningListener

type MiningListener interface {
	OnMiningStarted(channel *Channel, size uint64)
	OnNewMaxOnes(channel *Channel, nonce, ones uint64)
	OnMiningThresholdReached(channel *Channel, hash []byte, block *Block)
}

type Network

type Network interface {
	// Requests the head hash of the given channel
	GetHead(channel string) (*Reference, error)
	// Requests the block from the given reference
	GetBlock(reference *Reference) (*Block, error)
	// Broadcasts the channel update to the network
	Broadcast(channel *Channel, cache Cache, hash []byte, block *Block) error
}

type Node

type Node struct {
	Alias    string
	Key      *rsa.PrivateKey
	Cache    Cache
	Network  Network
	Channels map[string]*Channel
	// contains filtered or unexported fields
}
Example
package main

import (
	"aletheiaware.com/bcgo"
	"crypto/rand"
	"crypto/rsa"
	"encoding/base64"
	"fmt"
	"io/ioutil"
	"log"
)

func main() {
	// Create temp directory
	dir, err := ioutil.TempDir("", "test")
	if err != nil {
		log.Fatal("Could not create temp cache dir:", err)
	}

	// Create file cache
	cache, err := bcgo.NewFileCache(dir)
	if err != nil {
		log.Fatal("Could not create file cache:", err)
	}

	channel := &bcgo.Channel{
		Name: "Example",
	}

	// Write record to cache
	_, err = bcgo.WriteRecord(channel.Name, cache, &bcgo.Record{
		Payload: []byte("Example!"),
	})
	if err != nil {
		log.Fatal("Could not write record:", err)
	}

	// Generate private key
	privateKey, err := rsa.GenerateKey(rand.Reader, 4096)
	if err != nil {
		log.Fatal("Could not generate private key:", err)
	}

	// Create node
	node := &bcgo.Node{
		Alias: "ExampleNode",
		Key:   privateKey,
		Cache: cache,
	}

	// Mine all records in cache
	hash, block, err := node.Mine(channel, bcgo.THRESHOLD_G, nil)
	if err != nil {
		log.Fatal("Could not mine:", err)
	}

	fmt.Println(base64.RawURLEncoding.EncodeToString(hash))
	fmt.Println(block)
}
Output:

func NewNode

func NewNode(directory string, cache Cache, network Network) (*Node, error)

func (*Node) AddChannel

func (n *Node) AddChannel(channel *Channel)

func (*Node) GetChannel

func (n *Node) GetChannel(name string) (*Channel, error)

func (*Node) GetChannels

func (n *Node) GetChannels() []*Channel

func (*Node) GetLastMinedTimestamp

func (n *Node) GetLastMinedTimestamp(channel *Channel) (uint64, error)

func (*Node) GetOrOpenChannel

func (n *Node) GetOrOpenChannel(name string, opener func() *Channel) *Channel

func (*Node) Mine

func (n *Node) Mine(channel *Channel, threshold uint64, listener MiningListener) ([]byte, *Block, error)

func (*Node) MineBlock

func (n *Node) MineBlock(channel *Channel, threshold uint64, listener MiningListener, block *Block) ([]byte, *Block, error)

func (*Node) MineEntries

func (n *Node) MineEntries(channel *Channel, threshold uint64, listener MiningListener, entries []*BlockEntry) ([]byte, *Block, error)

func (*Node) MineProto

func (n *Node) MineProto(channel *Channel, threshold uint64, listener MiningListener, acl map[string]*rsa.PublicKey, references []*Reference, message proto.Message) error

func (*Node) Write

func (n *Node) Write(timestamp uint64, channel *Channel, acl map[string]*rsa.PublicKey, references []*Reference, payload []byte) (*Reference, error)

type PeriodicValidator

type PeriodicValidator struct {
	// TODO add validator that each block holds the full channel set of the previous
	// TODO add validator that the duration between block timestamps equals or exceeds the period
	// TODO add validator that each head reference in block is the longest chain before timestamp
	Channel *Channel
	Period  time.Duration
	Ticker  *time.Ticker
}

func GetCentenniallyValidator

func GetCentenniallyValidator(channel *Channel) *PeriodicValidator

func GetDailyValidator

func GetDailyValidator(channel *Channel) *PeriodicValidator

func GetDecenniallyValidator

func GetDecenniallyValidator(channel *Channel) *PeriodicValidator

func GetHourlyValidator

func GetHourlyValidator(channel *Channel) *PeriodicValidator

func GetWeeklyValidator

func GetWeeklyValidator(channel *Channel) *PeriodicValidator

func GetYearlyValidator

func GetYearlyValidator(channel *Channel) *PeriodicValidator

func NewPeriodicValidator

func NewPeriodicValidator(channel *Channel, period time.Duration) *PeriodicValidator

func (*PeriodicValidator) FillChannelSet

func (p *PeriodicValidator) FillChannelSet(set map[string]bool, cache Cache, network Network) error

Fills the given set with the names of all channels validated in this chain

func (*PeriodicValidator) Start

func (p *PeriodicValidator) Start(node *Node, threshold uint64, listener MiningListener)

Periodically mines a new block into the chain containing the head hashes of all open channels

func (*PeriodicValidator) Stop

func (p *PeriodicValidator) Stop()

func (*PeriodicValidator) Update

func (p *PeriodicValidator) Update(node *Node, threshold uint64, listener MiningListener, timestamp uint64) error

func (*PeriodicValidator) Validate

func (p *PeriodicValidator) Validate(channel *Channel, cache Cache, network Network, hash []byte, block *Block) error

Ensures all block hashes in validation chain for given channel appear in its chain

type PoWValidator

type PoWValidator struct {
	Threshold uint64
}

func (*PoWValidator) Validate

func (p *PoWValidator) Validate(channel *Channel, cache Cache, network Network, hash []byte, block *Block) error

type PrintingMiningListener

type PrintingMiningListener struct {
	Output io.Writer
}

func (*PrintingMiningListener) OnMiningStarted

func (p *PrintingMiningListener) OnMiningStarted(channel *Channel, size uint64)

func (*PrintingMiningListener) OnMiningThresholdReached

func (p *PrintingMiningListener) OnMiningThresholdReached(channel *Channel, hash []byte, block *Block)

func (*PrintingMiningListener) OnNewMaxOnes

func (p *PrintingMiningListener) OnNewMaxOnes(channel *Channel, nonce, ones uint64)

type Record

type Record struct {
	// Timestamp (nanoseconds) when the record was created.
	Timestamp uint64 `protobuf:"fixed64,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
	// Alias of the record creator's public key.
	Creator string `protobuf:"bytes,2,opt,name=creator,proto3" json:"creator,omitempty"`
	// The list of accesses granted.
	Access []*Record_Access `protobuf:"bytes,3,rep,name=access,proto3" json:"access,omitempty"`
	// Holds record content, optionally encrypted with a secret key.
	Payload []byte `protobuf:"bytes,4,opt,name=payload,proto3" json:"payload,omitempty"`
	// The algorithm used to compress the payload.
	CompressionAlgorithm cryptogo.CompressionAlgorithm `` /* 155-byte string literal not displayed */
	// The algorithm used to encrypt the payload.
	EncryptionAlgorithm cryptogo.EncryptionAlgorithm `` /* 151-byte string literal not displayed */
	// Signature of payload (signed by the record creator's private key).
	Signature []byte `protobuf:"bytes,7,opt,name=signature,proto3" json:"signature,omitempty"`
	// The algorithm used to sign the payload.
	SignatureAlgorithm cryptogo.SignatureAlgorithm `` /* 147-byte string literal not displayed */
	// References to previous records.
	Reference []*Reference `protobuf:"bytes,9,rep,name=reference,proto3" json:"reference,omitempty"`
	// Holds payload meta data.
	Meta                 map[string]string `` /* 150-byte string literal not displayed */
	XXX_NoUnkeyedLiteral struct{}          `json:"-"`
	XXX_unrecognized     []byte            `json:"-"`
	XXX_sizecache        int32             `json:"-"`
}

func CreateRecord

func CreateRecord(timestamp uint64, creatorAlias string, creatorKey *rsa.PrivateKey, access map[string]*rsa.PublicKey, references []*Reference, payload []byte) ([]byte, *Record, error)

func (*Record) Descriptor

func (*Record) Descriptor() ([]byte, []int)

func (*Record) GetAccess

func (m *Record) GetAccess() []*Record_Access

func (*Record) GetCompressionAlgorithm

func (m *Record) GetCompressionAlgorithm() cryptogo.CompressionAlgorithm

func (*Record) GetCreator

func (m *Record) GetCreator() string

func (*Record) GetEncryptionAlgorithm

func (m *Record) GetEncryptionAlgorithm() cryptogo.EncryptionAlgorithm

func (*Record) GetMeta

func (m *Record) GetMeta() map[string]string

func (*Record) GetPayload

func (m *Record) GetPayload() []byte

func (*Record) GetReference

func (m *Record) GetReference() []*Reference

func (*Record) GetSignature

func (m *Record) GetSignature() []byte

func (*Record) GetSignatureAlgorithm

func (m *Record) GetSignatureAlgorithm() cryptogo.SignatureAlgorithm

func (*Record) GetTimestamp

func (m *Record) GetTimestamp() uint64

func (*Record) ProtoMessage

func (*Record) ProtoMessage()

func (*Record) Reset

func (m *Record) Reset()

func (*Record) String

func (m *Record) String() string

func (*Record) XXX_DiscardUnknown

func (m *Record) XXX_DiscardUnknown()

func (*Record) XXX_Marshal

func (m *Record) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Record) XXX_Merge

func (m *Record) XXX_Merge(src proto.Message)

func (*Record) XXX_Size

func (m *Record) XXX_Size() int

func (*Record) XXX_Unmarshal

func (m *Record) XXX_Unmarshal(b []byte) error

type Record_Access

type Record_Access struct {
	// Alias of the public key granted access, empty if public.
	Alias string `protobuf:"bytes,1,opt,name=alias,proto3" json:"alias,omitempty"`
	// The secret access key used to encrypt the payload.
	SecretKey []byte `protobuf:"bytes,2,opt,name=secret_key,json=secretKey,proto3" json:"secret_key,omitempty"`
	// If the alias is set, the secret key will be encrypted by the alias' public key.
	// The algorithm used to encrypt the secret key.
	EncryptionAlgorithm  cryptogo.EncryptionAlgorithm `` /* 151-byte string literal not displayed */
	XXX_NoUnkeyedLiteral struct{}                     `json:"-"`
	XXX_unrecognized     []byte                       `json:"-"`
	XXX_sizecache        int32                        `json:"-"`
}

func (*Record_Access) Descriptor

func (*Record_Access) Descriptor() ([]byte, []int)

func (*Record_Access) GetAlias

func (m *Record_Access) GetAlias() string

func (*Record_Access) GetEncryptionAlgorithm

func (m *Record_Access) GetEncryptionAlgorithm() cryptogo.EncryptionAlgorithm

func (*Record_Access) GetSecretKey

func (m *Record_Access) GetSecretKey() []byte

func (*Record_Access) ProtoMessage

func (*Record_Access) ProtoMessage()

func (*Record_Access) Reset

func (m *Record_Access) Reset()

func (*Record_Access) String

func (m *Record_Access) String() string

func (*Record_Access) XXX_DiscardUnknown

func (m *Record_Access) XXX_DiscardUnknown()

func (*Record_Access) XXX_Marshal

func (m *Record_Access) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Record_Access) XXX_Merge

func (m *Record_Access) XXX_Merge(src proto.Message)

func (*Record_Access) XXX_Size

func (m *Record_Access) XXX_Size() int

func (*Record_Access) XXX_Unmarshal

func (m *Record_Access) XXX_Unmarshal(b []byte) error

type Reference

type Reference struct {
	// Timestamp (nanoseconds) when the referenced item was created.
	Timestamp uint64 `protobuf:"fixed64,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
	// Name of the channel holding the referenced item.
	ChannelName string `protobuf:"bytes,2,opt,name=channel_name,json=channelName,proto3" json:"channel_name,omitempty"`
	// Hash of the block holding the referenced item.
	BlockHash []byte `protobuf:"bytes,3,opt,name=block_hash,json=blockHash,proto3" json:"block_hash,omitempty"`
	// Hash of the record holding the referenced item.
	RecordHash []byte `protobuf:"bytes,4,opt,name=record_hash,json=recordHash,proto3" json:"record_hash,omitempty"`
	// Index of block in chain holding the referenced item.
	Index                uint64   `protobuf:"fixed64,5,opt,name=index,proto3" json:"index,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func GetHeadReference

func GetHeadReference(channel string, cache Cache, network Network) (*Reference, error)

func WriteRecord

func WriteRecord(channel string, cache Cache, record *Record) (*Reference, error)

func (*Reference) Descriptor

func (*Reference) Descriptor() ([]byte, []int)

func (*Reference) GetBlockHash

func (m *Reference) GetBlockHash() []byte

func (*Reference) GetChannelName

func (m *Reference) GetChannelName() string

func (*Reference) GetIndex

func (m *Reference) GetIndex() uint64

func (*Reference) GetRecordHash

func (m *Reference) GetRecordHash() []byte

func (*Reference) GetTimestamp

func (m *Reference) GetTimestamp() uint64

func (*Reference) ProtoMessage

func (*Reference) ProtoMessage()

func (*Reference) Reset

func (m *Reference) Reset()

func (*Reference) String

func (m *Reference) String() string

func (*Reference) XXX_DiscardUnknown

func (m *Reference) XXX_DiscardUnknown()

func (*Reference) XXX_Marshal

func (m *Reference) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Reference) XXX_Merge

func (m *Reference) XXX_Merge(src proto.Message)

func (*Reference) XXX_Size

func (m *Reference) XXX_Size() int

func (*Reference) XXX_Unmarshal

func (m *Reference) XXX_Unmarshal(b []byte) error

type StopIterationError

type StopIterationError struct {
}

func (StopIterationError) Error

func (e StopIterationError) Error() string

type TCPNetwork

type TCPNetwork struct {
	DialTimeout time.Duration
	GetTimeout  time.Duration
	// contains filtered or unexported fields
}

func NewTCPNetwork

func NewTCPNetwork(peers ...string) *TCPNetwork

func (*TCPNetwork) AddPeer

func (t *TCPNetwork) AddPeer(peer string)

func (*TCPNetwork) Broadcast

func (t *TCPNetwork) Broadcast(channel *Channel, cache Cache, hash []byte, block *Block) error

func (*TCPNetwork) Connect

func (t *TCPNetwork) Connect(peer string, data []byte) error

func (*TCPNetwork) GetBlock

func (t *TCPNetwork) GetBlock(reference *Reference) (*Block, error)

func (*TCPNetwork) GetHead

func (t *TCPNetwork) GetHead(channel string) (*Reference, error)

func (*TCPNetwork) PeerForAddress added in v1.1.6

func (t *TCPNetwork) PeerForAddress(address string) string

Returns the peer associated with the given address

func (*TCPNetwork) Peers

func (t *TCPNetwork) Peers() (peers []string)

func (*TCPNetwork) SetPeers

func (t *TCPNetwork) SetPeers(peers ...string)

type UniqueValidator

type UniqueValidator struct {
}

func (*UniqueValidator) Validate

func (v *UniqueValidator) Validate(channel *Channel, cache Cache, network Network, hash []byte, block *Block) error

type Validator

type Validator interface {
	Validate(channel *Channel, cache Cache, network Network, hash []byte, block *Block) error
}

Jump to

Keyboard shortcuts

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