Documentation ¶
Index ¶
- func PeerMapPidToJson(peerMapPid map[string]p5.PublicIdentity) (string, error)
- func PeerMapToJson(peermap map[string]int32) (string, error)
- func TestHeartBeat()
- func TestPeerListRebalance()
- type HeartBeatData
- type Pair
- type PairList
- type PeerList
- func (peers *PeerList) Add(addr string, id int32)
- func (peers *PeerList) AddPid(addr string, id p5.PublicIdentity)
- func (peers *PeerList) Copy() map[string]int32
- func (peers *PeerList) CopyPids() map[string]p5.PublicIdentity
- func (peers *PeerList) Delete(addr string)
- func (peers *PeerList) GetSelfId() int32
- func (peers *PeerList) InjectPeerMapJson(peerMapJsonStr string, selfAddr string)
- func (peers *PeerList) InjectPeerMapPidJson(peerMapPidJsonStr string, selfAddr string)
- func (peers *PeerList) PeerMapPidToJson() (string, error)
- func (peers *PeerList) PeerMapToJson() (string, error)
- func (peers *PeerList) Rebalance()
- func (peers *PeerList) Show() string
- func (peers *PeerList) ShowPids() string
- type RegisterData
- type SyncBlockChain
- func (sbc *SyncBlockChain) BlockChainToJson() (string, error)
- func (sbc *SyncBlockChain) CheckParentHash(insertBlock block.Block) bool
- func (sbc *SyncBlockChain) GenBlock(height int32, parentHash string, mpt p1.MerklePatriciaTrie, nonce string) block.Block
- func (sbc *SyncBlockChain) Get(height int32) ([]block.Block, bool)
- func (sbc *SyncBlockChain) GetBlock(height int32, hash string) (block.Block, bool)
- func (sbc *SyncBlockChain) GetLatestBlocks() []block.Block
- func (sbc *SyncBlockChain) GetLength() int32
- func (sbc *SyncBlockChain) GetParentBlock(blk block.Block) block.Block
- func (sbc *SyncBlockChain) Insert(block block.Block)
- func (sbc *SyncBlockChain) Show() string
- func (sbc *SyncBlockChain) UpdateEntireBlockChain(blockChainJson string)
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 ¶
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.
type PeerList ¶
type PeerList struct {
// contains filtered or unexported fields
}
PeerList contains selfId, peerMap, max length, and a mutex
func NewPeerList ¶
NewPeerList func creates a New PeerList for a id and maxLength
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) CopyPids ¶
func (peers *PeerList) CopyPids() map[string]p5.PublicIdentity
Copy func returns a copy of the peerMap
func (*PeerList) InjectPeerMapJson ¶
InjectPeerMapJson func injects the new PeerMap into existing PeerMap, except for the entry corresponding to self
func (*PeerList) InjectPeerMapPidJson ¶
InjectPeerMapJson func injects the new PeerMap into existing PeerMap, except for the entry corresponding to self
func (*PeerList) PeerMapPidToJson ¶
PeerMapToJson func returns a json string of PeerMap or an error
func (*PeerList) PeerMapToJson ¶
PeerMapToJson func returns a json string of PeerMap or an error
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 ¶
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