dht

package
v1.1.21 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2021 License: BSD-3-Clause Imports: 42 Imported by: 0

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

func PeerIDToPubkey(id string) (string, error)

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

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

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

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

Discovery dht discovery

func InitDhtDiscovery

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

InitDhtDiscovery init dht discovery

func (*Discovery) Close

func (d *Discovery) Close() error

Close close the dht

func (*Discovery) CloseFindLANPeers

func (d *Discovery) CloseFindLANPeers()

CloseFindLANPeers close peers

func (*Discovery) FindLANPeers

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

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

func (*Discovery) FindLocalPeer

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

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

func (*Discovery) FindLocalPeers

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

FindLocalPeers find local peers

func (*Discovery) FindNearestPeers

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

FindNearestPeers find nearest peers

func (*Discovery) FindPeersConnectedToPeer

func (d *Discovery) FindPeersConnectedToPeer(pid peer.ID) (<-chan *peer.AddrInfo, error)

FindPeersConnectedToPeer 获取连接指定的peerId的peers信息,查找连接PID=A的所有节点

func (*Discovery) FindSpecialPeer

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

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

func (*Discovery) ListPeers

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

ListPeers routingTable 路由表的节点信息

func (*Discovery) Remove

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

Remove remove peer

func (*Discovery) RoutingTable

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

RoutingTable get routing table

func (*Discovery) Start

func (d *Discovery) Start()

Start the dht

func (*Discovery) Update

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