common

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, GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BzzDefaultNetworkId = 4242
	WSDefaultPort       = 18543
	BzzDefaultPort      = 8542
)
View Source
const (
	P2pPort       = 30100
	IPCName       = "demo.ipc"
	DatadirPrefix = ".data_"
)
View Source
const (
	FooProtocolName       = "fooping"
	FooProtocolVersion    = 42
	FooProtocolMaxMsgSize = 1024
)

Variables

View Source
var (
	// custom log, easily grep'able
	Log = log.New("demolog", "*")

	// our working directory
	BasePath string

	// out local port for p2p connections
	P2PPort int
)
View Source
var (
	FooMessages = []interface{}{
		&FooPingMsg{},
	}
	FooProtocol = protocols.Spec{
		Name:       FooProtocolName,
		Version:    FooProtocolVersion,
		MaxMsgSize: FooProtocolMaxMsgSize,
		Messages:   FooMessages,
	}
)

Functions

func NewServer

func NewServer(privkey *ecdsa.PrivateKey, name string, version string, proto p2p.Protocol, port int) *p2p.Server

create a new p2p server

func NewServiceNode

func NewServiceNode(port int, httpport int, wsport int, modules ...string) (*node.Node, error)

set up the local service node

func WaitHealthy

func WaitHealthy(ctx context.Context, minbinsize int, rpcs ...*rpc.Client) error

Types

type FooAPI

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

Specify the API in this example we don't care about who the pongs comes from, we count them all note it is a bit fragile; we don't check for closed channels

func NewFooAPI

func NewFooAPI(pingC map[enode.ID]chan struct{}, pongcount *int) *FooAPI

func (*FooAPI) Increment

func (api *FooAPI) Increment()

func (*FooAPI) Ping

func (api *FooAPI) Ping(id enode.ID) error

invoke a single ping

func (*FooAPI) PongCount

func (api *FooAPI) PongCount() (int, error)

return the amounts of pongs received

func (*FooAPI) Quit

func (api *FooAPI) Quit(id enode.ID) error

quit the ping protocol

type FooPingMsg

type FooPingMsg struct {
	Pong    bool
	Created time.Time
}

type FooService

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

the service we want to offer on the node it must implement the node.Service interface

func NewFooService

func NewFooService() *FooService

func (*FooService) APIs

func (self *FooService) APIs() []rpc.API

specify API structs that carry the methods we want to use

func (*FooService) Protocols

func (self *FooService) Protocols() []p2p.Protocol

the p2p.Protocol to run sends a ping to its peer, waits pong

func (*FooService) Start

func (self *FooService) Start(srv *p2p.Server) error

func (*FooService) Stop

func (self *FooService) Stop() error

Jump to

Keyboard shortcuts

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