Documentation ¶
Index ¶
- Variables
- func EmptyMessage() *msg.Message
- func InitLocalNode(conf conf.Config) error
- func ListenMulticastUDP(network string, ifi *net.Interface, gaddr *net.UDPAddr) (conn.UDPConnect, error)
- func NewJsonMessage(body interface{}) (*msg.Message, error)
- func NewPayload(path string) *msg.Message
- func SendUdp(address string, p *msg.Message) error
- type Connector
- type ConnedNode
- type DefaultHandler
- type Discoverer
- type Handler
- type Listener
- type Messenger
- type Multicast
- func (m *Multicast) Listen() error
- func (m *Multicast) Offline() (err error)
- func (m *Multicast) On(f func(req *msg.Message) *msg.Message)
- func (m *Multicast) Online(ip []string) (err error)
- func (m *Multicast) SendMsg(p *msg.Message) (err error)
- func (m *Multicast) Started() bool
- func (m *Multicast) Stop()
- type NetNode
- type Network
- type Node
- func (n *Node) BroadcastMsg(data *msg.Message) error
- func (n *Node) GetNodeID() string
- func (n *Node) GetNodeList() (list []NodeInfo)
- func (n *Node) GetNodeStatus() NodeStatus
- func (n *Node) GetPubKey() []byte
- func (n *Node) Join() error
- func (n *Node) Leave() error
- func (n *Node) MsgProcessorRegister(router string, f func(req *msg.Message) *msg.Message)
- func (n *Node) MulticastMsg(data *msg.Message)
- func (n *Node) SendMsg(data *msg.Message) error
- func (n *Node) SetMessenger(m Messenger)
- type NodeInfo
- type NodeStatus
- type OnlineInfo
- type TcpService
- func (t *TcpService) CloseAndDel(key string)
- func (t *TcpService) DialTCP(addr string) (conn.TCPConnect, error)
- func (t *TcpService) DoConn(nodeID string, port int, ip []string) error
- func (t *TcpService) GetConn(key string) (conn.Connect, bool)
- func (t *TcpService) Listen() error
- func (t *TcpService) NodeList() (list []ConnedNode)
- func (t *TcpService) On(f func(req *msg.Message) *msg.Message)
- func (t *TcpService) Started() bool
- func (t *TcpService) Stop()
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultHandleMap = map[string]func(payload *msg.Message) *msg.Message{ msg.ActionJoin: func(request *msg.Message) *msg.Message { log.Println("join:", request.FromID, request) info := OnlineInfo{} err := json.Unmarshal(request.Payload, &info) if err != nil { panic(err) } if err = localNode.network.DoConn(info.NodeID, info.Port, info.IP); err != nil { log.Println("online err", err) } return nil }, msg.ActionLeave: func(request *msg.Message) *msg.Message { log.Println("msg.ActionLeave:", request.FromID) localNode.network.CloseAndDel(request.FromID) return nil }, }
Functions ¶
func EmptyMessage ¶
func InitLocalNode ¶
func ListenMulticastUDP ¶
func NewJsonMessage ¶
func NewPayload ¶
Types ¶
type ConnedNode ¶
type DefaultHandler ¶
type DefaultHandler struct {
// contains filtered or unexported fields
}
func NewDefaultHandler ¶
func NewDefaultHandler() *DefaultHandler
func (*DefaultHandler) RegisterHandler ¶
func (*DefaultHandler) SetMessenger ¶
func (d *DefaultHandler) SetMessenger(m Messenger)
type Discoverer ¶
type NetNode ¶
type NetNode interface { SetMessenger(Messenger) GetPubKey() []byte GetNodeStatus() NodeStatus GetNodeID() string GetNodeList() []NodeInfo Join() error Leave() error SendMsg(data *msg.Message) error MulticastMsg(data *msg.Message) BroadcastMsg(data *msg.Message) error MsgProcessorRegister(string, func(req *msg.Message) *msg.Message) }
type Network ¶
type Network struct { Discoverer Connector }
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
func (*Node) GetNodeList ¶
func (*Node) GetNodeStatus ¶
func (n *Node) GetNodeStatus() NodeStatus
func (*Node) MsgProcessorRegister ¶
func (*Node) MulticastMsg ¶
func (*Node) SetMessenger ¶
type NodeStatus ¶
type TcpService ¶
type TcpService struct {
// contains filtered or unexported fields
}
func NewTcpService ¶
func NewTcpService(conf conf.Config) (*TcpService, error)
func (*TcpService) CloseAndDel ¶
func (t *TcpService) CloseAndDel(key string)
func (*TcpService) DialTCP ¶
func (t *TcpService) DialTCP(addr string) (conn.TCPConnect, error)
func (*TcpService) Listen ¶
func (t *TcpService) Listen() error
func (*TcpService) NodeList ¶
func (t *TcpService) NodeList() (list []ConnedNode)
func (*TcpService) Started ¶
func (t *TcpService) Started() bool
func (*TcpService) Stop ¶
func (t *TcpService) Stop()
Source Files ¶
Click to show internal directories.
Click to hide internal directories.