p2p

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2019 License: GPL-3.0 Imports: 22 Imported by: 2

README

P2P

Documentation

Index

Constants

View Source
const (
	MessageTypeTx          = "tx"
	MessageTypeEvent       = "ev"
	MessageTypeBlockHeader = "blkH"
	MessageTypeBlock       = "blk"
)
View Source
const (
	GVTO  = time.Second * 64 // get value timeout
	GVBS  = 256              // get value buffer size
	PVTO  = time.Second * 64 // put value timeout
	PVBS  = 256              // put value buffer size
	GCITO = time.Second * 8  // duration for get chain information
	GCIBS = 64               // get chain formation buffer size

)
View Source
const (
	ChainCfgIdx      = 0
	DhtCfgIdx        = 1
	DftEvKeepTime    = time.Minute * 1
	DftDedupTime     = time.Second * 60
	DftBootstrapTime = time.Second * 4
	DftNatType       = config.NATT_NONE
	DftGatewayIp     = "0.0.0.0"
)
View Source
const (
	DhtGetDftTimeout = 60 * time.Second
)
View Source
const GCIKEY_LEN = 32
View Source
const MaxSubNetMaskBits = 15 // max number of mask bits for sub network identity
View Source
const YeShellManagerTag = "yeShMgr"

Variables

View Source
var (
	ErrDhtNotFound                 = errors.New("dht value not found")
	ErrInsufficientOutChanCapacity = errors.New("output chan capacity insufficient")
	ErrResourceLimited             = errors.New("underlying resources limited")
	ErrDhtInternal                 = errors.New("dht internal errors")
)
View Source
var DefaultYeShellConfig = YeShellConfig{
	AppType:       config.P2P_TYPE_ALL,
	Name:          config.DefaultNodeName,
	Validator:     true,
	BootstrapNode: false,
	BootstrapNodes: []string{
		"3CEF400192372CD94AAE8DCA465A4A48D4FFBF7E7364D5044CD003F07DCBB0D4EEA7E311D9ED0852890C2B72E79893F0CBA5238A09F7B441613218C3A0D4659B@192.168.1.109:30304:30304",
	},
	DhtBootstrapNodes: []string{
		"3CEF400192372CD94AAE8DCA465A4A48D4FFBF7E7364D5044CD003F07DCBB0D4EEA7E311D9ED0852890C2B72E79893F0CBA5238A09F7B441613218C3A0D4659B@192.168.1.109:40405:40405",
	},
	LocalNodeIp:    config.P2pGetLocalIpAddr().String(),
	LocalUdpPort:   config.DftUdpPort,
	LocalTcpPort:   config.DftTcpPort,
	LocalDhtIp:     config.P2pGetLocalIpAddr().String(),
	LocalDhtPort:   config.DftDhtPort,
	NodeDataDir:    config.P2pDefaultDataDir(true),
	NodeDatabase:   config.DefaultNodeDatabase,
	SubNetMaskBits: config.DftSnmBits,
	EvKeepTime:     DftEvKeepTime,
	DedupTime:      DftDedupTime,
	BootstrapTime:  DftBootstrapTime,
	NatType:        DftNatType,
	GatewayIp:      DftGatewayIp,
	// contains filtered or unexported fields
}

Default yee shell configuration for convenience

View Source
var YeShellCfg = make(map[string]YeShellConfig, 0)

Global shell configuration: this var is set when function YeShellConfigToP2pCfg called, the p2p user should not change those fields other than "Validator" and "SubNetMaskBits" which can be reconfigurated, since YeShellConfigToP2pCfg should be called once only.

View Source
var YesErrMsg = []string{
	"yesmgr: YesEnoNone",
	"yesmgr: YesEnoInStopping",
	"yesmgr: YesEnoParameter",
	"yesmgr: YesEnoPutValFull",
	"yesmgr: YesEnoPutValDup",
	"yesmgr: YesEnoGetValFull",
	"yesmgr: YesEnoGetValDup",
	"yesmgr: YesEnoGetValDupFull",
	"yesmgr: YesEnoGcdFull",
	"yesmgr: YesEnoGcdDup",
	"yesmgr: YesEnoTimeout",
	"yesmgr: YesEnoResource",
	"yesmgr: YesEnoScheduler",
	"yesmgr: YesEnoChClosed",
	"yesmgr: YesEnoEmptyVal",
	"yesmgr: YesEnoDhtInteral",
	"yesmgr: YesEnoUnknown",
}

