-
Notifications
You must be signed in to change notification settings - Fork 0
/
registry.go
executable file
·59 lines (45 loc) · 1.12 KB
/
registry.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
package main
import (
"fmt"
"net"
"strconv"
"github.com/alecthomas/repr"
"github.com/neutrino2211/commander"
"github.com/neutrino2211/hush-server/protocol"
"github.com/neutrino2211/hush-server/tcp"
)
type RegistryCommand struct {
commander.Command
clusterAddresses []string
}
func (d *RegistryCommand) Init() {
d.Logger.Init("start", 0)
d.Optionals = map[string]*commander.Optional{
"port": {
Type: "int",
Description: "Port to run cluster on",
},
}
d.Values = map[string]string{}
d.Usage = "cluster registry"
d.Description = d.BuildHelp("Start a cluster registry")
}
func (d *RegistryCommand) Run() {
port := d.GetUint("port", 8107)
ip := d.GetString("ipaddress", "0.0.0.0")
d.Logger.LogString(fmt.Sprintf("Starting a cluster registry on port %d", port))
listener := tcp.TCPListener{
Port: ":" + strconv.Itoa(int(port)),
IP: ip,
}
listener.Start(func(c net.Conn) {
pkt := protocol.RegistryAuthPacketDefinition.ReadFromConn(c).Unwrap()
ok := protocol.RegistryAuthPacketDefinition.Validate(&pkt)
if !ok {
c.Write([]byte{0})
return
}
repr.Println(pkt)
c.Write([]byte{0})
})
}