data

package
v0.0.0-...-c2f1f9c Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PeerMapPidToJson

func PeerMapPidToJson(peerMapPid map[string]p5.PublicIdentity) (string, error)

PeerMapSIDToJson func returns a json string of PeerMap or an error

func PeerMapToJson

func PeerMapToJson(peermap map[string]int32) (string, error)

PeerMapToJson func returns a json string of PeerMap or an error

func TestHeartBeat

func TestHeartBeat()

func TestPeerListRebalance

func TestPeerListRebalance()

Types

type HeartBeatData

type HeartBeatData struct {
	IfNewBlock       bool              `json:"ifNewBlock"`
	Id               int32             `json:"id"`
	Pid              p5.PublicIdentity `json:"pid"`
	BlockJson        string            `json:"blockJson"`
	SignForBlockJson []byte            `json:"signForBlockJson"`
	PeerMapJson      string            `json:"peerMapJson"`
	PeerMapPidJson   string            `json:"peerMapPidJson"`
	Addr             string            `json:"addr"`
	Hops             int32             `json:"hops"`
}

HeartBeatData struct defines the data to be sent between peers perodically

func DecodeToHeartBeatData

func DecodeToHeartBeatData(heartBeatDatajson string) HeartBeatData

DecodeToHeartBeatData func decodes json string to HeartBeatData

func NewHeartBeatData

func NewHeartBeatData(ifNewBlock bool, id int32, pid p5.PublicIdentity, blockJson string, signForBlockJson []byte, peerMapJson string, peerMapPidJson string, addr string) HeartBeatData

NewHeartBeatData creates new HeartBeatData

func PrepareHeartBeatData

func PrepareHeartBeatData(sbc *SyncBlockChain, selfId int32, selfpid p5.PublicIdentity, peerMapBase64 string, peerMapPidBase64 string, addr string, makingNew bool, newBlockJson string, signForBlockJson []byte) HeartBeatData

PrepareHeartBeatData func prepares and returns heartbeat

func (*HeartBeatData) EncodeToJson

func (data *HeartBeatData) EncodeToJson() string

EncodeToJson func encodes HeartBeatData to json string

func (*HeartBeatData) EncodeToJsonByteArray

func (data *HeartBeatData) EncodeToJsonByteArray() []byte

EncodeToJson func encodes HeartBeatData to json byte array

type Pair

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

///////// Pair - data structure to hold a key/value pair - addr/id.

type PairList

type PairList []Pair

A slice of Pairs that implements sort.Interface to sort by Value.

func (PairList) Len

func (p PairList) Len() int

func (PairList) Less

func (p PairList) Less(i, j int) bool

func (PairList) Swap

func (p PairList) Swap(i, j int)

type PeerList

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

PeerList contains selfId, peerMap, max length, and a mutex

func NewPeerList

func NewPeerList(id int32, sid p5.Identity, maxLength int32) PeerList

NewPeerList func creates a New PeerList for a id and maxLength

func (*PeerList) Add

func (peers *PeerList) Add(addr string, id int32)

Add func adds a peer with addr and id to peerMap

func (*PeerList) AddPid

func (peers *PeerList) AddPid(addr string, id p5.PublicIdentity)

Add func adds a peer with addr and id to peerMap

func (*PeerList) Copy

func (peers *PeerList) Copy() map[string]int32

Copy func returns a copy of the peerMap

func (*PeerList) CopyPids

func (peers *PeerList) CopyPids() map[string]p5.PublicIdentity

Copy func returns a copy of the peerMap

func (*PeerList) Delete

func (peers *PeerList) Delete(addr string)

Delete func deletes a peer with specific addr

func (*PeerList) GetSelfId

func (peers *PeerList) GetSelfId() int32

GetSelfId func returns selfId of Peer

func (*PeerList) InjectPeerMapJson

func (peers *PeerList) InjectPeerMapJson(peerMapJsonStr string, selfAddr string)

InjectPeerMapJson func injects the new PeerMap into existing PeerMap, except for the entry corresponding to self

func (*PeerList) InjectPeerMapPidJson

func (peers *PeerList) InjectPeerMapPidJson(peerMapPidJsonStr string, selfAddr string)

InjectPeerMapJson func injects the new PeerMap into existing PeerMap, except for the entry corresponding to self

func (*PeerList) PeerMapPidToJson

func (peers *PeerList) PeerMapPidToJson() (string, error)

PeerMapToJson func returns a json string of PeerMap or an error

func (*PeerList) PeerMapToJson

func (peers *PeerList) PeerMapToJson() (string, error)

PeerMapToJson func returns a json string of PeerMap or an error

func (*PeerList) Rebalance

func (peers *PeerList) Rebalance()

Rebalance func changes the PeerMap to contain take maxLength(32) closest peers (by Id)

func (*PeerList) Show

func (peers *PeerList) Show() string

Show func returns PeerMap string

func (*PeerList) ShowPids

func (peers *PeerList) ShowPids() string

Show func returns PeerMap string

type RegisterData

type RegisterData struct {
	AssignedId  string `json:"assignedId"`
	PeerMapJson string `json:"peerMapJson"`
}

RegisterData struct defines the AssignedId and PeerMapJson to a struct

func NewRegisterData

func NewRegisterData(id string, peerMapJson string) RegisterData

NewRegisterData func creates a new RegsterData

func (*RegisterData) EncodeToJson

func (data *RegisterData) EncodeToJson() (string, error)

EncodeToJson func encodes RegisterData to json string

type SyncBlockChain

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

SyncBlockChain struct is main - shared - common - datastu

func NewBlockChain

func NewBlockChain() SyncBlockChain

NewBlockChain func generates a new syncBlockchain

func (*SyncBlockChain) BlockChainToJson

func (sbc *SyncBlockChain) BlockChainToJson() (string, error)

BlockChainToJson converts blockchain to json string

func (*SyncBlockChain) CheckParentHash

func (sbc *SyncBlockChain) CheckParentHash(insertBlock block.Block) bool

CheckParentHash func takes a block and checks if parent hash exists and return true or false

func (*SyncBlockChain) GenBlock

func (sbc *SyncBlockChain) GenBlock(height int32, parentHash string, mpt p1.MerklePatriciaTrie, nonce string) block.Block

GenBlock finc takes in a mpt and returns a block for the node takes parentat list[0] in random height

func (*SyncBlockChain) Get

func (sbc *SyncBlockChain) Get(height int32) ([]block.Block, bool)

Get func takes height as input and returns list of block at that height

func (*SyncBlockChain) GetBlock

func (sbc *SyncBlockChain) GetBlock(height int32, hash string) (block.Block, bool)

GetBlock func takes height and hash as parameter and returns a block

func (*SyncBlockChain) GetLatestBlocks

func (sbc *SyncBlockChain) GetLatestBlocks() []block.Block

func (*SyncBlockChain) GetLength

func (sbc *SyncBlockChain) GetLength() int32

Get func takes height as input and returns list of block at that height

func (*SyncBlockChain) GetParentBlock

func (sbc *SyncBlockChain) GetParentBlock(blk block.Block) block.Block

func (*SyncBlockChain) Insert

func (sbc *SyncBlockChain) Insert(block block.Block)

Insert func inserts a block into blockchain in safe way

func (*SyncBlockChain) Show

func (sbc *SyncBlockChain) Show() string

Show func returns blockchain in displayable format

func (*SyncBlockChain) UpdateEntireBlockChain

func (sbc *SyncBlockChain) UpdateEntireBlockChain(blockChainJson string)

UpdateEntireBlockChain func takes a json and updates the existing blockchain

Jump to

Keyboard shortcuts

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