-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (40 loc) · 955 Bytes
/
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
package main
import (
"bufio"
"github.com/drp6/distrox/proxy"
"log"
"os"
"strconv"
"strings"
)
func main() {
// setup logger
log.SetFlags(log.LstdFlags | log.Lshortfile)
args := os.Args
host := args[1]
port, err := strconv.Atoi(args[2])
if err != nil {
log.Fatal(err)
}
is_leader, err := strconv.ParseBool(args[3])
if err != nil {
log.Fatal(err)
}
p := proxy.CreateProxyNode(host, port, is_leader, "config.json")
go p.HandleRequests()
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
line := scanner.Text()
tokens := strings.Split(line, " ")
if tokens[0] == "connect" {
message := p.Info.Url
msg := proxy.CreateMessage([]byte(message), p.Info.Url, proxy.JOIN_REQUEST_MESSAGE)
bytes := proxy.MessageToBytes(msg)
p.Unicast(bytes, tokens[1])
} else {
msg := proxy.CreateMessage([]byte(line), p.Info.Url, proxy.UNICAST_MESSAGE)
bytes := proxy.MessageToBytes(msg)
p.Multicast(bytes)
}
}
}