nodemanager

package
v0.0.0-...-f7c9202 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2018 License: MIT Imports: 15 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database struct {
	Logger *utils.LoggerMan
	Config database.DatabaseConfig
	// contains filtered or unexported fields
}

func (*Database) CheckConnectionIsOpen

func (db *Database) CheckConnectionIsOpen() bool

func (*Database) CleanConnection

func (db *Database) CleanConnection()

func (*Database) Clone

func (db *Database) Clone() Database

Clone database object. all is clonned except locker object. locker object is shared between all objects

func (*Database) CloseConnection

func (db *Database) CloseConnection() error

func (*Database) DB

func (db *Database) DB() database.DBManager

func (*Database) Init

func (db *Database) Init()

do initial actions

func (*Database) InitDatabase

func (db *Database) InitDatabase() error

prepare database before the first user

func (*Database) OpenConnection

func (db *Database) OpenConnection(reason string, sessid string) error

func (*Database) OpenConnectionIfNeeded

func (db *Database) OpenConnectionIfNeeded(reason string, sessid string) bool

func (*Database) PrepareConnection

func (db *Database) PrepareConnection(sessid string)

func (*Database) SetConfig

func (db *Database) SetConfig(config database.DatabaseConfig)

func (*Database) SetLogger

func (db *Database) SetLogger(Logger *utils.LoggerMan)

type Node

type Node struct {
	NodeBC  NodeBlockchain
	NodeNet net.NodeNetwork
	Logger  *utils.LoggerMan
	DataDir string

	MinterAddress string
	NodeClient    *nodeclient.NodeClient
	OtherNodes    []net.NodeAddr
	DBConn        *Database
	SessionID     string
}

This structure is central part of the application. only it can acces to blockchain and inside it all operation are done

func (*Node) AddBlock

func (n *Node) AddBlock(block *structures.Block) (uint, error)

func (*Node) AddNodeToKnown

func (n *Node) AddNodeToKnown(addr net.NodeAddr, sendversion bool)

Add node We need this for case when we want to do some more actions after node added

func (*Node) BlockchainExist

func (n *Node) BlockchainExist() bool

func (*Node) CheckAddressKnown

func (n *Node) CheckAddressKnown(addr net.NodeAddr) bool

* Check if the address is known . If not then add to known * and send list of all addresses to that node

func (*Node) CreateBlockchain

func (n *Node) CreateBlockchain(address, genesisCoinbaseData string) error

Create new blockchain, add genesis block witha given text

func (*Node) DropBlock

func (n *Node) DropBlock() error

* Drop block from the top of blockchain * This will not check if there are other branch that can now be longest and becomes main branch

func (*Node) GetBCManager

func (n *Node) GetBCManager() (*blockchain.Blockchain, error)

Build BC manager structure

func (*Node) GetBlockChainIterator

func (n *Node) GetBlockChainIterator() (*blockchain.BlockchainIterator, error)

Creates iterator to go over blockchain

func (*Node) GetNodeState

func (n *Node) GetNodeState() (nodeclient.ComGetNodeState, error)

func (*Node) GetTransactionsManager

func (n *Node) GetTransactionsManager() transactions.TransactionsManagerInterface

Build transaction manager structure

func (*Node) Init

func (n *Node) Init()

Init node. Init interfaces of all DBs, blockchain, unspent transactions, unapproved transactions

func (*Node) InitBlockchainFromOther

func (n *Node) InitBlockchainFromOther(host string, port int) (bool, error)

func (*Node) InitClient

func (n *Node) InitClient() error

Init network client object. It is used to communicate with other nodes

func (*Node) InitNodes

func (n *Node) InitNodes(list []net.NodeAddr, force bool) error

Load list of other nodes addresses

func (*Node) ReceivedBlockFromOtherNode

func (n *Node) ReceivedBlockFromOtherNode(addrfrom net.NodeAddr, bsdata []byte) (int, error)

New block info received from oher node. It is only Hash and PrevHash, not full block Check if this is new block and if previous block is fine returns state of processing. if a block data was requested or exists or prev doesn't exist

func (*Node) ReceivedFullBlockFromOtherNode

func (n *Node) ReceivedFullBlockFromOtherNode(blockdata []byte) (int, uint, *structures.Block, error)

