-
Manuel Kieweg authoredManuel Kieweg authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
nucleus-core.go 2.03 KiB
package nucleus
import (
pb "code.fbi.h-da.de/cocsn/gosdn/cliInterface"
"code.fbi.h-da.de/cocsn/gosdn/database"
"code.fbi.h-da.de/cocsn/gosdn/log"
"code.fbi.h-da.de/cocsn/gosdn/nucleus/interfaces"
"context"
_ "github.com/mattn/go-sqlite3"
"google.golang.org/grpc"
"net"
"time"
)
// server is used to implement helloworld.GreeterServer.
type server struct {
pb.UnimplementedGreeterServer
core *Core
}
// SayHello implements helloworld.GreeterServer
func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {
log.Debug("Received: %v", in.GetName())
return &pb.HelloReply{Message: "Hello " + in.GetName()}, nil
}
func (s *server) Shutdown(ctx context.Context, in *pb.ShutdownRequest) (*pb.ShutdownReply, error) {
log.Debug("Received: %v", in.GetName())
isRunning = false
return &pb.ShutdownReply{Message: "Shutdown " + in.GetName()}, nil
}
func getCLIGoing(core *Core) {
log.Info("Starting: GetCLIGoing")
// Boot-up the control interface for the cli
cliControlListener, err := net.Listen("tcp", core.config.CliSocket)
if err != nil {
log.Fatal("failed to listen: %v", err)
}
cliControlServer := grpc.NewServer()
pb.RegisterGreeterServer(cliControlServer, &server{core: core})
if err := cliControlServer.Serve(cliControlListener); err != nil {
log.Fatal("failed to serve: %v", err)
}
log.Info("Started: GetCLIGoing")
}
/*
* This function is used to start the core of the controller and any auxiliary services.
*/
// Next-up: backend database.
func StartUp(socket, filename string) {
log.Info("This is the network superintendent...")
log.Info("Starting my ducks")
// Init the Core
core := Core{
clients: make(map[string]interfaces.Client),
database: database.Database{},
}
core.Init(socket, filename)
// Start the GRCP CLI
go getCLIGoing(&core)
log.Info("and ready for take off")
}
/*
* nucleus.Run() is the "main loop" of the controller
*/
var isRunning = true
func Run() {
for isRunning {
time.Sleep(10 * time.Second)
log.Debug("Still alive...")
}
log.Info("Good bye....!")
}