p2p

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2017 License: LGPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultBucketsize            = 16
	DefaultLatency               = 10
	DefaultIP                    = "127.0.0.1"
	DefaultPort                  = 9999
	DefaultRandseed              = 12345
	DefaultMaxSyncNodes          = 16
	DefaultChainID               = 1
	DefaultVersion               = 0
	DefaultRelayCacheSize        = 65536
	DefaultStreamStoreSize       = 128
	DefaultStreamStoreExtendSize = 32
)

const

View Source
const (
	ProtocolID     = "/neb/1.0.0"
	SNC            = -1
	SHandshaking   = 0
	SOK            = 1
	HELLO          = "hello"
	OK             = "ok"
	BYE            = "bye"
	SyncRoute      = "syncroute"
	SyncRouteReply = "resyncroute"
	NewHashMsg     = "newhashmsg"
	ClientVersion  = "0.2.0"
)

connection state

View Source
const (
	LimitToSync = 1
)

const

Variables

View Source
var (
	ErrNodeNotEnough = errors.New("node is not enough")
)

errors

View Source
var MagicNumber = []byte{0x4e, 0x45, 0x42, 0x31}

MagicNumber the protocol magic number, A constant numerical or text value used to identify protocol.

Functions

func GenerateKey

func GenerateKey(addrs ma.Multiaddr, pid peer.ID) (string, error)

GenerateKey generate a key

func ReadBytes

func ReadBytes(reader io.Reader, n uint32) ([]byte, error)

ReadBytes read bytes from a stream

func Write

func Write(writer io.Writer, data []byte) error

Write write bytes to stream

Types

type Config

type Config struct {
	BootNodes []multiaddr.Multiaddr
	IP        string
	Port      uint
	Randseed  int64

	ChainID               uint32
	Version               uint8
	RelayCacheSize        int
	StreamStoreSize       int
	StreamStoreExtendSize int
	// contains filtered or unexported fields
}

Config TODO: move to proto config.

func DefautConfig

func DefautConfig() *Config

DefautConfig defautConfig is the p2p network defaut config

func NewP2PConfig

func NewP2PConfig(n Neblet) *Config

NewP2PConfig new p2p network config

type Neblet

type Neblet interface {
	Config() nebletpb.Config
}

Neblet interface breaks cycle import dependency.

type NetService

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

NetService service for nebulas p2p network

func NewNetService

func NewNetService(n Neblet) (*NetService, error)

NewNetService create netService

func (*NetService) Addrs

func (ns *NetService) Addrs() ma.Multiaddr

Addrs return peer address in string

func (*NetService) Broadcast

func (ns *NetService) Broadcast(name string, msg net.Serializable)

Broadcast broadcast message

func (*NetService) Bye

func (ns *NetService) Bye(pid peer.ID, addrs []ma.Multiaddr, s libnet.Stream, key string)

Bye say bye to a peer, and close connection.

func (*NetService) Deregister

func (ns *NetService) Deregister(subscribers ...*net.Subscriber)

Deregister Deregister the subscribers.

func (*NetService) Hello

func (ns *NetService) Hello(pid peer.ID) error

Hello say hello to a peer

func (*NetService) Node

func (ns *NetService) Node() *Node

Node return the peer node

func (*NetService) PutMessage

func (ns *NetService) PutMessage(msg net.Message)

PutMessage put message to dispatcher.

func (*NetService) Register

func (ns *NetService) Register(subscribers ...*net.Subscriber)

Register register the subscribers.

func (*NetService) Relay

func (ns *NetService) Relay(name string, msg net.Serializable)

Relay relay message

func (*NetService) SayHello

func (netService *NetService) SayHello(bootNode multiaddr.Multiaddr) error

SayHello Say hello to trustedNode

func (*NetService) SendMsg

func (ns *NetService) SendMsg(msgName string, msg []byte, key string)

SendMsg send message to a peer

func (*NetService) SendSyncReply

func (ns *NetService) SendSyncReply(key string, blocks net.Serializable)

SendSyncReply send sync reply message to remote peer

func (*NetService) Start

func (ns *NetService) Start() error

Start start p2p manager.

func (*NetService) Stop

func (ns *NetService) Stop()

Stop stop p2p manager.

func (*NetService) Sync

func (ns *NetService) Sync(tail net.Serializable) error

Sync do something ready to sync

func (*NetService) SyncRoutes

func (ns *NetService) SyncRoutes(pid peer.ID)

SyncRoutes sync routing table from a peer

type Node

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

Node the node can be used as both the client and the server

func NewNode

func NewNode(config *Config) (*Node, error)

NewNode start a local node and join the node to network

func (*Node) Config

func (node *Node) Config() *Config

Config return node config

func (*Node) GetSynchronized

func (node *Node) GetSynchronized() bool

GetSynchronized return node synchronized status

func (*Node) ID

func (node *Node) ID() peer.ID

ID return node config

func (*Node) SetSynchronized

func (node *Node) SetSynchronized(synchronized bool)

SetSynchronized set node synchronized

type Protocol

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

Protocol In Nebulas, we define our own wire protocol, as the following:

0               1               2               3              (bytes)
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Magic Number | +---------------------------------------------------------------+ | Chain ID | +-----------------------------------------------+---------------+ | Reserved | Version | +-----------------------------------------------+---------------+ | | + + | Message Name | + + | | +---------------------------------------------------------------+ | Data Length | +---------------------------------------------------------------+ | Data Checksum | +---------------------------------------------------------------+ | Header Checksum | |---------------------------------------------------------------+ | | + Data + . . | | +---------------------------------------------------------------+

type StreamStore

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

StreamStore is for stream cache

func NewStreamStore

func NewStreamStore(key string, conn int, stream libnet.Stream) *StreamStore

NewStreamStore return a new streamStore

Jump to

Keyboard shortcuts

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