network

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: Unlicense Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TODO rename and extract ParticlesCount to a config file
	ParticlesCount = 100000000

	GetBlocksRequest       = "GET BLOCKS REQUEST"
	GetTransactionsRequest = "GET TRANSACTIONS REQUEST"
	MineRequest            = "MINE REQUEST"
	StartMiningRequest     = "START MINING REQUEST"
	StopMiningRequest      = "STOP MINING REQUEST"
)
View Source
const (
	DefaultPort = 8106
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Blockchain

type Blockchain interface {
	Verify()
	StartVerification()
	Blocks() []*neighborhood.BlockResponse
	CalculateTotalAmount(currentTimestamp int64, blockchainAddress string) uint64
	AddBlock(blockResponse *neighborhood.BlockResponse)
}

type Client added in v1.0.3

type Client interface {
	Send(topic string, req p2p.Data) (res p2p.Data, err error)
}

type ClientFactory added in v1.0.3

type ClientFactory interface {
	CreateClient(ip string, port uint16, target string) (Client, error)
}

type Host

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

func NewHost

func NewHost(
	server Server,
	blockchain Blockchain,
	pool TransactionsPool,
	validator Validator,
	synchronizer *Synchronizer,
	watch clock.Time,
	logger *log.Logger,
) *Host

func (*Host) AddTransactions

func (host *Host) AddTransactions(request *neighborhood.TransactionRequest)

func (*Host) Amount

func (host *Host) Amount(request *neighborhood.AmountRequest) (res p2p.Data)

func (*Host) GetBlocks

func (host *Host) GetBlocks() (res p2p.Data)

func (*Host) GetTransactions

func (host *Host) GetTransactions() (res p2p.Data)

func (*Host) PostTargets

func (host *Host) PostTargets(request []neighborhood.TargetRequest)

func (*Host) Run

func (host *Host) Run() error

type Neighbor

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

func NewNeighbor

func NewNeighbor(target *Target, clientFactory ClientFactory, logger *log.Logger) (*Neighbor, error)

func (*Neighbor) AddTransaction

func (neighbor *Neighbor) AddTransaction(request neighborhood.TransactionRequest) (err error)

func (*Neighbor) GetAmount

func (neighbor *Neighbor) GetAmount(request neighborhood.AmountRequest) (amountResponse *neighborhood.AmountResponse, err error)

func (*Neighbor) GetBlocks

func (neighbor *Neighbor) GetBlocks() (blockResponses []*neighborhood.BlockResponse, err error)

func (*Neighbor) GetTransactions

func (neighbor *Neighbor) GetTransactions() (transactionResponses []neighborhood.TransactionResponse, err error)

func (*Neighbor) Ip

func (neighbor *Neighbor) Ip() string

func (*Neighbor) Mine

func (neighbor *Neighbor) Mine() (err error)

func (*Neighbor) Port

func (neighbor *Neighbor) Port() uint16

func (*Neighbor) SendTargets

func (neighbor *Neighbor) SendTargets(request []neighborhood.TargetRequest) (err error)

func (*Neighbor) StartMining

func (neighbor *Neighbor) StartMining() (err error)

func (*Neighbor) StopMining

func (neighbor *Neighbor) StopMining() (err error)

func (*Neighbor) Target

func (neighbor *Neighbor) Target() string

type Server

type Server interface {
	SetHandle(topic string, handler p2p.Handler)
	Serve() (err error)
}

type Synchronizer

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

func NewSynchronizer

func NewSynchronizer(hostPort uint16, time clock.Time, clientFactory ClientFactory, configurationPath string, logger *log.Logger) (synchronizer *Synchronizer, err error)

func (*Synchronizer) AddTargets

func (synchronizer *Synchronizer) AddTargets(targetRequests []neighborhood.TargetRequest)

func (*Synchronizer) Neighbors

func (synchronizer *Synchronizer) Neighbors() []neighborhood.Neighbor

func (*Synchronizer) StartSynchronization

func (synchronizer *Synchronizer) StartSynchronization()

func (*Synchronizer) Synchronize

func (synchronizer *Synchronizer) Synchronize()

func (*Synchronizer) Wait

func (synchronizer *Synchronizer) Wait()

type Target

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

func NewTarget

func NewTarget(ip string, port uint16) *Target

func (*Target) Ip

func (target *Target) Ip() string

func (*Target) Port

func (target *Target) Port() uint16

func (*Target) Value

func (target *Target) Value() string

type TransactionsPool

type TransactionsPool interface {
	AddTransaction(transactionRequest *neighborhood.TransactionRequest, blockchain Blockchain, neighbors []neighborhood.Neighbor)
	Transactions() []*neighborhood.TransactionResponse
}

type Validator

type Validator interface {
	StartValidation()
	StopValidation()
	Validate()
}

Jump to

Keyboard shortcuts

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