-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
84 lines (66 loc) · 1.51 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
package main
import (
"context"
"encoding/gob"
"fmt"
"log"
"math"
"os"
"os/signal"
"syscall"
"time"
)
const (
numberOfNodes int = 21
numberOfPeers int = 5
listenPort int64 = 11111
numberOfDelegates int64 = int64(numberOfNodes)
slotTimeInterval int64 = 3
)
var (
maxFPNode = int64(math.Floor(float64((numberOfDelegates - 1) / 3)))
currentForger int64 = -1
)
func gobInterfaceRegister() {
gob.Register(Block{})
gob.Register(Transaction{})
gob.Register(StageMessage{})
}
func init() {
gobInterfaceRegister()
}
func main() {
ctx, cancel := context.WithCancel(context.Background())
sysdone := make(chan struct{}, 1)
sigCh := make(chan os.Signal, 1)
log.SetFlags(log.LstdFlags | log.Lshortfile)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigCh
sysdone <- struct{}{}
}()
fmt.Println("MAX FP Node", maxFPNode)
nodes := make([]*Node, 0)
for i := 0; i < numberOfNodes; i++ {
node := NewNode(ctx, int64(i))
nodes = append(nodes, node)
}
fmt.Println("===================================")
time.Sleep(time.Second * 1)
for i := 0; i < numberOfNodes; i++ {
nodes[i].Connect(ctx)
}
fmt.Println("===================================")
time.Sleep(time.Second * 1)
for i := 0; i < numberOfNodes; i++ {
fmt.Println("NodeId:", i, len(nodes[i].Peers))
}
fmt.Println("===================================")
time.Sleep(time.Second * 1)
for i := 0; i < numberOfNodes; i++ {
go nodes[i].StartForging()
}
<-sysdone
fmt.Println("SSS")
cancel()
}