net

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2019 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const CmdSet = 2
View Source
const DefaultPort uint16 = 8484
View Source
const Vite = "vite"

@section Cmd

Variables

View Source
var NULL_ADDRESS = types.Address{}

Functions

This section is empty.

Types

type AccountblockCallback

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

type Broadcaster

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

@section Broadcaster

type Chain

type Chain interface {
	// the second return value mean chunk befor/after file
	GetSubLedgerByHeight(start, count uint64, forward bool) ([]*ledger.CompressedFileMeta, [][2]uint64)
	GetSubLedgerByHash(origin *types.Hash, count uint64, forward bool) ([]*ledger.CompressedFileMeta, [][2]uint64, error)

	// query chunk
	GetConfirmSubLedger(start, end uint64) ([]*ledger.SnapshotBlock, map[types.Address][]*ledger.AccountBlock, error)

	// single
	GetSnapshotBlockByHeight(height uint64) (*ledger.SnapshotBlock, error)
	GetSnapshotBlockByHash(hash *types.Hash) (*ledger.SnapshotBlock, error)
	// batcher
	GetSnapshotBlocksByHash(origin *types.Hash, count uint64, forward, content bool) ([]*ledger.SnapshotBlock, error)
	GetSnapshotBlocksByHeight(height, count uint64, forward, content bool) ([]*ledger.SnapshotBlock, error)

	// single
	GetAccountBlockByHash(blockHash *types.Hash) (*ledger.AccountBlock, error)
	GetAccountBlockByHeight(addr *types.Address, height uint64) (*ledger.AccountBlock, error)

	// batcher
	GetAccountBlocksByHash(addr types.Address, origin *types.Hash, count uint64, forward bool) ([]*ledger.AccountBlock, error)
	GetAccountBlocksByHeight(addr types.Address, start, count uint64, forward bool) ([]*ledger.AccountBlock, error)

	GetLatestSnapshotBlock() *ledger.SnapshotBlock
	GetGenesisSnapshotBlock() *ledger.SnapshotBlock

	Compressor() *compress.Compressor
}

all query include from block

type Config

type Config struct {
	Single bool // for test

	Port     uint16
	Chain    Chain
	Verifier Verifier

	// for topo
	Topology   []string
	Topic      string
	Interval   int64 // second
	TopoEnable bool
}

type Fetcher

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

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

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

@section Broadcaster

type Filter

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

type MsgHandler

type MsgHandler interface {
	ID() string
	Cmds() []ViteCmd
	Handle(msg *p2p.Msg, sender Peer) error
}

type MsgIder

type MsgIder interface {
	MsgID() uint64
}

type Net

type Net interface {
	Syncer
	Fetcher
	Broadcaster
	Receiver
	Protocols() []*p2p.Protocol
	Start(svr p2p.Server) error
	Stop()
	Info() *NodeInfo
	Tasks() []*Task
	AddPlugin(plugin p2p.Plugin)
}

@section Net

func New

func New(cfg *Config) Net

auto from

type NodeInfo

type NodeInfo struct {
	PeerCount int         `json:"peerCount"`
	Peers     []*PeerInfo `json:"peers"`
	Latency   []int64     `json:"latency"` // [0,1,12,24]

}

type Peer

type Peer interface {
	RemoteAddr() *net2.TCPAddr
	FileAddress() *net2.TCPAddr
	SetHead(head types.Hash, height uint64)
	SeeBlock(hash types.Hash)
	SendSnapshotBlocks(bs []*ledger.SnapshotBlock, msgId uint64) (err error)
	SendAccountBlocks(bs []*ledger.AccountBlock, msgId uint64) (err error)
	SendNewSnapshotBlock(b *ledger.SnapshotBlock) (err error)
	SendNewAccountBlock(b *ledger.AccountBlock) (err error)
	Send(code ViteCmd, msgId uint64, payload p2p.Serializable) (err error)
	Report(err error)
	ID() string
	Height() uint64
	Disconnect(reason p2p.DiscReason)
}

@section Peer for protocol handle, not p2p Peer. var errPeerTermed = errors.New("peer has been terminated")

type PeerInfo

type PeerInfo struct {
	ID     string `json:"id"`
	Addr   string `json:"addr"`
	Head   string `json:"head"`
	Height uint64 `json:"height"`
	// MsgReceived        uint64            `json:"msgReceived"`
	// MsgHandled         uint64            `json:"msgHandled"`
	// MsgSend            uint64            `json:"msgSend"`
	// MsgDiscarded       uint64            `json:"msgDiscarded"`
	// MsgReceivedDetail  map[string]uint64 `json:"msgReceived"`
	// MsgDiscardedDetail map[string]uint64 `json:"msgDiscarded"`
	// MsgHandledDetail   map[string]uint64 `json:"msgHandledDetail"`
	// MsgSendDetail      map[string]uint64 `json:"msgSendDetail"`
	Created string `json:"created"`
}

