Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultPort = 6091
var PingIntervalInMs = 3000
Functions ¶
This section is empty.
Types ¶
type AccountsP2P ¶
type AccountsP2P struct {
Accounts map[string]blockchain.Account
}
AccountsP2P represents all the accounts from a peer
type BlockP2P ¶ added in v0.1.0
type BlockP2P struct { PeerId []byte Timestamp int64 PrevBlockHash []byte Height uint64 Hash []byte IsTip bool TotalTransactions int Transactions []blockchain.Transaction }
BlockP2P represents a block from a peer
func (BlockP2P) MapToBlock ¶ added in v0.1.0
func (b BlockP2P) MapToBlock() (*blockchain.Block, error)
MapToBlock verified each transaction in the BlockP2P on wire and convert it to blockchain.Block
type BlockchainForest ¶ added in v0.1.0
type BlockchainForest struct { Local *blockchain.Blockchain Peers map[string]*blockchain.Blockchain }
BlockchainForest defines the local and peer chains
func NewBlockchainForest ¶ added in v0.1.0
func NewBlockchainForest(bcLocal *blockchain.Blockchain) *BlockchainForest
NewBlockchainForest initializes the peer blockchains by reading existing dbs from peerBlockchainDir which will be created should not exist
func (*BlockchainForest) AddBlock ¶ added in v0.1.0
func (b *BlockchainForest) AddBlock(blockP2p BlockP2P)
AddBlock persist the broadcasted or requested block from a peer to local peer blockchain db and index it
type ChallengeWordP2P ¶ added in v0.1.0
ChallengeWordP2P represents a challengeWord cache item from a peer
func (ChallengeWordP2P) Marshal ¶ added in v0.1.0
func (a ChallengeWordP2P) Marshal() []byte
Marshal serializes ChallengeWordP2P
type MappingsP2P ¶
type MappingsP2P struct {
Mappings map[string]blockchain.DocumentMapping
}
MappingsP2P represents all the collection mappings (schemas) from a peer
type P2P ¶
type P2P struct { Node *noise.Node BlockchainForest *BlockchainForest ChallengeWordsCache *cache.Cache Accounts map[string]blockchain.Account // used by http // contains filtered or unexported fields }
P2P is the main object to handle networking-related messages
func NewP2P ¶
func NewP2P(bc *blockchain.Blockchain, bindHost string, bindPort uint16, advertiseAddress string, connectionAddresses ...string) *P2P
NewP2P initializes the P2P node with messages and handlers
func (*P2P) BroadcastObject ¶
func (p *P2P) BroadcastObject(object noise.Serializable)
BroadcastObject sends a serializable object to all the known peers
func (*P2P) SyncAccountsFromPeers ¶
func (p *P2P) SyncAccountsFromPeers()
SyncAccountsFromPeers sends rpc to peers to sync the accounts
func (*P2P) SyncMappingsFromPeers ¶
func (p *P2P) SyncMappingsFromPeers()
SyncMappingsFromPeers sends rpc to peers to sync the mappings
func (*P2P) SyncPeerBlockchains ¶ added in v0.1.0
func (p *P2P) SyncPeerBlockchains()
SyncPeerBlockchains sends rpc to all known peers to sync the peer blockchains to local
type RequestP2P ¶
RequestP2P represents common p2p request body