p2p

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2020 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultPort = 6091
View Source
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

func (AccountsP2P) Marshal

func (a AccountsP2P) Marshal() []byte

Marshal serializes AccountsP2P

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

func (BlockP2P) Marshal added in v0.1.0

func (b BlockP2P) Marshal() []byte

Marshal serializes BlockP2P

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

func (*BlockchainForest) GetBlock added in v0.1.0

func (b *BlockchainForest) GetBlock(peerId []byte, blockId []byte, blockOnly bool) BlockP2P

GetBlock returns a local or peer block as requested

type ChallengeWordP2P added in v0.1.0

type ChallengeWordP2P struct {
	ChallengeWord string
	Address       string
}

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

func (MappingsP2P) Marshal

func (a MappingsP2P) Marshal() []byte

Marshal serializes MappingsP2P

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) GetPeers added in v0.1.0

func (p *P2P) GetPeers() []byte

GetPeers returns currently know peers in json format

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

type RequestP2P struct {
	RequestType       string
	RequestParameters map[string]string
}

RequestP2P represents common p2p request body

func (RequestP2P) Marshal

func (a RequestP2P) Marshal() []byte

Marshal serializes RequestP2P

Jump to

Keyboard shortcuts

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