p2p

package
v0.0.0-...-f5f0bdb Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2019 License: GPL-3.0 Imports: 35 Imported by: 0

README

Enums

Go does not natively support enums. However, through the following design pattern, enums can be used.

package foo

type enum int

const (
  // Foo1 ...
  Foo1 enum = iota
  // Foo2 ...
  Foo2 enum
)

// Enum is the exported enum that can be required by outside packages
type Enum interface {
  Type() enum
  String() string
}

// Type returns the enum
func (f enum) Type() enum {
  return f
}

// NOTE: the String() method is made with the 'stringer' command
package bar

// RequiresFoo requires a Foo enum.
//
// In this way, only Foo1 or Foo2 can be passed to 'RequiresFoo'
func RequiresFoo(f foo.Enum) error {
  // do something with f...

  return nil
}

Stringer

Each enum in this package includes a String() method. Rather then implement these methods by hand for each enum, the code is auto generated using golang.org/x/tools/cmd/stringer. Run $ make check to see if you have stringer installed and $ make install/stringer if the previous check errors.

After following the above steps, run $ make to autogenerate the stringer methods.

Documentation

Index

Constants

View Source
const (
	// Version is the semvar version of the build.
	Version string = "0.0.0"
)

Variables

View Source
var (
	// ErrNoPeersService ...
	ErrNoPeersService = errors.New("the p2p service has no peers service")
	// ErrUninitializedService ...
	ErrUninitializedService = errors.New("the p2p service has not been initialized")
	// ErrNoConfig ...
	ErrNoConfig = errors.New("a config is required")
	// ErrNoChainService ...
	ErrNoChainService = errors.New("a chain service is required")
	// ErrNoHost ...
	ErrNoHost = errors.New("the p2p service has no host")
	// ErrNoPublicKey ...
	ErrNoPublicKey = errors.New("the p2p service has no public key associated with it")
)
View Source
var DefaultAddress = fmt.Sprintf("/ip4/0.0.0.0/tcp/%v", DefaultPort)

DefaultAddress ...

View Source
var DefaultClientID = "golkadot/0.0.0"

DefaultClientID ...

View Source
var DefaultMaxPeers uint = 25

DefaultMaxPeers ...

View Source
var DefaultMaxQueuedBlocks = DefaultMaxRequestBlocks * 8

DefaultMaxQueuedBlocks ...

View Source
var DefaultMaxRequestBlocks uint = 64

DefaultMaxRequestBlocks ...

View Source
var DefaultMinIdleBlocks = 16

DefaultMinIdleBlocks ...

View Source
var DefaultPort uint = 30333

DefaultPort ...

View Source
var DefaultProtocolBase = "/substrate"

DefaultProtocolBase ... TODO: change...

DefaultProtocolDot ...

View Source
var DefaultProtocolPing = "/ipfs/ping/1.0.0"

DefaultProtocolPing ...

View Source
var DefaultProtocolType = "/sup"

DefaultProtocolType ...

View Source
var DefaultProtocolVersion = 1

DefaultProtocolVersion ...

View Source
var DefaultRole = "full"

DefaultRole ...

Functions

This section is empty.

Types

type P2P

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

P2P implements the p2p interface

func NewP2P

func NewP2P(ctx context.Context, cancel context.CancelFunc, ch chan interface{}, cfg *clienttypes.ConfigClient, c clienttypes.InterfaceChains) (*P2P, error)

NewP2P builds a new p2p service

func (*P2P) Config

func (p *P2P) Config() clienttypes.ConfigClient

Config returns the config

func (*P2P) GetNumPeers

func (p *P2P) GetNumPeers() (uint, error)

GetNumPeers ...

func (*P2P) GetSyncer

func (p *P2P) GetSyncer() (clienttypes.InterfaceSync, error)

GetSyncer ...

func (*P2P) IsStarted

func (p *P2P) IsStarted() bool

IsStarted ...

func (*P2P) On

func (p *P2P) On(event p2ptypes.EventEnum, cb clienttypes.EventCallback)

On handles messages

func (*P2P) Start

func (p *P2P) Start() error

Start starts the p2p service

func (*P2P) Stop

func (p *P2P) Stop() error

Stop stops the p2p service

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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