event

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2020 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	P2PRouterTestInt      int = iota // 0
	P2PRouterTestInt64               // 1
	P2PRouterTestString              // 2
	P2PGetStatus                     // 3 Status request
	P2PStatusMsg                     // 4 Status response
	P2PGetBlockHashMsg               // 5 BlockHash request
	P2PGetBlockHeadersMsg            // 6 BlockHeader request
	P2PGetBlockBodiesMsg             // 7 BlockBodies request
	P2PBlockHeadersMsg               // 8 BlockHeader response
	P2PBlockBodiesMsg                // 9 BlockBodies response
	P2PBlockHashMsg                  // 10 BlockHash response
	P2PNewBlockHashesMsg             // 11 NewBlockHash notify
	P2PTxMsg                         // 12 TxMsg notify
	P2PEndSize
	ChainHeadEv         = 1023 + iota - P2PEndSize // 1024 when blockchain insert or miner mined new block
	NewPeerNotify                                  // 1025 emit when remote peer incoming but needed to check chainID and genesis block
	DelPeerNotify                                  // 1026 emit when remote peer disconnected
	DisconectCtrl                                  // 1027 emit if needed to let remote peer disconnect
	NewPeerPassedNotify                            // 1028 emit when remote peer had same chain ID and genesis block
	OneMinuteLimited                               // 1029 add peer to blacklist
	NewMinedEv                                     // 1030 emit when new block was mined
	NewTxs                                         // 1031 emit when new transactions needed to broadcast
	EndSize
)

Type enumerator

Variables

This section is empty.

Functions

func Ack

func Ack(s Station) (uint64, time.Duration)

func AdaptorRegister

func AdaptorRegister(adaptor ProtoAdaptor)

AdaptorRegister register P2P interface to Router

func AddAck

func AddAck(s Station, dur time.Duration) (uint64, time.Duration)

func AddCPU

func AddCPU(s Station, dur time.Duration) time.Duration

func AddErr

func AddErr(s Station, n uint64) uint64

func AddNetIn

func AddNetIn(s Station, pkg uint64) uint64

func AddNetOut

func AddNetOut(s Station, pkg uint64) uint64

func AddThread

func AddThread(s Station, c int64) uint64

func CPU

func CPU(s Station) time.Duration

func Err

func Err(s Station) uint64

func GetDDosLimit

func GetDDosLimit(t int) int

GetDDosLimit get messagetype req limit per second

func GetTypeByCode

func GetTypeByCode(typecode int) reflect.Type

GetTypeByCode return Type by typecode

func NetIn

func NetIn(s Station) uint64

func NetOut

func NetOut(s Station) uint64

func ReplyEvent

func ReplyEvent(e *Event, typecode int, data interface{})

ReplyEvent is equivalent to `SendTo(e.To, e.From, typecode, data)`

func Reset

func Reset()

Reset ntended for testing。

func Score

func Score(s Station) uint64

func SendEvent

func SendEvent(e *Event) (nsent int)

SendEvent send event

func SendEvents

func SendEvents(es []*Event) (nsent int)

SendEvents .

func SendTo

func SendTo(from, to Station, typecode int, data interface{}) int

SendTo is equivalent to SendEvent(&Event{From: from, To: to, Type: typecode, Data: data})

func StationRegister

func StationRegister(station Station)

StationRegister register 'Station' to Router

func StationUnregister

func StationUnregister(station Station)

StationUnregister unregister 'Station'

func Thread

func Thread(s Station) uint64

Types

type BaseStation

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

func (*BaseStation) Data

func (bs *BaseStation) Data() interface{}

func (*BaseStation) Name

func (bs *BaseStation) Name() string

type BroadcastStation

type BroadcastStation struct {
	BaseStation
}

func (*BroadcastStation) IsBroadcast

func (*BroadcastStation) IsBroadcast() bool

func (*BroadcastStation) IsRemote

func (*BroadcastStation) IsRemote() bool

type Event

type Event struct {
	From     Station
	To       Station
	Typecode int
	Data     interface{}
}

Event is including normal event and p2p event

type Feed

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

Feed implements one-to-many subscriptions where the carrier of events is a channel. Values sent to a Feed are delivered to all subscribed channels simultaneously.

Feeds can only be used with a single type. The type is determined by the first Send or Subscribe operation. Subsequent calls to these methods panic if the type does not match.

The zero value is ready to use.

func (*Feed) Send

func (f *Feed) Send(value interface{}) (nsent int)

Send delivers to all subscribed channels simultaneously. It returns the number of subscribers that the value was sent to.

func (*Feed) Subscribe

func (f *Feed) Subscribe(channel interface{}) Subscription

Subscribe adds a channel to the feed. Future sends will be delivered on the channel until the subscription is canceled. All channels added must have the same element type.

The channel should have ample buffer space to avoid blocking other subscribers. Slow subscribers are not dropped.

type LocalStation

type LocalStation struct {
	BaseStation
}

func (*LocalStation) IsBroadcast

func (*LocalStation) IsBroadcast() bool

func (*LocalStation) IsRemote

func (*LocalStation) IsRemote() bool

type ProtoAdaptor

type ProtoAdaptor interface {
	SendOut(*Event) error
}

ProtoAdaptor used to send out event

type RemoteStation

type RemoteStation struct {
	BaseStation
}

func (*RemoteStation) IsBroadcast

func (*RemoteStation) IsBroadcast() bool

func (*RemoteStation) IsRemote

func (*RemoteStation) IsRemote() bool

type Router

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

Router Router all events

func New

func New() *Router

New returns an initialized Router instance.

func (*Router) AdaptorRegister

func (router *Router) AdaptorRegister(adaptor ProtoAdaptor)

func (*Router) GetStationByName

func (router *Router) GetStationByName(name string) Station

func (*Router) SendEvent

func (router *Router) SendEvent(e *Event) (nsent int)

func (*Router) StationRegister

func (router *Router) StationRegister(station Station)

func (*Router) StationUnregister

func (router *Router) StationUnregister(station Station)

func (*Router) Subscribe

func (router *Router) Subscribe(station Station, channel chan *Event, typecode int, data interface{}) Subscription

type Station

type Station interface {
	Name() string
	IsRemote() bool
	IsBroadcast() bool
	Data() interface{}
}

func GetStationByName

func GetStationByName(name string) Station

GetStationByName retrun Station by Station's name

func NewBroadcastStation

func NewBroadcastStation(name string, data interface{}) Station

func NewLocalStation

func NewLocalStation(name string, data interface{}) Station

func NewRemoteStation

func NewRemoteStation(name string, data interface{}) Station

func WorstStation

func WorstStation() Station

type Subscription

type Subscription interface {
	Err() <-chan error // returns the error channel
	Unsubscribe()      // cancels sending of events, closing the error channel
}

Subscription represents a stream of events. The carrier of the events is typically a channel, but isn't part of the interface.

Subscriptions can fail while established. Failures are reported through an error channel. It receives a value if there is an issue with the subscription (e.g. the network connection delivering the events has been closed). Only one value will ever be sent.

The error channel is closed when the subscription ends successfully (i.e. when the source of events is closed). It is also closed when Unsubscribe is called.

The Unsubscribe method cancels the sending of events. You must call Unsubscribe in all cases to ensure that resources related to the subscription are released. It can be called any number of times.

func Subscribe

func Subscribe(station Station, channel chan *Event, typecode int, data interface{}) Subscription

Subscribe .

Jump to

Keyboard shortcuts

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