net

package
v2.2.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: GPL-3.0 Imports: 37 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const DefaultFilePort = 8484
View Source
const DefaultForwardStrategy = "cross"
View Source
const ID = 1

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountBlockCallback

type AccountBlockCallback = func(addr types.Address, block *ledger.AccountBlock, source types.BlockSource)

AccountBlockCallback will be invoked when receive a block, source mark where the block come from: broadcast, sync or fetch

type BlockSubscriber added in v1.3.0

type BlockSubscriber interface {
	// SubscribeAccountBlock return the subId, always larger than 0, use to unsubscribe
	SubscribeAccountBlock(fn AccountBlockCallback) (subId int)
	// UnsubscribeAccountBlock if subId is 0, then ignore
	UnsubscribeAccountBlock(subId int)

	// SubscribeSnapshotBlock return the subId, always larger than 0, use to unsubscribe
	SubscribeSnapshotBlock(fn SnapshotBlockCallback) (subId int)
	// UnsubscribeSnapshotBlock if subId is 0, then ignore
	UnsubscribeSnapshotBlock(subId int)
}

A BlockSubscriber implementation can be subscribed and Unsubscribed, when got chain block, should notify subscribers

type Broadcaster

type Broadcaster interface {
	BroadcastSnapshotBlock(block *ledger.SnapshotBlock)
	BroadcastSnapshotBlocks(blocks []*ledger.SnapshotBlock)
	BroadcastAccountBlock(block *ledger.AccountBlock)
	BroadcastAccountBlocks(blocks []*ledger.AccountBlock)
}

A Broadcaster implementation can send blocks to the peers connected

type Chain

type Chain interface {
	// contains filtered or unexported methods
}

type Chunk

type Chunk struct {
	SnapshotChunks []ledger.SnapshotChunk
	SnapshotRange  [2]*ledger.HashHeight
	AccountRange   map[types.Address][2]*ledger.HashHeight
	HashMap        map[types.Hash]struct{}
	Source         types.BlockSource
	// contains filtered or unexported fields
}

Chunk means a chain chunk, contains snapshot blocks and dependent account blocks, SnapshotRange means the chunk range, the first HashHeight is the prevHash and prevHeight. eg. Chunk is from 101 to 200, SnapshotChunks is [101 ... 200], but SnapshotRange is [100, 200]. AccountRange like SnapshotRange but describe every account chain. HashMap record all blocks hash in Chunk, it can quickly tell if a block is in the chunk.

type ChunkReader

type ChunkReader interface {
	Peek() *Chunk
	Pop(endHash types.Hash)
}

type Chunks

type Chunks []*Chunk

func (Chunks) Len

func (cs Chunks) Len() int

func (Chunks) Less

func (cs Chunks) Less(i, j int) bool

func (Chunks) Swap

func (cs Chunks) Swap(i, j int)

type Config

type Config struct {
	Single             bool
	FileListenAddress  string
	TraceEnabled       bool
	ForwardStrategy    string   // default `cross`
	AccessControl      string   `json:"AccessControl"` // producer special any
	AccessAllowKeys    []string `json:"AccessAllowKeys"`
	AccessDenyKeys     []string `json:"AccessDenyKeys"`
	BlackBlockHashList []string

	MinePrivateKey ed25519.PrivateKey
	P2PPrivateKey  ed25519.PrivateKey
	Chain
	Verifier
}

type Connector

type Connector interface {
	ConnectNode(node *vnode.Node) error
}

type Consensus

type Consensus interface {
	SubscribeProducers(gid types.Gid, id string, fn func(event consensus.ProducersEvent))
	UnSubscribe(gid types.Gid, id string)
	API() consensus.APIReader
}

type DownloaderStatus

type DownloaderStatus struct {
	Tasks       []string               `json:"tasks"`
	Connections []SyncConnectionStatus `json:"connections"`
}

type Fetcher

type Fetcher interface {
	FetchSnapshotBlocks(start types.Hash, count uint64)

	FetchSnapshotBlocksWithHeight(hash types.Hash, height uint64, count uint64)

	// FetchAccountBlocks address is optional
	FetchAccountBlocks(start types.Hash, count uint64, address *types.Address)

	// FetchAccountBlocksWithHeight add snapshot height
	FetchAccountBlocksWithHeight(start types.Hash, count uint64, address *types.Address, sHeight uint64)
}

