-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_capabilities.go
More file actions
111 lines (96 loc) · 3.6 KB
/
node_capabilities.go
File metadata and controls
111 lines (96 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package dep2p
import (
"context"
"fmt"
pkgif "github.com/dep2p/go-dep2p/pkg/interfaces"
"github.com/dep2p/go-dep2p/pkg/types"
)
// ════════════════════════════════════════════════════════════════════════════
// Bootstrap 能力(ADR-0009)
// ════════════════════════════════════════════════════════════════════════════
// EnableBootstrap 启用 Bootstrap 能力
//
// 将当前节点设置为引导节点,为网络中的新节点提供初始对等方发现服务。
func (n *Node) EnableBootstrap(ctx context.Context) error {
if n.bootstrapService == nil {
return fmt.Errorf("bootstrap service not available")
}
return n.bootstrapService.Enable(ctx)
}
// DisableBootstrap 禁用 Bootstrap 能力
//
// 停止作为引导节点服务,但保留已存储的节点信息。
func (n *Node) DisableBootstrap(ctx context.Context) error {
if n.bootstrapService == nil {
return nil
}
return n.bootstrapService.Disable(ctx)
}
// IsBootstrapEnabled 检查 Bootstrap 能力是否已启用
func (n *Node) IsBootstrapEnabled() bool {
if n.bootstrapService == nil {
return false
}
return n.bootstrapService.IsEnabled()
}
// BootstrapStats 获取 Bootstrap 统计信息
func (n *Node) BootstrapStats() pkgif.BootstrapStats {
if n.bootstrapService == nil {
return pkgif.BootstrapStats{}
}
return n.bootstrapService.Stats()
}
// ════════════════════════════════════════════════════════════════════════════
// Relay 能力(v2.0 统一接口)
// ════════════════════════════════════════════════════════════════════════════
// EnableRelay 启用 Relay 能力
//
// 将当前节点设置为中继服务器,为 NAT 后的节点提供中继服务。
func (n *Node) EnableRelay(ctx context.Context) error {
if n.relayManager == nil {
return fmt.Errorf("relay manager not available")
}
return n.relayManager.EnableRelay(ctx)
}
// DisableRelay 禁用 Relay 能力
func (n *Node) DisableRelay(ctx context.Context) error {
if n.relayManager == nil {
return nil
}
return n.relayManager.DisableRelay(ctx)
}
// IsRelayEnabled 检查 Relay 能力是否已启用
func (n *Node) IsRelayEnabled() bool {
if n.relayManager == nil {
return false
}
return n.relayManager.IsRelayEnabled()
}
// SetRelayAddr 设置要使用的 Relay 地址(客户端使用)
func (n *Node) SetRelayAddr(addr types.Multiaddr) error {
if n.relayManager == nil {
return fmt.Errorf("relay manager not available")
}
return n.relayManager.SetRelayAddr(addr)
}
// RemoveRelayAddr 移除 Relay 地址配置
func (n *Node) RemoveRelayAddr() error {
if n.relayManager == nil {
return nil
}
return n.relayManager.RemoveRelayAddr()
}
// RelayAddr 获取当前配置的 Relay 地址
func (n *Node) RelayAddr() (types.Multiaddr, bool) {
if n.relayManager == nil {
return nil, false
}
return n.relayManager.RelayAddr()
}
// RelayStats 获取 Relay 统计信息
func (n *Node) RelayStats() pkgif.RelayStats {
if n.relayManager == nil {
return pkgif.RelayStats{}
}
return n.relayManager.RelayStats()
}