Documentation
¶
Index ¶
- Constants
- func Logger(l *zap.Logger) func(next http.Handler) http.Handler
- func NewAPI(interrupt <-chan struct{}, storage *storage, registry *Registry, ...) (*api, error)
- func NewDispatcher(interrupt <-chan struct{}, bind string, opts *Options, registry *Registry) *dispatcher
- func NewDistributor(shutdown <-chan struct{}, drawer *drawer) (*distributor, error)
- func NewDrawer(storage *storage) (*drawer, error)
- func NewStorage(path string, genesis proto.BlockID, scheme proto.Scheme) (*storage, error)
- type Conn
- type ConnHandler
- type Fork
- type ForkByHeightLengthAndPeersCount
- type Handler
- type NodeForkInfo
- type NodeState
- type Options
- type PeerForkInfo
- type PeerNode
- type PeerNodesByName
- type PublicAddressInfo
- type Registry
- func (r *Registry) Activate(addr net.Addr, h proto.Handshake) error
- func (r *Registry) Addresses() ([]net.Addr, error)
- func (r *Registry) AppendAddresses(addresses []net.TCPAddr) int
- func (r *Registry) Check(addr net.Addr, application string) error
- func (r *Registry) Connections() []PeerNode
- func (r *Registry) Deactivate(addr net.Addr) error
- func (r *Registry) FriendlyPeers() ([]PeerNode, error)
- func (r *Registry) PeerConnected(addr net.Addr) error
- func (r *Registry) PeerDiscarded(addr net.Addr) error
- func (r *Registry) PeerGreeted(addr net.Addr, nonce uint64, name string, v proto.Version) error
- func (r *Registry) PeerHostile(addr net.Addr, nonce uint64, name string, v proto.Version) error
- func (r *Registry) Peers() ([]PeerNode, error)
- func (r *Registry) SuggestVersion(addr net.Addr) (proto.Version, error)
- func (r *Registry) TakeAvailableAddresses() ([]net.Addr, error)
- type Server
Constants ¶
View Source
const ( DefaultRecvBufSize = 4 << 10 // Default size of the receiving buffer, 4096 bytes. DefaultSendQueueLen = 1 << 7 // Default length of the sending queue (size of the channel) - 64 packets. )
View Source
const ( StopImmediately = iota // StopImmediately mean stop directly, the cached data maybe will not send. StopGracefullyAndWait // StopGracefullyAndWait stop and block until cached data sent. )
View Source
const ( NodeUnknown = iota // Unknown node NodeDiscarded // Network connection to the node failed NodeResponding // Network connection to the node was successful NodeGreeted // Handshake with the node was successful NodeHostile // The node has different blockchain scheme )
Variables ¶
This section is empty.
Functions ¶
func Logger ¶
Logger is a middleware that logs the start and end of each request, along with some useful data about what was requested, what the response status was, and how long it took to return.
func NewDispatcher ¶
func NewDistributor ¶
func NewDistributor(shutdown <-chan struct{}, drawer *drawer) (*distributor, error)
Types ¶
type Conn ¶
type Conn struct { sync.Mutex Opts *Options RawConn net.Conn UserData interface{} SendDropped uint32 // contains filtered or unexported fields }
func (*Conn) DialAndServe ¶
func (*Conn) DroppedPacket ¶
DroppedPacket return the total dropped packet.
func (*Conn) IsStopped ¶
IsStopped return true if Conn is stopped or stopping, otherwise return false.
type ConnHandler ¶
type ConnHandler struct {
// contains filtered or unexported fields
}
func NewConnHandler ¶
func (*ConnHandler) OnAccept ¶
func (h *ConnHandler) OnAccept(conn *Conn)
func (*ConnHandler) OnClose ¶
func (h *ConnHandler) OnClose(conn *Conn)
func (*ConnHandler) OnConnect ¶
func (h *ConnHandler) OnConnect(conn *Conn)
func (*ConnHandler) OnReceive ¶
func (h *ConnHandler) OnReceive(conn *Conn, buf []byte)
type Fork ¶
type Fork struct { Longest bool `json:"longest"` // Indicates that the fork is the longest Height int `json:"height"` // The height of the last block in the fork HeadBlock proto.BlockID `json:"head_block"` // The last block of the fork LastCommonHeight int `json:"last_common_height"` // The height of the last common block LastCommonBlock proto.BlockID `json:"last_common_block"` // The last common block with the longest fork Length int `json:"length"` // The number of blocks since the last common block Peers []PeerForkInfo `json:"peers"` // Peers that seen on the fork }
type ForkByHeightLengthAndPeersCount ¶
type ForkByHeightLengthAndPeersCount []Fork
func (ForkByHeightLengthAndPeersCount) Len ¶
func (a ForkByHeightLengthAndPeersCount) Len() int
func (ForkByHeightLengthAndPeersCount) Less ¶
func (a ForkByHeightLengthAndPeersCount) Less(i, j int) bool
func (ForkByHeightLengthAndPeersCount) Swap ¶
func (a ForkByHeightLengthAndPeersCount) Swap(i, j int)
type NodeForkInfo ¶
type Options ¶
type Options struct { Handler Handler RecvBufSize int // default is DefaultRecvBufSize if you don't set. SendQueueLen int // default is DefaultSendQueueLen if you don't set. AsyncWrite bool // default is DefaultAsyncWrite if you don't set. NoDelay bool // default is true KeepAlive bool // default is false KeepAlivePeriod time.Duration // default is 0, mean use system setting. ReadDeadline time.Duration // default is 0, means Read will not time out. WriteDeadline time.Duration // default is 0, means Write will not time out. }
func NewOptions ¶
type PeerForkInfo ¶
type PeerNode ¶
type PeerNode struct { Address net.IP `json:"address"` Port uint16 `json:"port"` Nonce uint64 `json:"nonce"` Name string `json:"name"` Version proto.Version `json:"version"` Attempts int `json:"attempts"` NextAttempt time.Time `json:"next_attempt"` State NodeState `json:"state"` }
func (PeerNode) MarshalBinary ¶
func (*PeerNode) UnmarshalBinary ¶
type PeerNodesByName ¶
type PeerNodesByName []PeerNode
func (PeerNodesByName) Len ¶
func (a PeerNodesByName) Len() int
func (PeerNodesByName) Less ¶
func (a PeerNodesByName) Less(i, j int) bool
func (PeerNodesByName) Swap ¶
func (a PeerNodesByName) Swap(i, j int)
type PublicAddressInfo ¶
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func (*Registry) Check ¶
Check verifies that given address with the parameters could be accepted or connected.
func (*Registry) Connections ¶
func (*Registry) FriendlyPeers ¶
func (*Registry) PeerGreeted ¶
func (*Registry) PeerHostile ¶
func (*Registry) SuggestVersion ¶
type Server ¶
type Server struct { Opts *Options // contains filtered or unexported fields }
func (*Server) ListenAndServe ¶
Click to show internal directories.
Click to hide internal directories.