data

package
v0.0.0-...-8b53a4d Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TestPeerListRebalance

func TestPeerListRebalance()

Types

type HeartBeatData

type HeartBeatData struct {
	IfNewBlock  bool   `json:"ifNewBlock"`
	Id          int32  `json:"id"`
	BlockJson   string `json:"blockJson"`
	PeerMapJson string `json:"peerMapJson"`
	Addr        string `json:"addr"`
	Hops        int32  `json:"hops"`
}

Heartbeat is the JSON representation of the data we need to send to the other blockchains

func NewHeartBeatData

func NewHeartBeatData(ifNewBlock bool, id int32, blockJson string, peerMapJson string, addr string) HeartBeatData

func PrepareHeartBeatData

func PrepareHeartBeatData(sbc *SyncBlockChain, selfId int32, peerMapJson string, addr string, verified bool, trie p1.MerklePatriciaTrie) HeartBeatData

Create a new instance of HeartBeatData, then decide whether to create a new block and send it to other peers.

func (*HeartBeatData) HeartBeatToJson

func (heartbeat *HeartBeatData) HeartBeatToJson() string

type JsonPeerList

type JsonPeerList struct {
	JsonRep string
}

type Pair

type Pair struct {
	Key   int32
	Value string
}

Pair will hold peermap key as value, and value as key because that makes more sense

type PairList

type PairList []Pair

func (PairList) GetValue

func (p PairList) GetValue(i int) string

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
}

func NewPeerList

func NewPeerList(id int32, maxLength int32) PeerList

func (*PeerList) Add

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

func (*PeerList) Copy

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

Return copy of peer list presumably

func (*PeerList) Delete

func (peers *PeerList) Delete(addr string)

func (*PeerList) GetPeerMap

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

func (*PeerList) GetSelfId

func (peers *PeerList) GetSelfId() int32

func (*PeerList) InjectPeerMapJson

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

Todo: Take peerMap as json String insert each entry into own peer list except for selfAddr

func (*PeerList) PeerMapToJson

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

TODO: Fix error checking

func (*PeerList) Rebalance

func (peers *PeerList) Rebalance()
Sort all peers' Id, insert SelfId, consider the list as a cycle, and choose 16 nodes at each side of SelfId.

For example, if SelfId is 10, PeerList is [7, 8, 9, 15, 16], then the closest 4 nodes are [8, 9, 15, 16].

func (*PeerList) Register

func (peers *PeerList) Register(id int32)

func (*PeerList) Show

func (peers *PeerList) Show() string

Putting a lock here creates deadlock so don't do it

type PeerMap

type PeerMap struct {
	Addr string `json:"addr"`
	Id   int32  `json:"id"`
}

type RegisterData

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

func NewRegisterData

func NewRegisterData(id int32, peerMapJson string) RegisterData

func (*RegisterData) EncodeToJson

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

TODO: Check this for correctness

type SyncBlockChain

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

func NewBlockChain

func NewBlockChain() SyncBlockChain

func (*SyncBlockChain) BlockChainToJson

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

func (*SyncBlockChain) CheckParentHash

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

Check if this block is found in the chain

func (*SyncBlockChain) CountValues

func (sbc *SyncBlockChain) CountValues(value string) int

func (*SyncBlockChain) GenBlock

func (sbc *SyncBlockChain) GenBlock(mpt p1.MerklePatriciaTrie, public_key string) p2.Block

Create a new block to add to Sync. Blockchain

func (*SyncBlockChain) Get

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

Returns false if not found

func (*SyncBlockChain) GetBlock

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

func (*SyncBlockChain) GetLatestBlocks

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

func (*SyncBlockChain) GetLength

func (sbc *SyncBlockChain) GetLength() (height int32)

func (*SyncBlockChain) GetParentBlock

func (sbc *SyncBlockChain) GetParentBlock(block p2.Block) (p2.Block, error)

func (*SyncBlockChain) Insert

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

func (*SyncBlockChain) Show

func (sbc *SyncBlockChain) Show() string

func (*SyncBlockChain) ShowMPT

func (sbc *SyncBlockChain) ShowMPT() string

func (*SyncBlockChain) UpdateEntireBlockChain

func (sbc *SyncBlockChain) UpdateEntireBlockChain(blockChainJson string)

Jump to

Keyboard shortcuts

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