Functions

func GetSubnetIdentity

func GetSubnetIdentity(id config.NodeID, maskBits int) (config.SubNetworkID, error)

func OsnServiceConfig

func OsnServiceConfig(cfg *YeShellConfig, cfgFromFie interface{}) error

func SetupSubNetwork

func SetupSubNetwork(cfg *config.Config, mbs int, vdt bool) error

func Snid2Int

func Snid2Int(snid config.SubNetworkID) int

Types

type ChainProvider

type ChainProvider interface {
	GetChainData(kind string, key []byte) []byte
}

type InmemHub

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

Inmem Hub for all InmemService 模拟消息的延迟,丢失,dht检索

func GetInmemHub

func GetInmemHub() *InmemHub

func (*InmemHub) AddNode

func (ih *InmemHub) AddNode(node *InmemService)

func (*InmemHub) Broadcast

func (ih *InmemHub) Broadcast(from *InmemService, message Message) error

func (*InmemHub) GetValue

func (ih *InmemHub) GetValue(key []byte) ([]byte, error)

func (*InmemHub) RemoveNode

func (ih *InmemHub) RemoveNode(node *InmemService)

func (*InmemHub) SetValue

func (ih *InmemHub) SetValue(key []byte, value []byte) error

type InmemService

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

func NewInmemService

func NewInmemService() (*InmemService, error)

func (*InmemService) BroadcastMessage

func (is *InmemService) BroadcastMessage(message Message) error

func (*InmemService) BroadcastMessageOsn

func (is *InmemService) BroadcastMessageOsn(message Message) error

func (*InmemService) DhtGetValue

func (is *InmemService) DhtGetValue(key []byte) ([]byte, error)

func (*InmemService) DhtGetValues

func (is *InmemService) DhtGetValues(keys [][]byte, out chan<- []byte, timeout time.Duration) error

func (*InmemService) DhtSetValue

func (is *InmemService) DhtSetValue(key []byte, value []byte) error

func (*InmemService) GetChainInfo

func (is *InmemService) GetChainInfo(kind string, key []byte) ([]byte, error)

func (*InmemService) Ready

func (is *InmemService) Ready()

func (*InmemService) Reconfig

func (is *InmemService) Reconfig(reCfg *RecfgCommand) error

func (*InmemService) RegChainProvider

func (is *InmemService) RegChainProvider(cp ChainProvider)

func (*InmemService) Register

func (is *InmemService) Register(subscriber *Subscriber)

func (*InmemService) Start

func (is *InmemService) Start() error

func (*InmemService) Stop

func (is *InmemService) Stop()

func (*InmemService) UnRegister

func (is *InmemService) UnRegister(subscriber *Subscriber)

type Message

type Message struct {
	MsgType string
	From    string
	Key     []byte
	Data    []byte
}

type OsnService

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

func NewOsnService

func NewOsnService(cfg *YeShellConfig) (*OsnService, error)

func NewOsnServiceWithCfg

func NewOsnServiceWithCfg(cfg *yeeCfg.Config) (*OsnService, error)

func (*OsnService) BroadcastMessage

func (osns *OsnService) BroadcastMessage(message Message) error

func (*OsnService) BroadcastMessageOsn

func (osns *OsnService) BroadcastMessageOsn(message Message) error

func (*OsnService) DhtGetValue

func (osns *OsnService) DhtGetValue(key []byte) ([]byte, error)

func (*OsnService) DhtGetValues

func (osns *OsnService) DhtGetValues(keys [][]byte, out chan<- []byte, timeout time.Duration) error

func (*OsnService) DhtSetValue

func (osns *OsnService) DhtSetValue(key []byte, value []byte) error

func (*OsnService) GetChainInfo

func (osns *OsnService) GetChainInfo(kind string, key []byte) ([]byte, error)

func (*OsnService) GetLocalDhtNode

func (osns *OsnService) GetLocalDhtNode() *config.Node

