-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
97 lines (83 loc) · 1.85 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
93
94
95
96
97
package main
import (
"time"
)
func main() {
var err error
MyNode, err = CreateNodeIfNotExists(MyNodePath)
if err != nil {
panic(err)
}
MyUser, err = CreateUserIfNotExists(MyUserConfPath, "DefaultBob")
if err != nil {
panic(err)
}
// Checks if agora is running in CLI mode and executes cmds
// accordingly
HandleCmdIfCLI()
// Initialize Curation module
err = MyCurator.Init()
if err != nil {
panic(err)
}
defer MyCurator.Close()
// Starts PeerServer (non-blocking)
if opts.NoPeer {
Info.Println("PeerServer that provides PeerAPI disabled")
} else {
StartPeerAPI(MyNode)
}
// Starts peer list monitor (non-blocking)
if opts.MonPeers {
Info.Println("Peer monitor enabled")
go monitorPeers(MyNode)
}
// Discover new peers periodically
if opts.NoDiscover {
Info.Println("Discovery disabled")
} else {
go func() {
for {
MyNode.DiscoverPeers()
time.Sleep(20 * time.Second)
}
}()
}
if opts.NoPull {
Info.Println("Content pull disabled")
} else {
time.Sleep(5 * time.Second)
go func() {
for {
time.Sleep(3 * time.Second)
Info.Println("Pull new content from known network")
peers, err := MyNode.GetSomePeers()
if err != nil {
Error.Println("Unable to get list of known peers", err)
continue
}
for _, p := range peers {
Info.Println("Pull content from", p)
MyNode.pullPostFrom(p)
}
if !opts.NoComments {
// @TODO better to not check all at once
posts, err := MyNode.GetPosts()
if err != nil {
Error.Println("Unable to get list of posts", err)
continue
}
for _, p := range posts {
err := MyNode.pullPostComments(p)
if err != nil {
Warning.Println("Error getting comments for post", p, err)
continue
}
}
}
}
}()
}
// Starts communication pipeline for GUI
StartGUIPipe(MyNode)
}