Documentation ¶
Index ¶
- type HttpNetwork
- func (h *HttpNetwork) Broadcast(sender string, receivers []string, msg []byte)
- func (h *HttpNetwork) Close()
- func (h *HttpNetwork) GetOnDownload() signal.Signal[int]
- func (h *HttpNetwork) GetOnUpload() signal.Signal[int]
- func (h *HttpNetwork) Send(context []byte, addr string)
- func (h *HttpNetwork) Serve(endpoint string) chan []byte
- type Network
- type TcpCustomProtocolNetwork
- func (t *TcpCustomProtocolNetwork) Broadcast(sender string, receivers []string, msg []byte)
- func (t *TcpCustomProtocolNetwork) Close()
- func (t *TcpCustomProtocolNetwork) GetOnDownload() signal.Signal[int]
- func (t *TcpCustomProtocolNetwork) GetOnUpload() signal.Signal[int]
- func (t *TcpCustomProtocolNetwork) Send(content []byte, addr string)
- func (t *TcpCustomProtocolNetwork) Serve(endpoint string) chan []byte
- func (t *TcpCustomProtocolNetwork) UpdateMetric(up int, down int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HttpNetwork ¶
type HttpNetwork struct { }
func (*HttpNetwork) Broadcast ¶
func (h *HttpNetwork) Broadcast(sender string, receivers []string, msg []byte)
func (*HttpNetwork) Close ¶
func (h *HttpNetwork) Close()
func (*HttpNetwork) GetOnDownload ¶
func (h *HttpNetwork) GetOnDownload() signal.Signal[int]
func (*HttpNetwork) GetOnUpload ¶
func (h *HttpNetwork) GetOnUpload() signal.Signal[int]
func (*HttpNetwork) Send ¶
func (h *HttpNetwork) Send(context []byte, addr string)
func (*HttpNetwork) Serve ¶
func (h *HttpNetwork) Serve(endpoint string) chan []byte
type Network ¶
type Network interface { Serve(endpoint string) chan []byte Send(context []byte, addr string) Broadcast(sender string, receivers []string, msg []byte) GetOnUpload() signal.Signal[int] GetOnDownload() signal.Signal[int] Close() }
Network 实现p2p网络通信
var Tcp Network = NewTcpCustomProtocolNetwork()
type TcpCustomProtocolNetwork ¶
type TcpCustomProtocolNetwork struct { OnUpload signal.Signal[int] OnDownload signal.Signal[int] // contains filtered or unexported fields }
TcpCustomProtocolNetwork 基于 tcp 自定义的应用层协议 以 '\n' 作为消息的边界
func NewTcpCustomProtocolNetwork ¶
func NewTcpCustomProtocolNetwork() *TcpCustomProtocolNetwork
func (*TcpCustomProtocolNetwork) Broadcast ¶
func (t *TcpCustomProtocolNetwork) Broadcast(sender string, receivers []string, msg []byte)
Broadcast 广播消息
func (*TcpCustomProtocolNetwork) Close ¶
func (t *TcpCustomProtocolNetwork) Close()
Close 关闭所有连接并重置连接池
func (*TcpCustomProtocolNetwork) GetOnDownload ¶
func (t *TcpCustomProtocolNetwork) GetOnDownload() signal.Signal[int]
func (*TcpCustomProtocolNetwork) GetOnUpload ¶
func (t *TcpCustomProtocolNetwork) GetOnUpload() signal.Signal[int]
func (*TcpCustomProtocolNetwork) Send ¶
func (t *TcpCustomProtocolNetwork) Send(content []byte, addr string)
Send 发送消息
func (*TcpCustomProtocolNetwork) Serve ¶
func (t *TcpCustomProtocolNetwork) Serve(endpoint string) chan []byte
Serve 传入endpoint应当满足 IPv4地址:端口号
func (*TcpCustomProtocolNetwork) UpdateMetric ¶
func (t *TcpCustomProtocolNetwork) UpdateMetric(up int, down int)
Click to show internal directories.
Click to hide internal directories.