* New block info received from oher node * Check if this is new block and if previous block is fine * returns state of processing. if a block data was requested or exists or prev doesn't exist

func (*Node) Send

func (n *Node) Send(PubKey []byte, privKey ecdsa.PrivateKey, to string, amount float64) ([]byte, error)

* Send money . * This adds a transaction directly to the DB. Can be executed when a node server is not running

func (*Node) SendBlockToAll

func (n *Node) SendBlockToAll(newBlock *structures.Block, skipaddr net.NodeAddr)

Send block to all known nodes This is used in case when new block was received from other node or created by this node. We will notify our network about new block But not send full block, only hash and previous hash. So, other can copy it Address from where we get it will be skipped

func (*Node) SendTransactionToAll

func (n *Node) SendTransactionToAll(tx *structures.Transaction)

* Send transaction to all known nodes. This wil send only hash and node hash to check if hash exists or no

func (*Node) SendVersionToNodes

func (n *Node) SendVersionToNodes(nodes []net.NodeAddr)

* Send own version to all known nodes

func (*Node) TryToMakeBlock

func (n *Node) TryToMakeBlock(newTransactionID []byte) ([]byte, error)

Try to make a block. If no enough transactions, send new transaction to all other nodes

type NodeBlockchain

type NodeBlockchain struct {
	Logger        *utils.LoggerMan
	MinterAddress string
	DBConn        *Database
}

func (*NodeBlockchain) AddBlock

func (n *NodeBlockchain) AddBlock(block *structures.Block) (uint, error)

Add block to blockchain Block is not yet verified

func (*NodeBlockchain) CheckBlockExists

func (n *NodeBlockchain) CheckBlockExists(blockHash []byte) (bool, error)

Checks if a block exists in the chain. It will go over blocks list

func (*NodeBlockchain) CheckBlockState

func (n *NodeBlockchain) CheckBlockState(hash, prevhash []byte) (int, error)

* Checks state of a block by hashes * returns * -1 BCBState_error * 0 BCBState_canAdd if block doesn't exist and prev block exists * 1 BCBState_exists if block exists * 2 BCBState_notExistAndPrevNotExist if block doesn't exist and prev block doesn't exist

func (*NodeBlockchain) DropBlock

func (n *NodeBlockchain) DropBlock() (*structures.Block, error)

Drop block from a top of blockchain

func (*NodeBlockchain) GetAddressHistory

func (n *NodeBlockchain) GetAddressHistory(address string) ([]structures.TransactionsHistory, error)

Returns history of transactions for given address

func (*NodeBlockchain) GetBCManager

func (n *NodeBlockchain) GetBCManager() *blockchain.Blockchain

func (*NodeBlockchain) GetBestHeight

func (n *NodeBlockchain) GetBestHeight() (int, error)

Returns height of the chain. Index of top block

func (*NodeBlockchain) GetBlock

func (n *NodeBlockchain) GetBlock(hash []byte) (*structures.Block, error)

Get block objet by hash

func (*NodeBlockchain) GetBlocksAfter

func (n *NodeBlockchain) GetBlocksAfter(hash []byte) ([]*structures.BlockShort, error)

Get next blocks uppper then given

func (*NodeBlockchain) GetBranchesReplacement

func (n *NodeBlockchain) GetBranchesReplacement(sideBranchHash []byte, tip []byte) ([]*structures.Block, []*structures.Block, error)

returns two branches of a block starting from their common block. One of branches is primary at this time

func (*NodeBlockchain) GetTopBlockHash

func (n *NodeBlockchain) GetTopBlockHash() ([]byte, error)

Return top hash

type NodesListStorage

type NodesListStorage struct {
	DBConn    *Database
	SessionID string
}

func (NodesListStorage) AddNodeToKnown

func (s NodesListStorage) AddNodeToKnown(addr net.NodeAddr)

func (NodesListStorage) GetCountOfKnownNodes

func (s NodesListStorage) GetCountOfKnownNodes() (int, error)

func (NodesListStorage) GetNodes

func (s NodesListStorage) GetNodes() ([]net.NodeAddr, error)

func (NodesListStorage) RemoveNodeFromKnown

func (s NodesListStorage) RemoveNodeFromKnown(addr net.NodeAddr)

Jump to

Keyboard shortcuts

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