network

package
v0.0.0-...-8cfcfd0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BroadcastMsg

type BroadcastMsg struct {
	ModelID string                 `json:"model_id"`
	MsgType model.BroadcastMsgType `json:"msg_type"`
	Msg     []byte                 `json:"msg"`
}

type OnReceive

type OnReceive func(modelID string, msgBytes []byte, p *Peer)

OnReceive 注册接收消息回到

type Peer

type Peer struct {
	ID      string // 定义peerid  每个peerid应该是唯一的
	Address string // 地址
}

type PeerBooks

type PeerBooks struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewPeerBooks

func NewPeerBooks() *PeerBooks

func (*PeerBooks) AddPeer

func (pb *PeerBooks) AddPeer(p *Peer)

func (*PeerBooks) FindPeer

func (pb *PeerBooks) FindPeer(id string) *Peer

func (*PeerBooks) RemovePeer

func (pb *PeerBooks) RemovePeer(id string)

type SwitcherI

type SwitcherI interface {
	// 向所有的节点广播消息
	Broadcast(modelID string, msg *BroadcastMsg) error
	// 广播到指定的peer
	BroadcastToPeer(modelID string, msg *BroadcastMsg, p *Peer) error
	// 广播 除了指定的peer
	BroadcastExceptPeer(modelID string, msg *BroadcastMsg, p *Peer) error
	// 移除某个peer
	RemovePeer(p *Peer) error
	RegisterOnReceive(modelID string, callBack OnReceive) error
	Start() error
	// 返回所有存在的peers
	Peers() ([]*Peer, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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