-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
92 lines (73 loc) · 2.05 KB
/
main.go
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
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
"github.com/olekukonko/ts"
)
// Update progress and display in the terminal
func updateProgress() {
for {
mu.Lock()
totalRelays := len(clearOnline) + len(clearOffline) // Include both online and offline relays
crawled := len(crawledRelays)
mu.Unlock()
remaining := totalRelays - crawled
if remaining < 0 {
remaining = 0
}
// Progress calculation
var progress float64
if totalRelays > 0 {
progress = (float64(crawled) / float64(totalRelays)) * 100
}
// Print the status at the bottom
screen, _ := ts.GetSize() // Get terminal size to dynamically adjust progress bar width
barWidth := screen.Col() - 30 // Adjust width for bar
progressBar := generateProgressBar(int(progress), barWidth)
// Clear last line and print status
fmt.Printf("\rDiscovered Relays: %d | Crawled Relays: %d | Remaining: %d | [%s] %.2f%%",
totalRelays, crawled, remaining, progressBar, progress)
time.Sleep(1 * time.Second)
}
}
// Generate a progress bar
func generateProgressBar(progress int, width int) string {
filled := (progress * width) / 100
bar := ""
for i := 0; i < filled; i++ {
bar += "="
}
for i := filled; i < width; i++ {
bar += " "
}
return bar
}
func main() {
exitSignal := make(chan os.Signal, 1)
signal.Notify(exitSignal, os.Interrupt, syscall.SIGTERM)
go logRelayEvents() // Start the logger goroutine
go func() {
initialRelay := "wss://nos.lol"
concurrency := 200 // Adjust this value based on your needs and system capabilities
for {
err := ReqKind10002(initialRelay)
if err != nil {
logChannel <- fmt.Sprintf("Initial crawl failed: %v", err)
}
crawlClearOnlineRelays(concurrency)
mu.Lock()
logChannel <- fmt.Sprintf("Discovered relays: %d", len(clearOnline))
mu.Unlock()
time.Sleep(2 * time.Second)
}
}()
// Start the progress updater in a separate goroutine
go updateProgress()
// Wait for an exit signal (Ctrl+C or kill)
<-exitSignal
fmt.Println("\nReceived exit signal, writing logs and exiting...")
finalize()
}