protocol

package
v0.0.0-...-737687b Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusThanksABunch = iota
	StatusBusy
	StatusAreYouKidding
	StatusGaveup
)

enumeration used in status messages

View Source
const (
	HashSHA1 = iota
)

which hashes a hasher node offers

Variables

View Source
var (
	Messages = []interface{}{
		&Skills{},
		&Status{},
		&Request{},
		&Result{},
	}

	Spec = &protocols.Spec{
		Name:       protoName,
		Version:    protoVersion,
		MaxMsgSize: protoMax,
		Messages:   Messages,
	}
)

Functions

This section is empty.

Types

type DemoPeer

type DemoPeer struct {
	*protocols.Peer
	// contains filtered or unexported fields
}

Every protocol that wants to send messages back to sender, must have a peer abstraction this is because devp2p doesn't let us know about which peer is the sender

func (*DemoPeer) Handle

func (self *DemoPeer) Handle(ctx context.Context, msg interface{}) error

Dispatcher for incoming messages

type DemoProtocol

type DemoProtocol struct {
	Protocol       p2p.Protocol
	SkillsHandler  func(*Skills, *protocols.Peer) error
	StatusHandler  func(*Status, *protocols.Peer) error
	RequestHandler func(*Request, *protocols.Peer) error
	ResultHandler  func(*Result, *protocols.Peer) error
	// contains filtered or unexported fields
}

The protocol object wraps the code that starts a protocol on a peer upon connection

This implementation holds a callback function thats called upon a successful connection Any logic needed to be performed in the context of the protocol's service should be put there

func NewDemoProtocol

func NewDemoProtocol(runHook func(*protocols.Peer) error) (*DemoProtocol, error)

func (*DemoProtocol) Init

func (self *DemoProtocol) Init() error

TODO: double-check if we need the Init detached

func (*DemoProtocol) Run

func (self *DemoProtocol) Run(p *p2p.Peer, rw p2p.MsgReadWriter) error

This method is run on every new peer connection

It enters a loop that takes care of dispatching and receiving messages

type ID

type ID [8]byte

type Request

type Request struct {
	Id         ID
	Data       []byte
	Difficulty uint8
}

Request is a protocol message type

It is used by nodes to request a hashing job

type Result

type Result struct {
	Id    ID
	Nonce []byte
	Hash  []byte
}

Result is a protocol message type

It is used by nodes to transmit the results of a hashing job

type Skills

type Skills struct {
	Difficulty uint8
	MaxSize    uint16
}

Skills is a protocol message type

It is an asynchronous handshake message, signaling the state the node is in. The message may be issued at any time, and receiving peers should behave accordingly towards the node:

Difficulty > 0 means it's open for hashing, and what the max difficulty is.

MaxSize tells how many bytes can accompany one data submission

type Status

type Status struct {
	Id   ID
	Code uint8
}

Status is a protocol message type

It is mostly used to signal errors states.

A node also uses Status to signal successful reception of a Result message

Jump to

Keyboard shortcuts

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