func (*OsnService) GetLocalNode

func (osns *OsnService) GetLocalNode() *config.Node

func (*OsnService) Ready

func (osns *OsnService) Ready()

func (*OsnService) Reconfig

func (osns *OsnService) Reconfig(reCfg *RecfgCommand) error

func (*OsnService) RegChainProvider

func (osns *OsnService) RegChainProvider(cp ChainProvider)

func (*OsnService) Register

func (osns *OsnService) Register(subscriber *Subscriber)

func (*OsnService) Start

func (osns *OsnService) Start() error

func (*OsnService) Stop

func (osns *OsnService) Stop()

func (*OsnService) UnRegister

func (osns *OsnService) UnRegister(subscriber *Subscriber)

type RecfgCommand

type RecfgCommand struct {
	Validator      bool // is validator
	SubnetMaskBits int  // mask bits for sub network identity
}

type Service

type Service interface {
	Start() error
	Stop()
	Ready()

	Reconfig(reCfg *RecfgCommand) error
	BroadcastMessage(message Message) error
	//如果在多个子网,随机选一个。如果单一子网,直接发布。
	BroadcastMessageOsn(message Message) error
	Register(subscriber *Subscriber)
	UnRegister(subscriber *Subscriber)

	DhtGetValue(key []byte) ([]byte, error)
	DhtGetValues(keys [][]byte, out chan<- []byte, timeout time.Duration) error
	DhtSetValue(key []byte, value []byte) error

	// p2p service get chain data from provider
	RegChainProvider(cp ChainProvider)

	// ask peer for chain info
	GetChainInfo(kind string, key []byte) ([]byte, error)
}

type SingleSubnetDescriptor

type SingleSubnetDescriptor = sch.SingleSubnetDescriptor // single subnet descriptor

type SubnetDescriptor

type SubnetDescriptor struct {
	SubNetKeyList      map[config.SubNetworkID]ecdsa.PrivateKey // keys for sub-node
	SubNetNodeList     map[config.SubNetworkID]config.Node      // sub-node identities
	SubNetMaxPeers     map[config.SubNetworkID]int              // max peers would be
	SubNetMaxOutbounds map[config.SubNetworkID]int              // max concurrency outbounds
	SubNetMaxInBounds  map[config.SubNetworkID]int              // max concurrency inbounds
	SubNetIdList       []config.SubNetworkID                    // sub network identity list
}

func (*SubnetDescriptor) GetSubnetDescriptorList

func (snd *SubnetDescriptor) GetSubnetDescriptorList() *[]SingleSubnetDescriptor

func (*SubnetDescriptor) Setup

func (snd *SubnetDescriptor) Setup(node *config.Node, priKey *ecdsa.PrivateKey, mbs int, vdt bool) error

type Subscriber

type Subscriber struct {
	ID      interface{}
	MsgChan chan Message
	MsgType string
}

func NewSubscriber

func NewSubscriber(id interface{}, msgChan chan Message, msgType string) *Subscriber

type Transport

type Transport interface {
}

写一个内存测试版 一个tcp版,直接连接 一个全网广播版 一个dht版,匿名连接, tor或者garlic routing

type YeShellConfig

type YeShellConfig struct {
	// Notice: in current stage, a simple configuration for p2p is applied, for total configuration
	// about p2p, see config.Config please.
	AppType           config.P2pAppType // application type
	Name              string            // node name, should be unique
	ChainId           uint32            // chain identity
	Validator         bool              // validator flag
	BootstrapNode     bool              // bootstrap node flag
	BootstrapNodes    []string          // bootstrap nodes
	DhtBootstrapNodes []string          // bootstrap nodes for dht
	LocalNodeIp       string            // local node ip for chain-peers
	LocalUdpPort      uint16            // local node udp port
	LocalTcpPort      uint16            // local node tcp port
	LocalDhtIp        string            // local dht ip
	LocalDhtPort      uint16            // local dht port
	NodeDataDir       string            // node data directory
	NodeDatabase      string            // node database
	SubNetMaskBits    int               // mask bits for sub network identity
	EvKeepTime        time.Duration     // duration for events kept by dht
	DedupTime         time.Duration     // duration for deduplication cleanup timer
	BootstrapTime     time.Duration     // duration for bootstrap blind connection
	NatType           string            // nat type, "none"/"pmp"/"upnp"
	GatewayIp         string            // gateway ip when nat type is "pmp"
	// contains filtered or unexported fields
}

