Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateKey(addrs ma.Multiaddr, pid peer.ID) (string, error)
- func ReadBytes(reader io.Reader, n uint32) ([]byte, error)
- func Write(writer io.Writer, data []byte) error
- type Config
- type Neblet
- type NetService
- func (ns *NetService) Addrs() ma.Multiaddr
- func (ns *NetService) Broadcast(name string, msg net.Serializable)
- func (ns *NetService) Bye(pid peer.ID, addrs []ma.Multiaddr, s libnet.Stream, key string)
- func (ns *NetService) Deregister(subscribers ...*net.Subscriber)
- func (ns *NetService) Hello(pid peer.ID) error
- func (ns *NetService) Node() *Node
- func (ns *NetService) PutMessage(msg net.Message)
- func (ns *NetService) Register(subscribers ...*net.Subscriber)
- func (ns *NetService) Relay(name string, msg net.Serializable)
- func (netService *NetService) SayHello(bootNode multiaddr.Multiaddr) error
- func (ns *NetService) SendMsg(msgName string, msg []byte, key string)
- func (ns *NetService) SendSyncReply(key string, blocks net.Serializable)
- func (ns *NetService) Start() error
- func (ns *NetService) Stop()
- func (ns *NetService) Sync(tail net.Serializable) error
- func (ns *NetService) SyncRoutes(pid peer.ID)
- type Node
- type Protocol
- type StreamStore
Constants ¶
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
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
const (
LimitToSync = 1
)
const
Variables ¶
var (
ErrNodeNotEnough = errors.New("node is not enough")
)
errors
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 ¶
GenerateKey generate a key
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
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) Deregister ¶
func (ns *NetService) Deregister(subscribers ...*net.Subscriber)
Deregister Deregister the subscribers.
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) 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 (*Node) GetSynchronized ¶
GetSynchronized return node synchronized status
func (*Node) SetSynchronized ¶
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