|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"flag"
|
|
|
|
"log"
|
|
|
|
"strings"
|
|
|
|
"strconv"
|
|
|
|
"FRMS/internal/pkg/reactor"
|
|
|
|
)
|
|
|
|
|
|
|
|
type coordinator interface {
|
|
|
|
Start()
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCoordinator(ip string,port int,ch chan error) coordinator {
|
|
|
|
// allows interface checking as opposed to calling directly
|
|
|
|
return reactor.NewCoordinator(ip,port,ch)
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var ip string
|
|
|
|
var port int
|
|
|
|
|
|
|
|
flag.Usage = func() {
|
|
|
|
w := flag.CommandLine.Output()
|
|
|
|
fmt.Fprintf(w, "Usage: %s ip_addr port \n",os.Args[0])
|
|
|
|
}
|
|
|
|
flag.Parse()
|
|
|
|
if flag.NArg() != 2 {
|
|
|
|
flag.Usage()
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
args := flag.Args()
|
|
|
|
if s := strings.Split(args[0],"."); len(s) != 4 {
|
|
|
|
flag.Usage()
|
|
|
|
log.Fatal("second arguement must be an ip address of type x.x.x.x")
|
|
|
|
}
|
|
|
|
if p, err := strconv.Atoi(args[1]);p < 1024 || p > 65535 {
|
|
|
|
flag.Usage()
|
|
|
|
log.Fatal("Port must be between [1023,65535]")
|
|
|
|
} else if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
ip = args[0]
|
|
|
|
port, err := strconv.Atoi(args[1])
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
ch := make(chan error)
|
|
|
|
rlc := NewCoordinator(ip,port,ch) // host port
|
|
|
|
go rlc.Start()
|
|
|
|
err = <-ch
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|