internal

package
v0.10.6 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: MIT Imports: 31 Imported by: 0

Documentation

Index

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

func Logger(l *zap.Logger) func(next http.Handler) http.Handler

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 NewAPI

func NewAPI(interrupt <-chan struct{}, storage *storage, registry *Registry, drawer *drawer, bind string) (*api, error)

func NewDispatcher

func NewDispatcher(interrupt <-chan struct{}, bind string, opts *Options, registry *Registry) *dispatcher

func NewDistributor

func NewDistributor(shutdown <-chan struct{}, drawer *drawer) (*distributor, error)

func NewDrawer

func NewDrawer(storage *storage) (*drawer, error)

func NewStorage

func NewStorage(path string, genesis proto.BlockID, scheme proto.Scheme) (*storage, error)

Types

type Conn

type Conn struct {
	sync.Mutex
	Opts     *Options
	RawConn  net.Conn
	UserData interface{}

	SendDropped uint32
	// contains filtered or unexported fields
}

func NewConn

func NewConn(opts *Options) *Conn

NewConn return new connection.

func (*Conn) DialAndServe

func (c *Conn) DialAndServe(addr string) error

func (*Conn) DroppedPacket

func (c *Conn) DroppedPacket() uint32

DroppedPacket return the total dropped packet.

func (*Conn) IsStopped

func (c *Conn) IsStopped() bool

IsStopped return true if Conn is stopped or stopping, otherwise return false.

func (*Conn) RecvBytes

func (c *Conn) RecvBytes() uint64

RecvBytes returns the total number of bytes received over the connection.

func (*Conn) Send

func (c *Conn) Send(buf []byte) (int, error)

func (*Conn) SendBytes

func (c *Conn) SendBytes() uint64

SendBytes returns the total number of bytes sent over the connection.

func (*Conn) Stop

func (c *Conn) Stop(mode int)

Stop stops the conn.

func (*Conn) String

func (c *Conn) String() string

type ConnHandler

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

func NewConnHandler

func NewConnHandler(scheme byte, name string, nonce uint64, addr net.TCPAddr, registry *Registry, newConn, closeConn, score chan<- *Conn, ids chan<- idsEvent, blocks chan<- blockEvent) *ConnHandler

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 (ForkByHeightLengthAndPeersCount) Less

func (ForkByHeightLengthAndPeersCount) Swap

func (a ForkByHeightLengthAndPeersCount) Swap(i, j int)

type Handler

type Handler interface {
	OnAccept(*Conn)          // OnAccept occurs then server accepts new connection.
	OnConnect(*Conn)         // OnConnect happens on new client connection.
	OnReceive(*Conn, []byte) // OnReceive executes on new bytes arrival.
	OnClose(*Conn)           // OnClose fires then connection is closed.
}

type NodeForkInfo

type NodeForkInfo struct {
	Address    net.IP        `json:"address"`
	Nonce      int           `json:"nonce"`
	Name       string        `json:"name"`
	Version    proto.Version `json:"version"`
	OnFork     Fork          `json:"on_fork"`
	OtherForks []Fork        `json:"other_forks"`
}

type NodeState

type NodeState byte

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

func NewOptions(h Handler) *Options

type PeerForkInfo

type PeerForkInfo struct {
	Peer    net.IP        `json:"peer"`
	Lag     int           `json:"lag"`
	Name    string        `json:"name"`
	Version proto.Version `json:"version"`
}

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 (a PeerNode) MarshalBinary() ([]byte, error)

func (PeerNode) String

func (a PeerNode) String() string

func (*PeerNode) UnmarshalBinary

func (a *PeerNode) UnmarshalBinary(data []byte) error

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 PublicAddressInfo struct {
	Address         string    `json:"address"`
	Version         string    `json:"version"`
	Status          string    `json:"status"`
	Attempts        int       `json:"attempts"`
	NextAttemptTime time.Time `json:"next_attempt_time"`
}

type Registry

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

func NewRegistry

func NewRegistry(scheme byte, self net.Addr, versions []proto.Version, storage *storage) *Registry

func (*Registry) Activate

func (r *Registry) Activate(addr net.Addr, h proto.Handshake) error

func (*Registry) Addresses

func (r *Registry) Addresses() ([]net.Addr, error)

func (*Registry) AppendAddresses

func (r *Registry) AppendAddresses(addresses []net.TCPAddr) int

func (*Registry) Check

func (r *Registry) Check(addr net.Addr, application string) error

Check verifies that given address with the parameters could be accepted or connected.

func (*Registry) Connections

func (r *Registry) Connections() []PeerNode

func (*Registry) Deactivate

func (r *Registry) Deactivate(addr net.Addr) error

func (*Registry) FriendlyPeers

func (r *Registry) FriendlyPeers() ([]PeerNode, error)

func (*Registry) PeerConnected

func (r *Registry) PeerConnected(addr net.Addr) error

func (*Registry) PeerDiscarded

func (r *Registry) PeerDiscarded(addr net.Addr) error

func (*Registry) PeerGreeted

func (r *Registry) PeerGreeted(addr net.Addr, nonce uint64, name string, v proto.Version) error

func (*Registry) PeerHostile

func (r *Registry) PeerHostile(addr net.Addr, nonce uint64, name string, v proto.Version) error

func (*Registry) Peers

func (r *Registry) Peers() ([]PeerNode, error)

func (*Registry) SuggestVersion

func (r *Registry) SuggestVersion(addr net.Addr) (proto.Version, error)

func (*Registry) TakeAvailableAddresses

func (r *Registry) TakeAvailableAddresses() ([]net.Addr, error)

type Server

type Server struct {
	Opts *Options
	// contains filtered or unexported fields
}

func NewServer

func NewServer(opts *Options) *Server

func (*Server) IsStopped

func (s *Server) IsStopped() bool

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(addr string) error

func (*Server) Serve

func (s *Server) Serve(l net.Listener)

func (*Server) Stop

func (s *Server) Stop(mode int)

func (*Server) Stopped

func (s *Server) Stopped() <-chan struct{}

Jump to

Keyboard shortcuts

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