-
Notifications
You must be signed in to change notification settings - Fork 18
/
repserver.go
109 lines (98 loc) · 3.03 KB
/
repserver.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
98
99
100
101
102
103
104
105
106
107
108
109
// repserver is the repbin server that makes posts available to users.
package main
import (
"flag"
"fmt"
"os"
"runtime"
"github.com/repbin/repbin/cmd/repserver/handlers"
"github.com/repbin/repbin/cmd/repserver/messagestore"
"github.com/repbin/repbin/cmd/repserver/messagestore/sql"
log "github.com/repbin/repbin/deferconsole"
"github.com/repbin/repbin/hashcash"
"github.com/repbin/repbin/message"
"github.com/repbin/repbin/utils"
"github.com/repbin/repbin/utils/keyauth"
"github.com/repbin/repbin/utils/keyproof"
"github.com/repbin/repbin/utils/repproto"
"github.com/repbin/repbin/utils/repproto/structs"
_ "github.com/go-sql-driver/mysql"
_ "github.com/mattn/go-sqlite3"
)
// Version of this release
const Version = "0.0.2 very alpha"
var (
start *bool
stat *bool
)
func init() {
version := flag.Bool("version", false, "Print version information")
showconfig := flag.Bool("showconfig", false, "Print config file template")
configfile := flag.String("configfile", "", "Path to configuration file")
verbose := flag.Bool("verbose", false, "Show some verbose output")
start = flag.Bool("start", false, "Start server")
stat = flag.Bool("stat", false, "Enable usage statistics")
flag.Parse()
if *version {
fmt.Printf("Repserver: %s\n", Version)
fmt.Printf("MessageStore: %s\n", messagestore.Version)
fmt.Printf("SQL Store: %s\n", sql.Version)
fmt.Printf("Handlers: %s\n", handlers.Version)
fmt.Printf("HashCash: %s\n", hashcash.Version)
fmt.Printf("Utils: %s\n", utils.Version)
fmt.Printf("KeyAuth: %s\n", keyauth.Version)
fmt.Printf("KeyProof: %s\n", keyproof.Version)
fmt.Printf("Protocol: %s\n", repproto.Version)
fmt.Printf("Protocol Structures: %s\n", structs.Version)
fmt.Printf("Message: %s\n", message.VersionID)
fmt.Printf("Message Format: %d\n", message.Version)
os.Exit(0)
}
if *showconfig {
showConfig()
os.Exit(0)
}
if *configfile == "" || *configfile == "/" || len(*configfile) < 4 {
fmt.Println("No configuration file found. Specify with --configfile=FILE")
os.Exit(0)
}
if *verbose {
log.SetMinLevel(log.LevelDebug)
}
if *stat && !*verbose {
fmt.Println("Error: option --stat requires option --verbose")
os.Exit(1)
}
err := loadConfig(*configfile)
if err != nil {
fmt.Printf("Error: %s\n", err)
os.Exit(1)
}
}
func main() {
var pubKey, privKey []byte
pubKey, privKey = nil, nil
if defaultSettings.StoragePath == "" {
fmt.Println("Error: Storage path not configured")
os.Exit(1)
}
if defaultSettings.PeeringPublicKey != "" && defaultSettings.PeeringPrivateKey != "" {
pubKey = utils.B58decode(defaultSettings.PeeringPublicKey)
privKey = utils.B58decode(defaultSettings.PeeringPrivateKey)
}
runtime.GOMAXPROCS(runtime.NumCPU() - 1)
ms, err := handlers.New(defaultSettings.DBDriver, defaultSettings.DBURL, defaultSettings.StoragePath, pubKey, privKey)
if err != nil {
fmt.Printf("Error: %s\n", err)
os.Exit(1)
}
applyConfig(ms)
ms.Stat = *stat
if *start {
ms.RunServer()
} else {
fmt.Println("Server not started. Enable with --start")
os.Exit(1)
}
os.Exit(0)
}