Documentation ¶
Index ¶
- Constants
- func WriteMsg(writer io.Writer, compressible bool, msg *Msg) (err error)
- type AsyncMsgConn
- type CmdSet
- type Config
- type ConnProperty
- type DiscReason
- type Discovery
- type Handshake
- type Msg
- type MsgReadWriter
- type MsgReader
- type MsgRw
- type MsgWriter
- type NetworkID
- type NodeInfo
- type Peer
- func (p *Peer) CmdSets() []*CmdSet
- func (p *Peer) Disconnect(reason DiscReason)
- func (p *Peer) GetConnProperty() *ConnProperty
- func (p *Peer) ID() discovery.NodeID
- func (p *Peer) IP() net.IP
- func (p *Peer) Info() *PeerInfo
- func (p *Peer) Name() string
- func (p *Peer) RemoteAddr() *net.TCPAddr
- func (p *Peer) String() string
- type PeerInfo
- type PeerSet
- type Protocol
- type Serializable
- type Server
- type Task
Constants ¶
View Source
const ( DefaultMaxPeers uint = 50 DefaultMaxPendingPeers uint = 20 DefaultMaxInboundRatio uint = 2 DefaultPort uint = 8483 DefaultNetID NetworkID = Aquarius )
View Source
const P2PDir = "p2p"
View Source
const Version uint64 = 2
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AsyncMsgConn ¶
type AsyncMsgConn struct {
// contains filtered or unexported fields
}
func NewAsyncMsgConn ¶
func NewAsyncMsgConn(fd net.Conn, handler func(msg *Msg)) *AsyncMsgConn
create an AsyncMsgConn, fd is the basic connection
func (*AsyncMsgConn) Close ¶
func (c *AsyncMsgConn) Close(err error)
func (*AsyncMsgConn) Handshake ¶
func (c *AsyncMsgConn) Handshake(data []byte) (their *Handshake, err error)
send Handshake data, after signature with ed25519 algorithm
func (*AsyncMsgConn) Send ¶
func (c *AsyncMsgConn) Send(cmdset, cmd, id uint64, s Serializable) bool
func (*AsyncMsgConn) SendMsg ¶
func (c *AsyncMsgConn) SendMsg(msg *Msg) bool
send a message asynchronously, put message into a internal buffered channel before send it if the internal channel is full, return false
func (*AsyncMsgConn) Start ¶
func (c *AsyncMsgConn) Start()
type CmdSet ¶
func (*CmdSet) Deserialize ¶
type Config ¶
type Config struct { Name string NetID NetworkID // which network server runs on MaxPeers uint // max peers can be connected MaxPendingPeers uint // max peers waiting for connect MaxInboundRatio uint // max inbound peers: MaxPeers / MaxInboundRatio Port uint // TCP and UDP listen port Database string // the directory for storing node table PrivateKey ed25519.PrivateKey // use for encrypt message, the corresponding public key use for NodeID Protocols []*Protocol // protocols server supported BootNodes []string }
func EnsureConfig ¶
type ConnProperty ¶
type ConnProperty struct { LocalID string `json:"localID"` LocalIP net.IP `json:"localIP"` LocalPort uint16 `json:"localPort"` RemoteID string `json:"remoteID"` RemoteIP net.IP `json:"remoteIP"` RemotePort uint16 `json:"remotePort"` }
func (*ConnProperty) Deproto ¶
func (cp *ConnProperty) Deproto(pb *protos.ConnProperty)
func (*ConnProperty) Deserialize ¶
func (cp *ConnProperty) Deserialize(buf []byte) error
func (*ConnProperty) Proto ¶
func (cp *ConnProperty) Proto() *protos.ConnProperty
func (*ConnProperty) Serialize ¶
func (cp *ConnProperty) Serialize() ([]byte, error)
type DiscReason ¶
type DiscReason uint64
@section peer error
const ( DiscRequested DiscReason = iota DiscNetworkError DiscProtocolError DiscUselessPeer DiscTooManyPeers DiscTooManyPassivePeers DiscAlreadyConnected DiscIncompatibleVersion DiscInvalidIdentity DiscQuitting DiscUnexpectedIdentity DiscSelf DiscReadTimeout DiscResponseTimeout DiscSubprotocolError = 0x10 )
func DeserializeDiscReason ¶
func DeserializeDiscReason(buf []byte) (DiscReason, error)
func ReadDiscReason ¶
func ReadDiscReason(r io.Reader) (DiscReason, error)
func (DiscReason) Deserialize ¶
func (d DiscReason) Deserialize(buf []byte) error
just implement Serializable interface
func (DiscReason) Error ¶
func (d DiscReason) Error() string
func (DiscReason) Serialize ¶
func (d DiscReason) Serialize() ([]byte, error)
func (DiscReason) String ¶
func (d DiscReason) String() string
type Handshake ¶
type Handshake struct { Version uint64 // peer name, use for readability and log Name string // running at which network NetID NetworkID // peer remoteID ID discovery.NodeID // command set supported CmdSets []*CmdSet // peer`s IP RemoteIP net.IP // peer`s Port RemotePort uint16 }
handshake message
func (*Handshake) Deserialize ¶
type Msg ¶
type Msg struct { CmdSetID uint64 Cmd uint64 Id uint64 // as message context Size uint64 // how many bytes in payload, used to quickly determine whether payload is valid Payload []byte ReceivedAt time.Time }
@section Msg
type MsgReadWriter ¶
type MsgRw ¶
type MsgRw struct {
// contains filtered or unexported fields
}
the most basic Msg reader & writer, Thread unsafe
type NodeInfo ¶
type NodeInfo struct { ID string `json:"remoteID"` Name string `json:"name"` Url string `json:"url"` NetID NetworkID `json:"netId"` Address *address `json:"address"` Protocols []string `json:"protocols"` }
@section NodeInfo
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
@section Peer
func (*Peer) Disconnect ¶
func (p *Peer) Disconnect(reason DiscReason)
func (*Peer) GetConnProperty ¶
func (p *Peer) GetConnProperty() *ConnProperty
func (*Peer) RemoteAddr ¶
type PeerInfo ¶
type PeerInfo struct { ID string `json:"remoteID"` Name string `json:"name"` CmdSets []string `json:"caps"` Address string `json:"address"` Inbound bool `json:"inbound"` }
@section PeerInfo
type PeerSet ¶
type PeerSet struct {
// contains filtered or unexported fields
}
@section PeerSet
func NewPeerSet ¶
func NewPeerSet() *PeerSet
type Protocol ¶
type Protocol struct { // description of the protocol Name string // use for message command set, should be unique ID uint64 // read and write Msg with rw Handle func(p *Peer, rw MsgReadWriter) error }
@section protocol
type Serializable ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.