func (*PeerInfo) String

func (p *PeerInfo) String() string

type Receiver

type Receiver interface {
	ReceiveSnapshotBlock(block *ledger.SnapshotBlock, sender Peer) (err error)
	ReceiveAccountBlock(block *ledger.AccountBlock, sender Peer) (err error)

	ReceiveSnapshotBlocks(blocks []*ledger.SnapshotBlock, sender Peer) (err error)
	ReceiveAccountBlocks(blocks []*ledger.AccountBlock, sender Peer) (err error)

	ReceiveNewSnapshotBlock(block *ledger.SnapshotBlock, sender Peer) (err error)
	ReceiveNewAccountBlock(block *ledger.AccountBlock, sender Peer) (err error)

	SubscribeAccountBlock(fn AccountblockCallback) (subId int)
	// if subId is 0, then ignore
	UnsubscribeAccountBlock(subId int)

	// return the subId, use to unsubscibe
	// subId is always larger than 0
	SubscribeSnapshotBlock(fn SnapshotBlockCallback) (subId int)
	// if subId is 0, then ignore
	UnsubscribeSnapshotBlock(subId int)
	// contains filtered or unexported methods
}

@section Receiver

type Request

type Request interface {
	Handle(ctx context, msg *p2p.Msg, peer Peer)
	ID() uint64
	SetID(id uint64)
	Run(ctx context)
	Done(ctx context)
	Catch(err error)
	Expired() bool
	State() reqState
	Req() Request
	Band() (from, to uint64)
	SetBand(from, to uint64)
	SetPeer(peer Peer)
	Peer() Peer
}

type SnapshotBlockCallback

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

@section Subscriber

type Subscriber

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

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

	// return the subId, use to unsubscibe
	// subId is always larger than 0
	SubscribeSyncStatus(fn SyncStateCallback) (subId int)
	// if subId is 0, then ignore
	UnsubscribeSyncStatus(subId int)

	SyncState() SyncState
}

type SyncState

type SyncState uint
const (
	SyncNotStart SyncState = iota
	Syncing
	Syncdone
	Syncerr
	SyncCancel
	SyncDownloaded
)

func (SyncState) String

func (s SyncState) String() string

type SyncStateCallback

type SyncStateCallback = func(SyncState)

type SyncStateFeed

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

func (*SyncStateFeed) Notify

func (s *SyncStateFeed) Notify(st SyncState)

func (*SyncStateFeed) Sub

func (s *SyncStateFeed) Sub(fn SyncStateCallback) int

func (*SyncStateFeed) Unsub

func (s *SyncStateFeed) Unsub(subId int)

type SyncStatus

type SyncStatus struct {
	From     uint64
	To       uint64
	Current  uint64
	Received uint64
	State    SyncState
}

type Syncer

type Syncer interface {
	Status() *SyncStatus
	SubscribeSyncStatus(fn SyncStateCallback) (subId int)
	UnsubscribeSyncStatus(subId int)
	SyncState() SyncState
}

@section Syncer

type Task

type Task struct {
	Msg    string `json:"Msg"`
	Sender string `json:"Sender"`
}

type Verifier

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

type ViteCmd

type ViteCmd p2p.Cmd
const (
	HandshakeCode ViteCmd = iota
	StatusCode
	ForkCode // tell peer it has forked, use for respond GetSnapshotBlocksCode
	GetSubLedgerCode
	GetSnapshotBlocksCode // get snapshotblocks without content
	GetSnapshotBlocksContentCode
	GetFullSnapshotBlocksCode   // get snapshotblocks with content
	GetSnapshotBlocksByHashCode // a batch of hash
	GetSnapshotBlocksContentByHashCode
	GetFullSnapshotBlocksByHashCode
	GetAccountBlocksCode       // query single AccountChain
	GetMultiAccountBlocksCode  // query multi AccountChain
	GetAccountBlocksByHashCode // query accountBlocks by hashList
	GetFilesCode
	GetChunkCode
	SubLedgerCode
	FileListCode
	SnapshotBlocksCode
	SnapshotBlocksContentCode
	FullSnapshotBlocksCode
	AccountBlocksCode
	NewSnapshotBlockCode
	NewAccountBlockCode

	ExceptionCode = 127
)

func (ViteCmd) String

func (t ViteCmd) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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