network

package
v0.0.0-...-e899ace Latest Latest
Warning

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

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

Documentation

Overview

Package network is now deprecated, more to networkv2

Package network is now deprecated, more to networkv2

Package network is now deprecated, more to networkv2

Package network is now deprecated, more to networkv2

Package network is now deprecated, more to networkv2

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NetAddress

type NetAddress struct {
	IP   net.IP `json:"ip"`
	Port uint16 `json:"port"`
	// contains filtered or unexported fields
}

NetAddress defines information about a peer on the network including its ID, IP address, and port.

type Node

type Node struct {
	// sendChan contains sendData used for broadcast message
	SendChan chan []byte
	// StoreFunc can be invoked when receiving broadcast message from neigbors
	Receive func(message string) error
	// contains filtered or unexported fields
}

Node hold send chan and store func

func (*Node) Broadcast

func (node *Node) Broadcast(data string) bool

Broadcast message to other node

func (*Node) Init

func (node *Node) Init(_receive func(data string) error)

Init SendChan and on receive method

func (*Node) NewNetwork

func (node *Node) NewNetwork()

NewNetwork create a new p2p network server

type NodeInfo

type NodeInfo interface {
	// contains filtered or unexported methods
}

type Peer

type Peer interface {
	//service.Service
	FlushStop()

	RemoteIP() net.IP     // remote IP of the connection
	RemoteAddr() net.Addr // remote address of the connection

	IsOutbound() bool   // did we dial the peer
	IsPersistent() bool // do we redial this peer when we disconnect

	CloseConn() error // close original connection

	NodeInfo() NodeInfo // peer's info
	//Status() ConnectionStatus
	SocketAddr() *NetAddress // actual address of the socket

	Send(byte, []byte) bool
	TrySend(byte, []byte) bool

	Set(string, interface{})
	Get(string) interface{}
}

Peer defines network apis.

Jump to

Keyboard shortcuts

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