Documentation ¶
Index ¶
- Constants
- func WriteMsg(writer io.Writer, msg *Msg) (err error)
- type Cmd
- type CmdSet
- type Config
- type ConnProperty
- type DiscReason
- type Handshake
- type Msg
- type MsgReadWriter
- type MsgReader
- type MsgWriter
- type NodeInfo
- type P2PVersion
- 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 Plugin
- type ProtoFrame
- type Protocol
- type Serializable
- type Server
- type Transport
Constants ¶
View Source
const ( DefaultMaxPeers uint = 50 DefaultMaxPendingPeers uint = 20 DefaultMaxInboundRatio uint = 2 DefaultPort uint = 8483 DefaultNetID = network.Aquarius DefaultMinPeers = 5 )
View Source
const DefaultAddr = "0.0.0.0:8483"
View Source
const Dirname = "p2p"
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct { Discovery bool Name string NetID network.ID // 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 Addr string // TCP and UDP listen port DataDir string // the directory for storing node table, default is "~/viteisbest/p2p" PeerKey ed25519.PrivateKey // use for encrypt message, the corresponding public key use for NodeID ExtNodeData []byte // extension data for Node Protocols []*Protocol // protocols server supported BootNodes []string // nodes as discovery seed StaticNodes []string // nodes to connect }
Config is the essential configuration to create a p2p.server
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"` }
@section ConnProperty
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 + 1 DiscNetworkError DiscAllProtocolDone DiscProtocolError DiscUselessPeer DiscTooManyPeers DiscTooManyInboundPeers DiscAlreadyConnected DiscIncompatibleVersion DiscInvalidIdentity DiscQuitting DiscSelf DiscReadTimeout DiscReadError DiscResponseTimeout DiscUnKnownProtocol DiscHandshakeFail )
func DeserializeDiscReason ¶
func DeserializeDiscReason(buf []byte) (reason DiscReason, err 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 { // peer name, use for readability and log Name string // peer remoteID ID discovery.NodeID // command set supported CmdSets []CmdSet // peer`s IP RemoteIP net.IP // peer`s Port RemotePort uint16 // tell peer our tcp listen port, could use for update discovery info Port uint16 }
handshake message
func (*Handshake) Deserialize ¶
type Msg ¶
type Msg struct { CmdSet CmdSet Cmd Cmd Id uint64 // as message context Payload []byte ReceivedAt time.Time SendAt time.Time }
@section Msg
type MsgReadWriter ¶
type NodeInfo ¶
type NodeInfo struct { ID string `json:"remoteID"` Name string `json:"name"` Url string `json:"url"` NetID network.ID `json:"netId"` Address *address `json:"address"` Protocols []string `json:"protocols"` }
NodeInfo represent current p2p node
type 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:"id"` Name string `json:"name"` CmdSets []string `json:"cmdSets"` 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
func (*PeerSet) DisconnectAll ¶ added in v1.2.0
func (s *PeerSet) DisconnectAll()
type ProtoFrame ¶
type ProtoFrame struct { *Protocol Received map[Cmd]uint64 Discarded map[Cmd]uint64 Send map[Cmd]uint64 // contains filtered or unexported fields }
func (*ProtoFrame) ReadMsg ¶
func (pf *ProtoFrame) ReadMsg() (msg *Msg, err error)
func (*ProtoFrame) WriteMsg ¶
func (pf *ProtoFrame) WriteMsg(msg *Msg) (err error)
type Protocol ¶
type Protocol struct { // description of the protocol Name string // use for message command set, should be unique ID CmdSet // read and write Msg with rw Handle func(p *Peer, rw *ProtoFrame) error }
@section protocol
type Serializable ¶
type Server ¶
type Server interface { Start() error Stop() AddPlugin(plugin Plugin) Connect(id discovery.NodeID, addr *net.TCPAddr) Peers() []*PeerInfo PeersCount() uint NodeInfo() *NodeInfo Available() bool Nodes() (urls []string) SubNodes(ch chan<- *discovery.Node) UnSubNodes(ch chan<- *discovery.Node) URL() string Config() *Config Block(id discovery.NodeID, ip net.IP, err error) }
Click to show internal directories.
Click to hide internal directories.