p2p

package
v0.0.0-...-d2d1786 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2018 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LoggerHandler = HandlerFunc(func(msg Message) {
	data, error := json.Marshal(msg)
	if error != nil {
		fmt.Println("logger plugin err: ", error)
		return
	}

	fmt.Println("logger - message : ", string(data))
})

LoggerHandler logs the messages back and forth.

View Source
var StringLoggerHandler = HandlerFunc(func(msg Message) {
	fmt.Printf("Received message %T\n", msg.Envelope.P2PMessage)
})

StringLoggerHandler simply prints the messages as they go through the client.

Functions

func DecodeHex

func DecodeHex(hexString string) (data []byte)

Types

type Client

type Client struct {
	ChainID        eos.SHA256Bytes
	NetworkVersion uint16
	Conn           net.Conn
	NodeID         eos.SHA256Bytes
	SigningKey     *ecc.PrivateKey
	AgentName      string
	ShowEmptyChain bool

	LastHandshakeReceived *eos.HandshakeMessage
	// contains filtered or unexported fields
}

func NewClient

func NewClient(p2pAddr string, chainID string, networkVersion uint16) (*Client, error)

func (*Client) Connect

func (c *Client) Connect() (err error)

func (*Client) RegisterHandler

func (c *Client) RegisterHandler(h Handler)

func (*Client) RegisterHandlerFunc

func (c *Client) RegisterHandlerFunc(f func(Message)) Handler

func (*Client) SendHandshake

func (c *Client) SendHandshake(info *HandshakeInfo) (err error)

func (*Client) SendSyncRequest

func (c *Client) SendSyncRequest(startBlockNum uint32, endBlockNumber uint32) (err error)

func (*Client) UnregisterHandler

func (c *Client) UnregisterHandler(h Handler)

type Handler

type Handler interface {
	Handle(msg Message)
}

type HandlerFunc

type HandlerFunc func(msg Message)

func (HandlerFunc) Handle

func (f HandlerFunc) Handle(msg Message)

type HandshakeInfo

type HandshakeInfo struct {
	HeadBlockNum             uint32
	HeadBlockID              eos.SHA256Bytes
	HeadBlockTime            time.Time
	LastIrreversibleBlockNum uint32
	LastIrreversibleBlockID  eos.SHA256Bytes
}

type Message

type Message struct {
	Route    *Route                  `json:"route"`
	Envelope *eos.P2PMessageEnvelope `json:"envelope"`
}

type Proxy

type Proxy struct {
	Routes   []*Route
	Handlers []Handler
}

func (*Proxy) Start

func (p *Proxy) Start()

type Route

type Route struct {
	From string `json:"from"`
	To   string `json:"to"`
}

Jump to

Keyboard shortcuts

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