p2p

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectToGRPCServer

func ConnectToGRPCServer(addr string) (*grpc.ClientConn, protos.P2PClient)

Types

type Downloader

type Downloader struct {
	Peers []*Peer
	Self  string

	TxpoolCh     chan *types.Transaction
	BlockCh      chan *types.Block
	BlockchainDB *dbstore.BlockchainDB
}

func NewDownloader

func NewDownloader(self string, initPeers []string, txpoolCh chan *types.Transaction, blockCh chan *types.Block, blockchainDB *dbstore.BlockchainDB) *Downloader

func (*Downloader) GetPeers

func (d *Downloader) GetPeers() []*Peer

func (*Downloader) Start

func (d *Downloader) Start()

type P2PMessage

type P2PMessage struct {
	From    string
	Query   string
	Message string
	Error   error
}

type P2PServer

type P2PServer struct {
	Port                  string
	Lis                   net.Listener
	GRPCSrv               *grpc.Server
	Peers                 []string
	P2PAddrBlockNumberMap map[string]int
	Downloader            *Downloader

	BlockchainDB *dbstore.BlockchainDB
	StateDB      *dbstore.StateDB
	Txpool       *txpool.TxPool

	protos.UnimplementedP2PServer
}

func NewServer

func NewServer(port string, initPeers []string, statedb *dbstore.StateDB, blockchainDb *dbstore.BlockchainDB, txpool *txpool.TxPool, txpoolCh chan *types.Transaction, blockCh chan *types.Block) *P2PServer

func (*P2PServer) BlocksInRange

func (*P2PServer) LatestBlock

func (*P2PServer) StartServer

func (p2psrv *P2PServer) StartServer()

func (*P2PServer) TxPoolPending

type Peer

type Peer struct {
	Addr        string
	ClientConn  *grpc.ClientConn
	P2PClient   protos.P2PClient
	LatestBlock *types.Block
}

func (*Peer) PeerBlocksLoop

func (p *Peer) PeerBlocksLoop(blockCh chan *types.Block, blockchainDB dbstore.BlockchainDB)

func (*Peer) PeerTxpoolLoop

func (p *Peer) PeerTxpoolLoop(txpoolCh chan *types.Transaction)

Jump to

Keyboard shortcuts

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