SealP2P

package module
v0.0.0-...-5028ebd Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

README

SealP2P

Documentation

Index

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 EmptyMessage() *msg.Message

func InitLocalNode

func InitLocalNode(conf conf.Config) error

func ListenMulticastUDP

func ListenMulticastUDP(network string, ifi *net.Interface, gaddr *net.UDPAddr) (conn.UDPConnect, error)

func NewJsonMessage

func NewJsonMessage(body interface{}) (*msg.Message, error)

func NewPayload

func NewPayload(path string) *msg.Message

func SendUdp

func SendUdp(address string, p *msg.Message) error

Types

type Connector

type Connector interface {
	Listener
	NodeList() (list []ConnedNode)
	GetConn(key string) (conn.Connect, bool)
	CloseAndDel(key string)
	DoConn(nodeID string, port int, ip []string) error
	On(func(req *msg.Message) *msg.Message)
}

type ConnedNode

type ConnedNode struct {
	NodeID string
	PubKey *rsa.PublicKey

	Addr string
	// contains filtered or unexported fields
}

type DefaultHandler

type DefaultHandler struct {
	// contains filtered or unexported fields
}

func NewDefaultHandler

func NewDefaultHandler() *DefaultHandler

func (*DefaultHandler) RegisterHandler

func (d *DefaultHandler) RegisterHandler(key string, f func(req *msg.Message) *msg.Message)

func (*DefaultHandler) SetMessenger

func (d *DefaultHandler) SetMessenger(m Messenger)

type Discoverer

type Discoverer interface {
	Listener
	Online(ip []string) error
	Offline() error
	SendMsg(payload *msg.Message) error
	On(func(req *msg.Message) *msg.Message)
}

type Handler

type Handler interface {
	SetMessenger(Messenger)
	RegisterHandler(string, func(req *msg.Message) *msg.Message)
	// contains filtered or unexported methods
}

type Listener

type Listener interface {
	Listen() error
	Started() bool
	Stop()
}

type Messenger

type Messenger interface {
	OnMessage(p *msg.Message) *msg.Message
}

type Multicast

type Multicast struct {
	// contains filtered or unexported fields
}

func NewMulticast

func NewMulticast(conf conf.Config) (*Multicast, error)

func (*Multicast) Listen

func (m *Multicast) Listen() error

func (*Multicast) Offline

func (m *Multicast) Offline() (err error)

func (*Multicast) On

func (m *Multicast) On(f func(req *msg.Message) *msg.Message)

func (*Multicast) Online

func (m *Multicast) Online(ip []string) (err error)

func (*Multicast) SendMsg

func (m *Multicast) SendMsg(p *msg.Message) (err error)

func (*Multicast) Started

func (m *Multicast) Started() bool

func (*Multicast) Stop

func (m *Multicast) Stop()

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)
}

func LocalNode

func LocalNode() NetNode

type Network

type Network struct {
	Discoverer
	Connector
}

func NewNetwork

func NewNetwork(conf conf.Config, h Handler) (*Network, error)

type Node

type Node struct {
	// contains filtered or unexported fields
}

func (*Node) BroadcastMsg

func (n *Node) BroadcastMsg(data *msg.Message) error

func (*Node) GetNodeID

func (n *Node) GetNodeID() string

func (*Node) GetNodeList

func (n *Node) GetNodeList() (list []NodeInfo)

func (*Node) GetNodeStatus

func (n *Node) GetNodeStatus() NodeStatus

func (*Node) GetPubKey

func (n *Node) GetPubKey() []byte

func (*Node) Join

func (n *Node) Join() error

func (*Node) Leave

func (n *Node) Leave() error

func (*Node) MsgProcessorRegister

func (n *Node) MsgProcessorRegister(router string, f func(req *msg.Message) *msg.Message)

func (*Node) MulticastMsg

func (n *Node) MulticastMsg(data *msg.Message)

func (*Node) SendMsg

func (n *Node) SendMsg(data *msg.Message) error

func (*Node) SetMessenger

func (n *Node) SetMessenger(m Messenger)

type NodeInfo

type NodeInfo struct {
	ID   string    `json:"id"`
	Addr string    `json:"addr"`
	Type conn.Type `json:"type"`
}

type NodeStatus

type NodeStatus struct {
	ID  string   `json:"id"`
	IP  []string `json:"ip"`
	Dis bool     `json:"dis"`
	Ser bool     `json:"ser"`
}

type OnlineInfo

type OnlineInfo struct {
	NodeID  string
	IP      []string
	Port    int
	Version string
}

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) DoConn

func (t *TcpService) DoConn(nodeID string, port int, ip []string) error

func (*TcpService) GetConn

func (t *TcpService) GetConn(key string) (conn.Connect, bool)

func (*TcpService) Listen

func (t *TcpService) Listen() error

func (*TcpService) NodeList

func (t *TcpService) NodeList() (list []ConnedNode)

func (*TcpService) On

func (t *TcpService) On(f func(req *msg.Message) *msg.Message)

func (*TcpService) Started

func (t *TcpService) Started() bool

func (*TcpService) Stop

func (t *TcpService) Stop()

Directories

Path Synopsis
cmd
msg
tools
gio
ip

Jump to

Keyboard shortcuts

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