p2p

package
v0.0.0-...-f163260 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2022 License: MIT Imports: 57 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultDialRatio = 0.2

	DefaultLibp2pPort int = 1478

	MinimumPeerConnections int64 = 1

	MinimumBootNodes int = 1

	// Priority for dial queue
	PriorityRequestedDial uint64 = 1

	PriorityRandomDial uint64 = 10
)
View Source
const ConsensusProtocolPrefiix = "/quantos/consensus/1.0.0"
View Source
const DNSRegex = `^/?(dns)(4|6)?/[^-|^/][A-Za-z0-9-]([^-|^/]?)+([\\-\\.]{1}[a-z0-9]+)*\\.[A-Za-z]{2,}(/?)$`

regex string to match against a valid dns/dns4/dns6 addr

View Source
const GossipProtocolPrefix = "/quantos/karod/gossip/1.0.0"
View Source
const GossipProtocolTopic = "quantos"
View Source
const P2PRpcPrefix protocol.ID = "/quantos/p2p/rpc/1.0.0"
View Source
const QuantosLiveProtocolPrefix = "/quantos/live/1.0.0"
View Source
const QuantosTestProtocolPrefix = "/quantostestnet/test/1.0.0"

Variables

View Source
var (
	ErrInvalidChainID   = errors.New("invalid chain ID")
	ErrNotReady         = errors.New("not ready")
	ErrNoAvailableSlots = errors.New("no available Slots")
)
View Source
var (
	ErrNoBootnodes  = errors.New("no bootnodes specified")
	ErrMinBootnodes = errors.New("minimum 1 bootnode is required")
)
View Source
var (
	// Anything below 35s is prone to false timeouts, as seen from empirical test data
	DefaultJoinTimeout   = 40 * time.Second
	DefaultBufferTimeout = DefaultJoinTimeout + time.Second*5
)
View Source
var IdentityProtocolPrefix = "/id/1.0.0"
View Source
var MaxWorkers = runtime.NumCPU() - 1

Functions

func AddrInfoToString

func AddrInfoToString(addr *peer.AddrInfo) string

AddrInfoToString converts an AddrInfo into a string representation that can be dialed from another node

func CreateNewHost

func CreateNewHost() (host.Host, *dht.IpfsDHT, error)

func MultiAddrFromDNS

func MultiAddrFromDNS(addr string, port int) (multiaddr.Multiaddr, error)

MultiAddrFromDNS constructs a multiAddr from the passed in DNS address and port combination

func StartNetwork

func StartNetwork()

func StringToAddrInfo

func StringToAddrInfo(addr string) (*peer.AddrInfo, error)

Types

type Metrics

type Metrics struct {
	// No.of connected peers
	Peers metrics.Gauge
}

Metrics represents the network metrics

func GetPrometheusMetrics

func GetPrometheusMetrics(namespace string, labelsWithValues ...string) *Metrics

GetPrometheusMetrics return the network metrics instance

func NilMetrics

func NilMetrics() *Metrics

NilMetrics will return the non operational metrics

type P2PRpc

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

func (*P2PRpc) New

func (prpc *P2PRpc) New(h host.Host)

func (*P2PRpc) RegisterServices

func (prpc *P2PRpc) RegisterServices(repo *services.ServiceRepository) (err error)

type Peer

type Peer struct {
	Info peer.AddrInfo
	// contains filtered or unexported fields
}

type PeerEvent

type PeerEvent struct {
	// PeerID is the id of the peer that triggered
	// the event
	PeerID peer.ID

	// Type is the type of the event
	Type PeerEventType
}

type PeerEventType

type PeerEventType uint
const (
	PeerConnected        PeerEventType = iota // Emitted when a peer connected
	PeerFailedToConnect                       // Emitted when a peer failed to connect
	PeerDisconnected                          // Emitted when a peer disconnected from node
	PeerAlreadyConnected                      // Emitted when a peer already connected on dial
	PeerDialCompleted                         // Emitted when a peer completed dial
	PeerAddedToDialQueue                      // Emitted when a peer is added to dial queue
)

func (PeerEventType) String

func (s PeerEventType) String() string

type Protocol

type Protocol interface {
	Client(network.Stream) interface{}
	Handler() func(network.Stream)
}

type Server

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

func NewServer

func NewServer(logger hclog.Logger, config *ServerConfig) (*Server, error)

func (*Server) AddrInfo

func (s *Server) AddrInfo() *peer.AddrInfo

func (*Server) Close

func (s *Server) Close() error

func (*Server) Disconnect

func (s *Server) Disconnect(peer peer.ID, reason string)

func (*Server) GetPeerInfo

func (s *Server) GetPeerInfo(peerID peer.ID) peer.AddrInfo

func (*Server) GetProtocols

func (s *Server) GetProtocols(peerID peer.ID) ([]string, error)

func (*Server) Join

func (s *Server) Join(addr *peer.AddrInfo, timeout time.Duration) error

func (*Server) JoinAddr

func (s *Server) JoinAddr(addr string, timeout time.Duration) error

func (*Server) NewProtoStream

func (s *Server) NewProtoStream(proto string, id peer.ID) (interface{}, error)

func (*Server) NewStream

func (s *Server) NewStream(proto string, id peer.ID) (network.Stream, error)

func (*Server) NewTopic

func (s *Server) NewTopic(protoID string, obj proto.Message) (*Topic, error)

func (*Server) Peers

func (s *Server) Peers() []*Peer

func (*Server) Register

func (s *Server) Register(id string, p Protocol)

func (*Server) RunDialerWorkPool

func (s *Server) RunDialerWorkPool()

func (*Server) Subscribe

func (s *Server) Subscribe() (*Subscription, error)

Subscribe starts a PeerEvent subscription

func (*Server) SubscribeCh

func (s *Server) SubscribeCh() (<-chan *PeerEvent, error)

SubscribeCh returns an event of of subscription events

func (*Server) SubscribeFn

func (s *Server) SubscribeFn(handler func(evnt *PeerEvent)) error

SubscribeFn is a helper method to run subscription of PeerEvents

type ServerConfig

type ServerConfig struct {
	NoDiscover       bool
	Addr             *net.TCPAddr
	NatAddr          net.IP
	DNS              multiaddr.Multiaddr
	DataDir          string
	MaxPeers         int64
	MaxInboundPeers  int64
	MaxOutboundPeers int64
	Chain            sdk.BlockchainManager
	SecretsManager   sdk.KeyManager
	Metrics          *Metrics
}

func SetDefaultConfig

func SetDefaultConfig() *ServerConfig

type Store

type Store struct{}

type Subscription

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

func (*Subscription) Close

func (s *Subscription) Close()

func (*Subscription) Get

func (s *Subscription) Get() *PeerEvent

func (*Subscription) GetCh

func (s *Subscription) GetCh() chan *PeerEvent

type Topic

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

func (*Topic) Publish

func (t *Topic) Publish(obj proto.Message) error

func (*Topic) Subscribe

func (t *Topic) Subscribe(handler func(obj interface{})) error

type TopicSub

type TopicSub struct {
	Topic        *pubsub.Topic
	Subscription *pubsub.Subscription
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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