-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
62 lines (50 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
package main
import (
"flag"
"os"
"polar/database"
"polar/models"
"polar/rpc"
"polar/utils"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
var (
bind *string
netw *string
port *string
seed *string
data *string
)
func init() {
// Print banner, because it's nice :)
utils.Banner("alpha-01")
// Setup logger
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
// Declare CLI flags
bind = flag.String("bind", "127.0.0.1", "address to bind polar on")
port = flag.String("port", "1312", "port on which the node will listen")
netw = flag.String("network", "mainnet", "network polar connect to, mainnet for production, testnet for experiment, etc")
seed = flag.String("seed", "https://polar.coldnet.org:1312", "address to an instance of polar to download the network and discorver new nodes")
data = flag.String("data", "/opt/polar/", "path to the folder where the local database will be stored")
flag.Parse()
// Check if storage dir exist and if signing keys are there
utils.CheckPath(*data)
utils.ChecKeys(*data)
// Init database
database.Connect(*data)
database.DB.AutoMigrate(&models.Node{})
database.DB.AutoMigrate(&models.Object{})
address := *bind + ":" + *port
utils.InitNode(&address, *data, *seed, *netw)
}
func main() {
log.Info().Msg("seeding server: " + *seed)
log.Info().Msg("data path: " + *data)
log.Info().Msg("Listing nodes:")
nodes := models.Node{}.List()
for _, node := range nodes {
log.Info().Msg(node.Address + "/" + node.PublicKey)
}
rpc.Listen(*port)
}