/
main.go
49 lines (42 loc) · 1.03 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
package main
import (
"flag"
"fmt"
"log"
"strings"
"sync"
"github.com/degdb/degdb/core"
"github.com/dustin/go-humanize"
"github.com/fatih/color"
)
var (
bindPort = flag.Int("port", 7946, "The port to bind on.")
initialPeers = flag.String("peers", "", "CSV list of peers to connect to.")
diskAllowed = flag.String("disk", "1G", "Amount of disk space to allocate.")
nodes = flag.Int("nodes", 1, "Number of nodes to launch in this binary. Development use only. Disables external connections.")
)
func main() {
flag.Parse()
color.NoColor = false
var peers []string
if len(*initialPeers) > 0 && *nodes == 1 {
peers = strings.Split(*initialPeers, ",")
}
diskFloat, _, err := humanize.ParseSI(*diskAllowed)
if err != nil {
log.Fatal(err)
}
disk := int(diskFloat)
var wg sync.WaitGroup
for i := 0; i < *nodes; i++ {
port := *bindPort + i
launchPeers := peers
go func() {
core.Main(port, launchPeers, disk)
wg.Done()
}()
wg.Add(1)
peers = []string{fmt.Sprintf("localhost:%d", port)}
}
wg.Wait()
}