forked from sieve-project/sieve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
34 lines (31 loc) · 872 Bytes
/
server.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
package main
import (
"log"
"net"
"net/rpc"
"os"
sieve "sieve.client"
)
// Sieve server runs on one of the kind-control-plane node (not in the pod).
// The server reads the config `server.yaml` and decides which listener to use.
// The listener will handle the RPC from sieve client (called by controllers or k8s components).
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile | log.Lmicroseconds)
log.Println("registering rpc server...")
args := os.Args
phase := args[1]
switch phase {
case sieve.LEARN:
rpc.Register(NewLearnListener())
case sieve.TEST:
rpc.Register(NewTestCoordinator())
default:
log.Fatalf("Cannot recognize mode: %s\n", phase)
}
log.Println("setting up connection...")
addr, err := net.ResolveTCPAddr("tcp", ":12345")
checkError(err)
inbound, err := net.ListenTCP("tcp", addr)
checkError(err)
rpc.Accept(inbound)
}