func YeShellConfigToP2pCfg

func YeShellConfigToP2pCfg(yesCfg *YeShellConfig) ([]*config.Config, *YeShellConfig)

type YeShellManager

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

func NewYeShellManager

func NewYeShellManager(yesCfg *YeShellConfig) *YeShellManager

func (*YeShellManager) BroadcastMessage

func (yeShMgr *YeShellManager) BroadcastMessage(message Message) error

func (*YeShellManager) BroadcastMessageOsn

func (yeShMgr *YeShellManager) BroadcastMessageOsn(message Message) error

func (*YeShellManager) DhtFindNode

func (yeShMgr *YeShellManager) DhtFindNode(target *config.NodeID, done chan interface{}) error

func (*YeShellManager) DhtGetProvider

func (yeShMgr *YeShellManager) DhtGetProvider(key []byte, done chan interface{}) error

func (*YeShellManager) DhtGetValue

func (yeShMgr *YeShellManager) DhtGetValue(key []byte) ([]byte, error)

func (*YeShellManager) DhtGetValues

func (yeShMgr *YeShellManager) DhtGetValues(keys [][]byte, out chan<- []byte, timeout time.Duration) error

func (*YeShellManager) DhtSetProvider

func (yeShMgr *YeShellManager) DhtSetProvider(key []byte, provider *config.Node, done chan interface{}) error

func (*YeShellManager) DhtSetValue

func (yeShMgr *YeShellManager) DhtSetValue(key []byte, value []byte) error

func (*YeShellManager) GetChainInfo

func (yeShMgr *YeShellManager) GetChainInfo(kind string, key []byte) ([]byte, error)

func (*YeShellManager) GetLocalDhtNode

func (yeShMgr *YeShellManager) GetLocalDhtNode() *config.Node

func (*YeShellManager) GetLocalNode

func (yeShMgr *YeShellManager) GetLocalNode() *config.Node

func (*YeShellManager) GetLocalPrivateKey

func (yeShMgr *YeShellManager) GetLocalPrivateKey() *ecdsa.PrivateKey

func (*YeShellManager) Ready

func (yeShMgr *YeShellManager) Ready()

func (*YeShellManager) Reconfig

func (yeShMgr *YeShellManager) Reconfig(reCfg *RecfgCommand) error

func (*YeShellManager) RegChainProvider

func (yeShMgr *YeShellManager) RegChainProvider(cp ChainProvider)

func (*YeShellManager) Register

func (yeShMgr *YeShellManager) Register(subscriber *Subscriber)

func (*YeShellManager) Start

func (yeShMgr *YeShellManager) Start() error

func (*YeShellManager) Stop

func (yeShMgr *YeShellManager) Stop()

func (*YeShellManager) UnRegister

func (yeShMgr *YeShellManager) UnRegister(subscriber *Subscriber)

type YesErrno

type YesErrno int
const (
	YesEnoNone YesErrno = iota
	YesEnoInStopping
	YesEnoParameter
	YesEnoPutValFull
	YesEnoPutValDup
	YesEnoGetValFull
	YesEnoGetValDup
	YesEnoGetValDupFull
	YesEnoGcdFull
	YesEnoGcdDup
	YesEnoTimeout
	YesEnoResource
	YesEnoScheduler
	YesEnoChClosed
	YesEnoEmptyVal
	YesEnoDhtInteral
	YesEnoUnknown
)

func (YesErrno) Error

func (eno YesErrno) Error() string

Directories

Path Synopsis
dht
pb
udpmsg/pb
Package udpmsg_pb is a generated protocol buffer package.
Package udpmsg_pb is a generated protocol buffer package.
Notice: the test cases can work only those _TEST_ in peer manager and dht manager are set to "true", check them please.
Notice: the test cases can work only those _TEST_ in peer manager and dht manager are set to "true", check them please.
pb

Jump to

Keyboard shortcuts

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