network

package
v0.0.0-...-5fa8bf8 Latest Latest
Warning

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

Go to latest
Published: May 18, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

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网络通信

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)

Jump to

Keyboard shortcuts

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