-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
73 lines (68 loc) · 1.69 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
package main
import (
"flag"
"log"
"os"
)
func main() {
var service string
var address string
var mode string
var data string
var count int
var clientKey string
var clientGen string
var clientToken string
flag.StringVar(&service, "service_type", "simple", "Only [simple | mod] service type")
flag.StringVar(&address, "address", "127.0.0.1:59090", "Bind address")
flag.StringVar(&mode, "mode", "testing", "Only [client | service | testing | selftest]")
flag.StringVar(&data, "data", "Simple_Token_Data", "Token data")
flag.IntVar(&count, "count", 100, "Count")
flag.StringVar(&clientKey, "c_key", "empty", "Client private key")
flag.StringVar(&clientGen, "c_gen", "empty", "Client generation")
flag.StringVar(&clientToken, "c_tok", "empty", "Client token")
flag.Parse()
store := NewStore()
store.LoadAll()
if mode == "selftest" {
c := NewClient()
c.LoadTokens()
tokenHash := c.NewToken(data)
for i := 0; i < count; i++ {
hash := c.AddHash(tokenHash)
verified := store.Add(hash)
log.Println("Verified: ", verified)
if !verified {
break
}
}
c.StoreTokens()
} else if mode == "testing" {
var verified bool
go StartService(address, &store)
sc := NewSimpleClient(address)
defer sc.Close()
c := NewClient()
c.LoadTokens()
tokenHash := c.NewToken(data)
for i := 0; i < count; i++ {
hash := c.AddHash(tokenHash)
verified = sc.CreateHash(hash)
log.Println("Verified: ", verified)
if !verified {
break
}
}
if verified {
c.StoreTokens()
}
} else if mode == "service" {
log.Println("Starting ", address, " ...")
StartService(address, &store)
} else {
log.Fatal("Unknown mode ", mode)
os.Exit(-1)
}
store.StoreAll()
os.Exit(0)
}