net

package
v0.0.3-chain-bsopt Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2018 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HandshakeCode cmd = 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
)
View Source
const CmdSet = 2
View Source
const CmdSetName = "vite"

@section Cmd

View Source
const DefaultPort uint16 = 8484
View Source
const INIT_ID uint64 = 1

@section requestPool

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)

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)

	GetSnapshotBlocksByHash(origin *types.Hash, count uint64, forward, content bool) ([]*ledger.SnapshotBlock, error)
	GetSnapshotBlocksByHeight(height, count uint64, forward, content bool) ([]*ledger.SnapshotBlock, 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)
	// single
	GetAccountBlockByHash(blockHash *types.Hash) (*ledger.AccountBlock, error)
	GetAccountBlockByHeight(addr *types.Address, height uint64) (*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
}

type Fetcher

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

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

@section Broadcaster

type Filter

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

type MsgHandler

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

type Net

type Net interface {
	Syncer
	Fetcher
	Broadcaster
	Receiver
	Protocols() []*p2p.Protocol
	Start(svr *p2p.Server) error
	Stop()
}

@section Net

func New

func New(cfg *Config) Net

auto from

type Peer

type Peer struct {
	*p2p.Peer

	ID string

	CmdSet      uint64 // which cmdSet it belongs
	KnownBlocks *cuckoofilter.CuckooFilter
	// contains filtered or unexported fields
}

func (*Peer) FileAddress

func (p *Peer) FileAddress() *net2.TCPAddr

func (*Peer) Handshake

func (p *Peer) Handshake(our *message.HandShake) error

func (*Peer) Info added in v1.3.2

func (p *Peer) Info() *PeerInfo

func (*Peer) ReadHandshake

func (p *Peer) ReadHandshake() (their *message.HandShake, err error)

func (*Peer) SeeBlock

func (p *Peer) SeeBlock(hash types.Hash)

func (*Peer) Send

func (p *Peer) Send(code cmd, msgId uint64, payload p2p.Serializable) error

func (*Peer) SendAccountBlocks

func (p *Peer) SendAccountBlocks(bs []*ledger.AccountBlock, msgId uint64) (err error)

func (*Peer) SendNewAccountBlock

func (p *Peer) SendNewAccountBlock(b *ledger.AccountBlock) (err error)

func (*Peer) SendNewSnapshotBlock

func (p *Peer) SendNewSnapshotBlock(b *ledger.SnapshotBlock) (err error)

func (*Peer) SendSnapshotBlocks

func (p *Peer) SendSnapshotBlocks(bs []*ledger.SnapshotBlock, msgId uint64) (err error)

func (*Peer) SendSubLedger

func (p *Peer) SendSubLedger(bs []*ledger.SnapshotBlock, abs []*ledger.AccountBlock, msgId uint64) (err error)

func (*Peer) SetHead

func (p *Peer) SetHead(head types.Hash, height uint64)

type PeerInfo

type PeerInfo struct {
	ID     string `json:"id"`
	Addr   string `json:"addr"`
	Head   string `json:"head"`
	Height uint64 `json:"height"`
}

func (*PeerInfo) String

func (p *PeerInfo) String() string

type Peers

type Peers []*Peer

@implementation sort.Interface

func (Peers) Len

func (s Peers) Len() int

func (Peers) Less

func (s Peers) Less(i, j int) bool

func (Peers) Swap

func (s Peers) Swap(i, j int)

type Receiver

type Receiver interface {
	ReceiveSnapshotBlocks(blocks []*ledger.SnapshotBlock)
	ReceiveAccountBlocks(blocks []*ledger.AccountBlock)

	ReceiveNewSnapshotBlock(block *ledger.SnapshotBlock)
	ReceiveNewAccountBlock(block *ledger.AccountBlock)

	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)
}

@section Receiver

type Request

type Request interface {
	Handle(ctx *context, msg *p2p.Msg, peer *Peer)
	ID() uint64
	Run(ctx *context)
	Done(err error)
	Expired() bool
	State() reqState
}

type RequestPool

type RequestPool interface {
	Add(r Request) bool // can add request or not
	Retry(r uint64) bool
	Del(r uint64) bool
	MsgID() uint64
}

type SnapshotBlockCallback

type SnapshotBlockCallback = func(block *ledger.SnapshotBlock)

@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 int32
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
	State   SyncState
}

type Syncer

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

@section Syncer

type Verifier

type Verifier interface {
	VerifyforP2P(block *ledger.AccountBlock) bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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