A Fetcher implementation can request the wanted blocks to peers

type FilePoolStatus added in v1.3.0

type FilePoolStatus struct {
	Connections []SyncConnectionStatus `json:"connections"`
}

type FileServerStatus added in v1.3.0

type FileServerStatus struct {
	Connections []SyncConnectionStatus `json:"connections"`
}

type InvalidHash added in v1.3.0

type InvalidHash struct {
	HashList []string `json:"hashList"`
}

type IrreversibleReader

type IrreversibleReader interface {
	GetIrreversibleBlock() *ledger.SnapshotBlock
}

type MsgIder

type MsgIder interface {
	MsgID() p2p.MsgId
}

type Net

type Net interface {
	p2p.Protocol
	Syncer
	Fetcher
	Broadcaster
	BlockSubscriber
	Init(consensus Consensus, irreader IrreversibleReader)
	Start(svr p2p.P2P) error
	Stop() error
	Info() NodeInfo
	Trace()
}

func New

func New(cfg Config) Net

type NodeInfo

type NodeInfo struct {
	p2p.NodeInfo
	Height  uint64           `json:"height"`
	Peers   []PeerInfo       `json:"peers"`
	Latency []int64          `json:"latency"` // [0,1,12,24]
	Server  FileServerStatus `json:"server"`
}

type Peer

type Peer interface {
	p2p.Peer
	// contains filtered or unexported methods
}

Peer for protocol handle, not p2p Peer.

type PeerInfo

type PeerInfo struct {
	p2p.PeerInfo
	Peers []string `json:"peers"`
}

PeerInfo is for api

type SnapshotBlockCallback

type SnapshotBlockCallback = func(block *ledger.SnapshotBlock, source types.BlockSource)

SnapshotBlockCallback will be invoked when receive a block, source mark where the block come from: broadcast, sync or fetch

type Subscriber

type Subscriber interface {
	BlockSubscriber
	SyncStateSubscriber
}

type SyncConnectionStatus

type SyncConnectionStatus struct {
	Address string `json:"address"`
	Speed   string `json:"speed"`
	Task    string `json:"task"`
}

type SyncDetail added in v1.3.0

type SyncDetail struct {
	SyncStatus
	DownloaderStatus
	Chunks [][2]*ledger.HashHeight `json:"chunks"`
	Caches interfaces.SegmentList  `json:"caches"`
}

type SyncState

type SyncState byte
const (
	SyncInit SyncState = iota
	Syncing
	SyncDone
	SyncError
	SyncCancel
)

func (SyncState) MarshalText

func (s SyncState) MarshalText() (text []byte, err error)
Example
var s SyncState

data, err := s.MarshalText()
if err != nil {
	panic(err)
}

fmt.Printf("%s\n", data)
Output:

Sync Not Start

func (SyncState) String

func (s SyncState) String() string

func (*SyncState) UnmarshalText

func (s *SyncState) UnmarshalText(text []byte) error

type SyncStateCallback

type SyncStateCallback = func(SyncState)

SyncStateCallback will be invoked when sync state change, the param is state after change

type SyncStateSubscriber added in v1.3.0

type SyncStateSubscriber interface {
	// SubscribeSyncStatus return the subId, always larger than 0, use to unsubscribe
	SubscribeSyncStatus(fn SyncStateCallback) (subId int)
	// UnsubscribeSyncStatus if subId is 0, then ignore
	UnsubscribeSyncStatus(subId int)

	// SyncState return the latest sync state_bak
	SyncState() SyncState
}

type SyncStatus

type SyncStatus struct {
	From    uint64    `json:"from"`
	To      uint64    `json:"to"`
	Current uint64    `json:"current"`
	State   SyncState `json:"state"`
	Status  string    `json:"status"`
}

type Syncer

type Syncer interface {
	SyncStateSubscriber
	ChunkReader
	Status() SyncStatus
	Detail() SyncDetail
}

A Syncer implementation can synchronise blocks to peers

type Tracer

type Tracer interface {
	Trace()
	// contains filtered or unexported methods
}

type Verifier

type Verifier interface {
	VerifyNetSb(block *ledger.SnapshotBlock) error
	VerifyNetAb(block *ledger.AccountBlock) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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