nodemanager

package
v0.0.0-...-acf744c Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2018 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangesPullResults

type ChangesPullResults struct {
	AddedTransactions [][]byte
	AddedBlocks       [][]byte
	AddedNodes        []net.NodeAddr
}

func (ChangesPullResults) AnyChangesPulled

func (p ChangesPullResults) AnyChangesPulled() bool

Detects if there were any changes pulled

type Database

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

func (*Database) CheckConnection

func (db *Database) CheckConnection() error

check if connection to DB can be set

func (*Database) CheckConnectionIsOpen

func (db *Database) CheckConnectionIsOpen() bool

check if connection was opened

func (*Database) CleanConnection

func (db *Database) CleanConnection()

clean connection object

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) Dump

func (db *Database) Dump(file string) error

dump DB to file

func (*Database) GetAllTables

func (db *Database) GetAllTables() ([]string, error)

check if connection to DB can be set

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(sessid string) error

open DB connection if it is not yet opened

func (*Database) OpenConnectionIfNeeded

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

open connection if it is not yet opened

func (*Database) PrepareConnection

func (db *Database) PrepareConnection(sessid string)

func (*Database) Restore

func (db *Database) Restore(file string) error

restore from dump

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
	NodeClient *nodeclient.NodeClient
	DBConn     *Database

	ConfigDir       string
	MinterAddress   string
	ProxyPubKey     []byte
	ProxyPrivateKey ecdsa.PrivateKey

	OtherNodes []net.NodeAddr

	SessionID string

	ConsensusConfig *consensus.ConsensusConfig
	// contains filtered or unexported fields
}

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

func (*Node) Clone

func (orignode *Node) Clone() *Node

Clone node

func (*Node) CreateBlockchain

func (n *Node) CreateBlockchain(minterAddress string, pubKey []byte, privateKey ecdsa.PrivateKey) 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) DumpBlockchain

func (n *Node) DumpBlockchain(file string) error

Dump DB to file

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) GetCommunicationManager

func (n *Node) GetCommunicationManager() *communicationManager

Create communication object to do requests to othernodes

func (*Node) GetNodeState

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

Get node state

func (*Node) GetSQLQueryManager

func (n *Node) GetSQLQueryManager() (consensus.SQLTransactionsInterface, error)

Init SQL transactions manager

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) ReceivedNewCurrencyTransactionData

func (n *Node) ReceivedNewCurrencyTransactionData(txBytes []byte, Signature []byte) (*structures.Transaction, error)

New transactions created. It is received in serialysed view and signatures separately This data is ready to be convertd to complete gransaction

func (*Node) ReceivedNewTransaction

func (n *Node) ReceivedNewTransaction(tx *structures.Transaction, flags int) error

Received new transaction . This must verify and if all ok it adds to the pool

func (*Node) RestoreBlockchain

func (n *Node) RestoreBlockchain(file string) error

Create new blockchain in empty DB using a DB dump

func (*Node) SQLTransaction

func (n *Node) SQLTransaction(PubKey []byte, privKey ecdsa.PrivateKey, sqlcommand string) ([]byte, error)

Execute SQL query This adds a transaction directly to the DB. Can be executed when a node server is not running This creates SQL transaction . Currency part can be present if SQL query "costs money"

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 This creates currency transfer transaction where SQL command is not present

func (*Node) SendVersionToNodes

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

Send own version to all known node

func (*Node) TryToMakeBlock

func (n *Node) TryToMakeBlock(newTransactionID []byte, callback PreparedTransactionsCallback) ([]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
	// contains filtered or unexported fields
}

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) GetBCTopState

func (n *NodeBlockchain) GetBCTopState(bcount int) (height int, topBlocks [][]byte, err error)

Get BC top info, height and last N block hashes

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 NodeLocks

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

func (*NodeLocks) InitLocks

func (n *NodeLocks) InitLocks()

create locks object

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)

type PreparedTransactionsCallback

type PreparedTransactionsCallback func(list [][]byte) error

Jump to

Keyboard shortcuts

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