-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-discovery.go
More file actions
49 lines (38 loc) · 1.2 KB
/
test-discovery.go
File metadata and controls
49 lines (38 loc) · 1.2 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
package main
import (
"fmt"
"time"
"nghost/internal/config"
"nghost/internal/nkn"
)
func testExitNodeDiscovery(configPath string) error {
cfg, err := config.Load(configPath)
if err != nil {
return fmt.Errorf("failed to load config: %w", err)
}
fmt.Println("🔍 Testing exit node discovery...")
nknClient, err := nkn.NewClient(cfg.NKN)
if err != nil {
return fmt.Errorf("failed to create NKN client: %w", err)
}
defer nknClient.Close()
fmt.Printf("📡 Your NKN Address: %s\n", nknClient.GetAddress())
fmt.Println("🔗 Waiting for NKN connection...")
// Wait for connection and discovery
for i := 0; i < 30; i++ {
time.Sleep(1 * time.Second)
peers := nknClient.GetPeers()
exitNodes := nknClient.FindExitNodes()
fmt.Printf("\r⏱️ %02ds - Peers: %d, Exit nodes: %d", i+1, len(peers), len(exitNodes))
if len(exitNodes) > 0 {
fmt.Printf("\n🎉 Found exit nodes!\n")
for _, node := range exitNodes {
fmt.Printf(" 🚪 %s (IP: %s)\n", node.Address[:16]+"...", node.IPAddress)
}
return nil
}
}
fmt.Printf("\n❌ No exit nodes discovered after 30 seconds\n")
fmt.Println("💡 Make sure an exit node is running with: sudo ./nghost -exit-node")
return nil
}