pex

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2021 License: MIT Imports: 19 Imported by: 1

README

go-libp2p-pex

Implementation of libp2p peer discovery module which uses custom Peer EXchange protocol

Install

go get github.com/Secured-Finance/go-libp2p-pex

Usage

Check out the Go Docs.

Contribute

PRs accepted.

License

This project is licensed under the MIT license, Copyright (c) 2021 Secured Finance. For more information see LICENSE.md.

Documentation

Index

Constants

View Source
const (
	PEXProtocolID = "/pex/2.0.0"

	DefaultGetPeersMaxCount = 30
)
View Source
const (
	MessageTypeGetPeers = iota
	MessageTypeAdvertise
	MessageTypePing
	MessageTypePong
)

Variables

View Source
var (
	Random = rand.New(cryptoSource{})
)

Functions

This section is empty.

Types

type DiscoveryNetworkManager

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

func NewPEXDiscoveryNetwork

func NewPEXDiscoveryNetwork(ctx context.Context, pex *PEXDiscovery) *DiscoveryNetworkManager

type Handler

type Handler func(ctx context.Context, peerID peer.ID, msg *PEXMessage) (*PEXMessage, error)

type PEXDiscovery

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

func NewPEXDiscovery

func NewPEXDiscovery(h host.Host, bootstrapNodes []ma.Multiaddr, updateInterval time.Duration) (*PEXDiscovery, error)

func (*PEXDiscovery) Advertise

func (pd *PEXDiscovery) Advertise(ctx context.Context, ns string, opts ...discovery.Option) (time.Duration, error)

func (*PEXDiscovery) FindPeers

func (pd *PEXDiscovery) FindPeers(ctx context.Context, ns string, opts ...discovery.Option) (<-chan peer.AddrInfo, error)

type PEXMessage

type PEXMessage struct {
	Type          uint8       `json:"type"`
	PeerInfo      *peerInfo   `json:"peerInfo"`
	Peers         []*peerInfo `json:"peers"`
	GetPeersCount uint        `json:"getPeersCount"`
	NetworkID     string      `json:"networkID"`
}

type StreamWrapper

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

func (*StreamWrapper) SendMessage

func (sw *StreamWrapper) SendMessage(ctx context.Context, msg *PEXMessage) error

func (*StreamWrapper) SendRequest

func (sw *StreamWrapper) SendRequest(ctx context.Context, msg *PEXMessage) (*PEXMessage, error)

Jump to

Keyboard shortcuts

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