dht

package
v1.69.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: BSD-3-Clause Imports: 45 Imported by: 1

Documentation

Overview

Package dht 基于libp2p实现p2p 插件

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenPrivPubkey

func GenPrivPubkey() ([]byte, []byte, error)

GenPrivPubkey return key and pubkey in bytes

func GenPubkey

func GenPubkey(key string) (string, error)

GenPubkey generate public key

func New

func New(mgr *p2p.Manager, subCfg []byte) p2p.IP2P

New new dht p2p network

func PeerIDToPubkey added in v1.65.0

func PeerIDToPubkey(id string) (string, error)

PeerIDToPubkey 提供节点ID转换为pubkey,进而通过pubkey创建chain33 地址的功能

Types

type AddrBook

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

AddrBook peer address manager

func NewAddrBook

func NewAddrBook(cfg *types.P2P) *AddrBook

NewAddrBook new addr book

func (*AddrBook) AddrsInfo

func (a *AddrBook) AddrsInfo() []peer.AddrInfo

AddrsInfo get addr infos

func (*AddrBook) GetPrivPubKey

func (a *AddrBook) GetPrivPubKey() (string, string)

GetPrivPubKey return privkey and pubkey

func (*AddrBook) GetPrivkey

func (a *AddrBook) GetPrivkey() crypto.PrivKey

GetPrivkey get private key

func (*AddrBook) Randkey added in v1.65.0

func (a *AddrBook) Randkey() crypto.PrivKey

Randkey Rand keypair

func (*AddrBook) SaveAddr

func (a *AddrBook) SaveAddr(addrinfos []peer.AddrInfo) error

SaveAddr save addr

func (*AddrBook) StoreHostID

func (a *AddrBook) StoreHostID(id peer.ID, path string)

StoreHostID store host id into file

type Discovery added in v1.65.1

type Discovery struct {
	RoutingDiscovery *rout.RoutingDiscovery
	// contains filtered or unexported fields
}

Discovery dht rout

func InitDhtDiscovery added in v1.65.1

func InitDhtDiscovery(ctx context.Context, host host.Host, peersInfo []peer.AddrInfo, chainCfg *types.Chain33Config, subCfg *p2pty.P2PSubConfig) *Discovery

InitDhtDiscovery init dht rout

func (*Discovery) Close added in v1.65.1

func (d *Discovery) Close() error

Close close the dht

func (*Discovery) CloseFindLANPeers added in v1.65.1

func (d *Discovery) CloseFindLANPeers()

CloseFindLANPeers close peers

func (*Discovery) FindLANPeers added in v1.65.1

func (d *Discovery) FindLANPeers(host host.Host, serviceTag string) (<-chan peer.AddrInfo, error)

FindLANPeers 查找局域网内的其他节点

func (*Discovery) FindLocalPeer added in v1.65.1

func (d *Discovery) FindLocalPeer(pid peer.ID) peer.AddrInfo

FindLocalPeer 根据pid 查找当前DHT内部的peer信息

func (*Discovery) FindLocalPeers added in v1.65.1

func (d *Discovery) FindLocalPeers(pids []peer.ID) []peer.AddrInfo

FindLocalPeers find local peers

func (*Discovery) FindNearestPeers added in v1.65.1

func (d *Discovery) FindNearestPeers(pid peer.ID, count int) []peer.ID

FindNearestPeers find nearest peers

func (*Discovery) FindSpecialPeer added in v1.65.1

func (d *Discovery) FindSpecialPeer(pid peer.ID) (*peer.AddrInfo, error)

FindSpecialPeer 根据指定的peerID ,查找指定的peer,

func (*Discovery) ListPeers added in v1.65.1

func (d *Discovery) ListPeers() []peer.ID

ListPeers routingTable 路由表的节点信息

func (*Discovery) Remove added in v1.65.1

func (d *Discovery) Remove(pid peer.ID)

Remove remove peer

func (*Discovery) RoutingTable added in v1.65.1

func (d *Discovery) RoutingTable() *kbt.RoutingTable

RoutingTable get routing table

func (*Discovery) Start added in v1.65.1

func (d *Discovery) Start()

Start the dht

func (*Discovery) Update added in v1.65.1

func (d *Discovery) Update(pid peer.ID) error

Update update peer

type P2P

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

P2P p2p struct

func (*P2P) CloseP2P

func (p *P2P) CloseP2P()

CloseP2P close p2p

func (*P2P) StartP2P

func (p *P2P) StartP2P()

StartP2P start p2p

Directories

Path Synopsis
Package manage p2p manage
Package manage p2p manage
Package protocol p2p protocol
Package protocol p2p protocol
broadcast
Package broadcast broadcast protocol
Package broadcast broadcast protocol
Package types dht public types
Package types dht public types

Jump to

Keyboard shortcuts

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