Documentation ¶
Index ¶
- Constants
- func Ack(s Station) (uint64, time.Duration)
- func AdaptorRegister(adaptor ProtoAdaptor)
- func AddAck(s Station, dur time.Duration) (uint64, time.Duration)
- func AddCPU(s Station, dur time.Duration) time.Duration
- func AddErr(s Station, n uint64) uint64
- func AddNetIn(s Station, pkg uint64) uint64
- func AddNetOut(s Station, pkg uint64) uint64
- func AddThread(s Station, c int64) uint64
- func CPU(s Station) time.Duration
- func Err(s Station) uint64
- func GetDDosLimit(t int) int
- func GetTypeByCode(typecode int) reflect.Type
- func NetIn(s Station) uint64
- func NetOut(s Station) uint64
- func ReplyEvent(e *Event, typecode int, data interface{})
- func Reset()
- func Score(s Station) uint64
- func SendEvent(e *Event) (nsent int)
- func SendEvents(es []*Event) (nsent int)
- func SendTo(from, to Station, typecode int, data interface{}) int
- func StationRegister(station Station)
- func StationUnregister(station Station)
- func Thread(s Station) uint64
- type BaseStation
- type BroadcastStation
- type Event
- type Feed
- type LocalStation
- type ProtoAdaptor
- type RemoteStation
- type Router
- func (router *Router) AdaptorRegister(adaptor ProtoAdaptor)
- func (router *Router) GetStationByName(name string) Station
- func (router *Router) SendEvent(e *Event) (nsent int)
- func (router *Router) StationRegister(station Station)
- func (router *Router) StationUnregister(station Station)
- func (router *Router) Subscribe(station Station, channel chan *Event, typecode int, data interface{}) Subscription
- type Station
- type Subscription
Constants ¶
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 AdaptorRegister ¶
func AdaptorRegister(adaptor ProtoAdaptor)
AdaptorRegister register P2P interface to Router
func GetTypeByCode ¶
GetTypeByCode return Type by typecode
func ReplyEvent ¶
ReplyEvent is equivalent to `SendTo(e.To, e.From, typecode, data)`
func SendTo ¶
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'
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 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 ¶
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 ¶
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 (*Router) AdaptorRegister ¶
func (router *Router) AdaptorRegister(adaptor ProtoAdaptor)
func (*Router) GetStationByName ¶
func (*Router) StationRegister ¶
func (*Router) StationUnregister ¶
type Station ¶
func GetStationByName ¶
GetStationByName retrun Station by Station's name
func NewBroadcastStation ¶
func NewLocalStation ¶
func NewRemoteStation ¶
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.