Documentation
¶
Index ¶
- Constants
- Variables
- func GetDefaultBootstrapPeerAddrInfos() []peer.AddrInfo
- func NewTable(h host.Host) (table *kbucket.RoutingTable, err error)
- func PublishLookupEvent(ctx context.Context, ev *LookupEvent)
- func RegisterForLookupEvents(ctx context.Context) (context.Context, <-chan *LookupEvent)
- type CPUInfo
- type ConnSupervisor
- type ContentRouting
- type DeP2P
- func (bp *DeP2P) ConnectPeer() []peer.AddrInfo
- func (bp *DeP2P) Context() context.Context
- func (bp *DeP2P) DHT() *DeP2PDHT
- func (bp *DeP2P) Host() host.Host
- func (bp *DeP2P) IsRunning() bool
- func (bp *DeP2P) NodeInfo() *NodeInfo
- func (bp *DeP2P) Options() Options
- func (bp *DeP2P) RoutingTable(mode int) *kbucket.RoutingTable
- func (bp *DeP2P) RoutingTables() map[int]*kbucket.RoutingTable
- func (bp *DeP2P) Start() error
- func (bp *DeP2P) Stop() error
- type DeP2PDHT
- func (dht *DeP2PDHT) Bootstrap(ctx context.Context) error
- func (dht *DeP2PDHT) Close() error
- func (dht *DeP2PDHT) Context() context.Context
- func (dht *DeP2PDHT) FindProvidersAsync(ctx context.Context, key cid.Cid, count int) <-chan peer.AddrInfo
- func (dht *DeP2PDHT) ForceRefresh() <-chan error
- func (dht *DeP2PDHT) GetClosestPeers(ctx context.Context, key string) ([]peer.ID, error)
- func (dht *DeP2PDHT) Host() host.Host
- func (dht *DeP2PDHT) Mode() ModeOpt
- func (dht *DeP2PDHT) PeerID() peer.ID
- func (dht *DeP2PDHT) PeerKey() []byte
- func (dht *DeP2PDHT) Ping(ctx context.Context, p peer.ID) error
- func (dht *DeP2PDHT) Provide(ctx context.Context, key cid.Cid, brdcst bool) (err error)
- func (dht *DeP2PDHT) RefreshRoutingTable() <-chan error
- func (dht *DeP2PDHT) RoutingTable() *kb.RoutingTable
- type DiskInfo
- type Handshake
- type KeyKadID
- type LookupEvent
- type LookupTerminateEvent
- type LookupTerminationReason
- type LookupUpdateEvent
- type MemoryInfo
- type ModeOpt
- type NetworkInfo
- type NodeInfo
- type Option
- type OptionDeP2P
- type Options
- type PeerKadID
- type QueryFilterFunc
- type RouteTableFilterFunc
- type RoutingDiscovery
Constants ¶
const ( // DefaultTryTimes 是默认的尝试次数。最大超时时间为10分钟10秒。 DefaultTryTimes = 15 // DefaultTryTimesAfterMaxTime 是最大超时时间(90天)后的默认尝试次数。 DefaultTryTimesAfterMaxTime = 6 * 24 * 90 )
const (
// HandshakeProtocol 默认 dep2p 连接握手协议
HandshakeProtocol = "/dep2p/handshake/1.0.0"
)
连接握手协议
Variables ¶
var DefaultBootstrapPeers []multiaddr.Multiaddr
DefaultBootstrapPeers 是 libp2p 提供的一组公共 DHT 引导节点。
var LookupEventBufferSize = 16
LookupEventBufferSize 是要缓冲的事件数。
Functions ¶
func GetDefaultBootstrapPeerAddrInfos ¶
GetDefaultBootstrapPeerAddrInfos 返回默认引导对等点的peer.AddrInfos,因此我们可以通过将它们传递给 BootstrapPeers(...) 选项来使用它们来初始化 DHT。
func PublishLookupEvent ¶
func PublishLookupEvent(ctx context.Context, ev *LookupEvent)
PublishLookupEvent 将查询事件发布到与给定上下文关联的查询事件通道(如果有)。
func RegisterForLookupEvents ¶
func RegisterForLookupEvents(ctx context.Context) (context.Context, <-chan *LookupEvent)
RegisterForLookupEvents 使用给定的上下文注册查找事件通道。 返回的上下文可以传递给 DHT 查询以接收返回通道上的查找事件。
当调用者不再对查询事件感兴趣时,必须取消传递的上下文。
Types ¶
type ConnSupervisor ¶
type ConnSupervisor struct {
IsConnected bool // 是否有已连接到对等节点
// contains filtered or unexported fields
}
ConnSupervisor 是一个连接监管器。
func (*ConnSupervisor) Connected ¶
func (cm *ConnSupervisor) Connected(p peer.AddrInfo) bool
Connected 如果节点已连接,则返回true;否则返回false。
func (*ConnSupervisor) ConnectedAddrInfo ¶
func (cm *ConnSupervisor) ConnectedAddrInfo() []peer.AddrInfo
ConnectedAddrInfo 返回连接到节点信息。
func (*ConnSupervisor) RemoveConn ¶
func (cm *ConnSupervisor) RemoveConn(p peer.AddrInfo)
RemoveConn 移除一个连接。
type ContentRouting ¶
type ContentRouting interface {
// Provide 将给定的 cid 添加到内容路由系统中。如果传递了 'true',
// 它还会宣布它,否则它只是保留在本地的对象提供的记账中。
Provide(context.Context, cid.Cid, bool) error
// 搜索能够提供给定键的对等方
//
// 当计数为0时,此方法将返回无限制数量的结果。
FindProvidersAsync(context.Context, cid.Cid, int) <-chan peer.AddrInfo
}
ContentRouting 是一个值提供者的间接层。它用于找到谁拥有什么内容的信息。
内容由CID(内容标识符)标识,它以未来可证明的方式编码了被标识内容的哈希值。
type DeP2P ¶
type DeP2P struct {
// contains filtered or unexported fields
}
func NewDeP2P ¶
func NewDeP2P(ctx context.Context, opts ...OptionDeP2P) (*DeP2P, error)
New 创建新的 DeP2P 实例
func (*DeP2P) RoutingTable ¶
func (bp *DeP2P) RoutingTable(mode int) *kbucket.RoutingTable
RoutingTable 根据dht类型获取指定类型RoutingTable
func (*DeP2P) RoutingTables ¶
func (bp *DeP2P) RoutingTables() map[int]*kbucket.RoutingTable
RoutingTables 返回 RoutingTables
type DeP2PDHT ¶
type DeP2PDHT struct {
// Validator 是一个应该由记录验证器实现的接口。
Validator record.Validator // 记录验证器
// contains filtered or unexported fields
}
DeP2PDHT 是经过 S/Kademlia 修改的 Kademlia 实现。 它用于实现基本路由模块。
func New ¶
New 使用指定的主机和选项创建一个新的 DHT。 请注意,连接到 DHT 对等点并不一定意味着它也在 DHT 路由表中。 如果路由表具有超过"minRTRefreshThreshold"的对等点,则仅当我们成功从某个对等点获取查询响应或它向我们发送查询时,我们才会将其视为路由表候选者。
func (*DeP2PDHT) FindProvidersAsync ¶
func (dht *DeP2PDHT) FindProvidersAsync(ctx context.Context, key cid.Cid, count int) <-chan peer.AddrInfo
FindProvidersAsync 与 FindProviders 方法相同,但返回一个通道。 对等节点将在找到时立即通过通道返回,即使搜索查询尚未完成。 如果 count 为零,则查询将一直运行,直到完成。 注意:不读取返回的通道可能会阻塞查询的进展。
func (*DeP2PDHT) ForceRefresh ¶
ForceRefresh 行为类似于 RefreshRoutingTable,但强制 DHT 刷新路由表中的所有存储桶,无论上次刷新时间如何。
返回的通道将阻塞直到刷新完成,然后产生错误并关闭。 该通道已缓冲并且可以安全地忽略。
func (*DeP2PDHT) GetClosestPeers ¶
GetClosestPeers 是一个 Kademlia 的 'node lookup' 操作。返回与给定键最接近的 K 个节点的通道。
如果上下文被取消,该函数将返回上下文错误以及迄今为止找到的最接近的 K 个节点。
func (*DeP2PDHT) RefreshRoutingTable ¶
RefreshRoutingTable 告诉 DHT 刷新它的路由表。
返回的通道将阻塞直到刷新完成,然后产生错误并关闭。 该通道已缓冲并且可以安全地忽略。
func (*DeP2PDHT) RoutingTable ¶
func (dht *DeP2PDHT) RoutingTable() *kb.RoutingTable
RoutingTable 返回 DHT 的路由表。
type DiskInfo ¶
type DiskInfo struct {
TotalSize string // 硬盘大小
FreeSpace string // 剩余空间
UsedSpace string // 已使用空间
UsagePercent float64 // 使用率
HomeDirTotalSize string // 当前用户硬盘大小
HomeDirFreeSpace string // 当前用户剩余空间
HomeDirUsedSpace string // 当前用户已使用空间
HomeDirUsagePercent float64 // 当前用户使用率
}
硬盘信息
type LookupEvent ¶
type LookupEvent struct {
// Node 是执行查找的节点的 ID。
Node *PeerKadID
// ID 是查找实例的唯一标识符。
ID uuid.UUID
// Key 是用作查找目标的 Kademlia 密钥。
Key *KeyKadID
// Request, 如果不为零,则描述与传出查询请求关联的状态更新事件。
Request *LookupUpdateEvent
// Response, 如果不为零,则描述与传出查询响应关联的状态更新事件。
Response *LookupUpdateEvent
// Terminate, 如果不为零,则描述终止事件。
Terminate *LookupTerminateEvent
}
LookupEvent 为 DHT 查找期间发生的每个显着事件发出。 LookupEvent 支持 JSON 编组,因为它的所有字段都以递归方式支持。
func NewLookupEvent ¶
func NewLookupEvent( node peer.ID, id uuid.UUID, key string, request *LookupUpdateEvent, response *LookupUpdateEvent, terminate *LookupTerminateEvent, ) *LookupEvent
NewLookupEvent 创建一个 LookupEvent,自动将节点 dep2p Peer ID 转换为 PeerKadID,并将字符串 Kademlia 键转换为 KeyKadID。
type LookupTerminateEvent ¶
type LookupTerminateEvent struct {
// Reason 是查找终止的原因。
Reason LookupTerminationReason
}
LookupTerminateEvent 描述查找终止事件。
func NewLookupTerminateEvent ¶
func NewLookupTerminateEvent(reason LookupTerminationReason) *LookupTerminateEvent
NewLookupTerminateEvent 创建一个具有给定原因的新查找终止事件。
type LookupTerminationReason ¶
type LookupTerminationReason int
LookupTerminationReason 捕获终止查找的原因。
const ( // LookupStopped 表示查找被用户的 stopFn 中止。 LookupStopped LookupTerminationReason = iota // LookupCancelled 表示查找被上下文中止。 LookupCancelled // LookupStarvation 表示查找由于缺少未查询的对等点而终止。 LookupStarvation // LookupCompleted 表示查找成功终止,达到 Kademlia 结束条件。 LookupCompleted )
func (LookupTerminationReason) MarshalJSON ¶
func (r LookupTerminationReason) MarshalJSON() ([]byte, error)
MarshalJSON 返回传递的查找终止原因的 JSON 编码。
func (LookupTerminationReason) String ¶
func (r LookupTerminationReason) String() string
type LookupUpdateEvent ¶
type LookupUpdateEvent struct {
// Cause 是其响应(或缺乏响应)导致更新事件的对等方。
// 如果 Cause 为零,则这是查找中的第一个更新事件,由播种引起。
Cause *PeerKadID
// Source 是向我们通报此更新中的对等 ID 的对等点(如下)。
Source *PeerKadID
// Heard 是一组对等体,其在查找对等体集中的状态被设置为“已听到”。
Heard []*PeerKadID
// Waiting 是一组对等体,其在查找对等体集中的状态被设置为“等待”。
Waiting []*PeerKadID
// Queried 是一组对等体,其在查找对等体集中的状态被设置为“已查询”。
Queried []*PeerKadID
// Unreachable 是一组对等体,其在查找对等体集中的状态被设置为“无法访问”。
Unreachable []*PeerKadID
}
LookupUpdateEvent 描述查找状态更新事件。
type MemoryInfo ¶
type MemoryInfo struct {
TotalMemory string // 内存总大小
UsedMemory string // 已用大小
AvailableMemory string // 剩余大小
MemoryUsage float64 // 内存使用率
}
内存信息
type NetworkInfo ¶
type NetworkInfo struct {
IspName string // 网络类型
UpstreamBandwidth float64 // 上行带宽
DownstreamBandwidth float64 // 下行带宽
NetworkStatus string // 网络状态
LocalIPAddress string // 本地IP地址
PublicAddress string // 公网IP地址
MACAddress string // MAC地址
Lat string // 纬度
Lon string // 经度
}
网络信息
type NodeInfo ¶
type NodeInfo struct {
HostNmae string // 主机名字
OSName string // 主机系统
DiskInfo DiskInfo // 硬盘信息
NetworkInfo NetworkInfo // 网络信息
CPUInfo CPUInfo // CPU信息
MemoryInfo MemoryInfo // 内存信息
}
节点信息
func GetNodeInfo ¶
func GetNodeInfo() *NodeInfo
type OptionDeP2P ¶
Option 类型是一个函数,它接受一个 DeP2P 指针,并返回一个错误。它用于配置 DeP2P 结构体的选项。
func WithBootstrapsPeers ¶
func WithBootstrapsPeers(bootstrapsPeers []string) OptionDeP2P
WithBootstrapsPeers 设置引导节点
func WithLibp2pOpts ¶
func WithLibp2pOpts(Option []config.Option) OptionDeP2P
WithLibp2pOpts 设置本地网络监听地址
func WithRendezvousString ¶
func WithRendezvousString(rendezvousString string) OptionDeP2P
WithRendezvousString 设置本地网络监听地址
type PeerKadID ¶
PeerKadID 包含一个 libp2p Peer ID 和一个二进制 Kademlia ID。
func NewPeerKadID ¶
NewPeerKadID 从 libp2p Peer ID 创建 PeerKadID。
func NewPeerKadIDSlice ¶
NewPeerKadIDSlice 从传递的 libp2p Peer ID 片段创建 PeerKadID 片段。
func OptPeerKadID ¶
OptPeerKadID 返回一个指向 PeerKadID 的指针,如果传递的 Peer ID 是它的默认值,则返回 nil。
type QueryFilterFunc ¶
type QueryFilterFunc = dhtcfg.QueryFilterFunc
QueryFilterFunc 是在查询时考虑要拨号的对等点时应用的过滤器
type RouteTableFilterFunc ¶
type RouteTableFilterFunc = dhtcfg.RouteTableFilterFunc
RouteTableFilterFunc 是在考虑要保留在本地路由表中的连接时应用的过滤器。
type RoutingDiscovery ¶
type RoutingDiscovery struct {
routing.ContentRouting
}
RoutingDiscovery 是使用 ContentRouting 的发现实现。 使用 SHA256 哈希将命名空间转换为 Cids。
func NewRoutingDiscovery ¶
func NewRoutingDiscovery(router routing.ContentRouting) *RoutingDiscovery
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package core provides convenient access to foundational, central dep2p primitives via type aliases.
|
Package core provides convenient access to foundational, central dep2p primitives via type aliases. |
|
connmgr
Package connmgr provides connection tracking and management interfaces for dep2p.
|
Package connmgr provides connection tracking and management interfaces for dep2p. |
|
crypto
Package crypto implements various cryptographic utilities used by dep2p.
|
Package crypto implements various cryptographic utilities used by dep2p. |
|
discovery
Package discovery provides service advertisement and peer discovery interfaces for dep2p.
|
Package discovery provides service advertisement and peer discovery interfaces for dep2p. |
|
event
Package event contains the abstractions for a local event bus, along with the standard events that dep2p subsystems may emit.
|
Package event contains the abstractions for a local event bus, along with the standard events that dep2p subsystems may emit. |
|
host
Package host provides the core Host interface for dep2p.
|
Package host provides the core Host interface for dep2p. |
|
metrics
Package metrics provides metrics collection and reporting interfaces for dep2p.
|
Package metrics provides metrics collection and reporting interfaces for dep2p. |
|
network
Package network provides core networking abstractions for dep2p.
|
Package network provides core networking abstractions for dep2p. |
|
network/mocks
Code generated by MockGen.
|
Code generated by MockGen. |
|
peer
Package peer implements an object used to represent peers in the dep2p network.
|
Package peer implements an object used to represent peers in the dep2p network. |
|
peerstore
Package peerstore provides types and interfaces for local storage of address information, metadata, and public key material about dep2p peers.
|
Package peerstore provides types and interfaces for local storage of address information, metadata, and public key material about dep2p peers. |
|
pnet
Package pnet provides interfaces for private networking in dep2p.
|
Package pnet provides interfaces for private networking in dep2p. |
|
protocol
Package protocol provides core interfaces for protocol routing and negotiation in dep2p.
|
Package protocol provides core interfaces for protocol routing and negotiation in dep2p. |
|
routing
Package routing provides interfaces for peer routing and content routing in dep2p.
|
Package routing provides interfaces for peer routing and content routing in dep2p. |
|
sec
Package sec provides secure connection and transport interfaces for dep2p.
|
Package sec provides secure connection and transport interfaces for dep2p. |
|
sec/insecure
Package insecure provides an insecure, unencrypted implementation of the SecureConn and SecureTransport interfaces.
|
Package insecure provides an insecure, unencrypted implementation of the SecureConn and SecureTransport interfaces. |
|
transport
Package transport provides the Transport interface, which represents the devices and network protocols used to send and receive data.
|
Package transport provides the Transport interface, which represents the devices and network protocols used to send and receive data. |
|
Package kbucket implements a kademlia 'k-bucket' routing table.
|
Package kbucket implements a kademlia 'k-bucket' routing table. |
|
generate
command
|
|
