peer

package
v0.0.0-...-d9e9b57 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SendRequest     = 1
	ServerPing      = 2 // ping to the seed
	ServerPong      = 3 // pong to the ping
	SyncBackupSeeds = 4 // query for the backup seeds
	BackupSeeds     = 5 // return the backup seeds
	RequestReceived = 6 // ack
)

Variables

This section is empty.

Functions

func WriteConnRequest

func WriteConnRequest(conn net.Conn, r Request) error

WriteConnRequest write request data to conn

Types

type MessageHandle

type MessageHandle interface {

	// OnGetAddr is invoked when a peer receives a getaddr message.
	OnGetAddr(msg *protocol.MsgGetAddr)

	// OnAddr is invoked when a peer receives an addr message.
	OnAddr(msg *protocol.MsgAddr)

	// OnInv is invoked when a peer receives an inv message.
	OnInv(msg *protocol.MsgInv)

	// OnVersion is invoked when a peer receives an ver message
	OnVersion(msg *protocol.MsgVersion)

	// OnGetBlocks is invoked when a peer receives an getblocks message
	OnGetBlocks(msg *protocol.MsgGetBlocks)

	// OnGetData is invoked when a peer receives an getdata message
	OnGetData(msg *protocol.MsgGetData)

	// OnBlock is invoked when a peer receives an block message
	OnBlock(msg *protocol.MsgBlock)

	// OnTx is invoked when a peer receives an tx message
	OnTx(msg *protocol.MsgTx)
}

type Node

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

Node is the local server

func NewNode

func NewNode(laddr, saddr string, boardcast chan *RequestInfo, recv chan *Request, single chan *RequestInfo) *Node

NewNode return new &node with laddr, saddr, send, recv

type Packet

type Packet struct {
	Addr string
	// contains filtered or unexported fields
}

type Peer

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

Peer extends the node to maintain state shared by the server

func NewPeer

func NewPeer(listenAddr, seedAddr string, msgHandler MessageHandle) *Peer

func (*Peer) BroadcastMessage

func (p *Peer) BroadcastMessage(msg protocol.Message)

BroadcastMessage send message to all downstream nodes and seed node

func (*Peer) GetListenAddr

func (p *Peer) GetListenAddr() string

GetListenAddr get peer listen addr

func (*Peer) GetSeedAddr

func (p *Peer) GetSeedAddr() string

func (*Peer) PushAddrMsg

func (p *Peer) PushAddrMsg(msg *protocol.MsgAddr) error

func (*Peer) PushBlock

func (p *Peer) PushBlock(msg *protocol.MsgBlock) error

func (*Peer) PushGetBlocks

func (p *Peer) PushGetBlocks(msg *protocol.MsgGetBlocks) error

func (*Peer) PushTx

func (p *Peer) PushTx(msg *protocol.MsgTx) error

func (*Peer) PushVersion

func (p *Peer) PushVersion(msg *protocol.MsgVersion) error

func (*Peer) ReciveMessage

func (p *Peer) ReciveMessage()

ReciveMessage recive message from net node

func (*Peer) SendRouteMessage

func (p *Peer) SendRouteMessage(msg protocol.Message)

RouteMessage send message to all downstream nodes and seed node without source node

func (*Peer) SendSingleMessage

func (p *Peer) SendSingleMessage(msg protocol.Message)

BroadcastMessage send message to all downstream nodes and seed node

func (*Peer) StartListen

func (p *Peer) StartListen() error

type Request

type Request struct {
	ID      int64
	Command int
	From    string
	Data    interface{}
}

Request 节点之间交换的数据结构

func ReadConnRequest

func ReadConnRequest(conn net.Conn) (*Request, error)

ReadConnRequest read request data from conn

type RequestInfo

type RequestInfo struct {
	Data     interface{}
	FromAddr string
}

type Seed

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

Seed structure

Jump to

Keyboard shortcuts

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