diff --git a/cmd/gosdn-tview/grpc/commands.go b/cmd/gosdn-tview/grpc/commands.go index c243d6517ee2fc8b1dd0a56edd343123df73804a..74d2b09558e9e5a51a1ee3427623c96ca7006dfd 100644 --- a/cmd/gosdn-tview/grpc/commands.go +++ b/cmd/gosdn-tview/grpc/commands.go @@ -32,7 +32,7 @@ var CommandList = []command{ //Connect creates a new connection to the gRPC server func Connect() (*grpc.ClientConn, error) { - address := "localhost:55055" + address := "141.100.70.170:55066" return grpc.Dial(address, grpc.WithInsecure(), grpc.WithTimeout(5*time.Second), grpc.WithBlock()) } diff --git a/nucleus/cli-handling.go b/nucleus/cli-handling.go index 1f4d6981338518ada182f059bcce28dd05b300c7..2afb6f6f3a87e1597b5179e16d813c0cad92ec7d 100644 --- a/nucleus/cli-handling.go +++ b/nucleus/cli-handling.go @@ -8,9 +8,10 @@ package nucleus import ( "context" + "io" "net" + "os" "sync" - "time" pb "code.fbi.h-da.de/cocsn/gosdn/api/proto" "code.fbi.h-da.de/cocsn/gosdn/log" @@ -33,6 +34,17 @@ type server struct { logConnections []*LogConnection } +var srv *server + +type buf []byte + +func (b *buf) Write(p []byte) (n int, err error) { + + reply := pb.LogReply{Log: string(p)} + srv.BroadcastLog(&reply) + return len(p), nil +} + func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) { log.Info("Received: ", in.GetName()) return &pb.HelloReply{Message: "Hello " + in.GetName(), GoSDNInfo: "goSDN in version: DEVELOP"}, nil @@ -88,6 +100,8 @@ func (s *server) Shutdown(ctx context.Context, in *pb.ShutdownRequest) (*pb.Shut func getCLIGoing(core *Core) { var logConnections []*LogConnection + var logBuffer buf + log.Info("Starting: GetCLIGoing") // Boot-up the control interface for the cli cliControlListener, err := net.Listen("tcp", core.config.CliSocket) @@ -96,18 +110,13 @@ func getCLIGoing(core *Core) { } cliControlServer := grpc.NewServer() - server := &server{core: core, logConnections: logConnections} + srv = &server{core: core, logConnections: logConnections} - pb.RegisterGrpcCliServer(cliControlServer, server) + //TODO: move? + wrt := io.MultiWriter(os.Stdout, &logBuffer) + log.Output(wrt) - //TODO: remove! - go func() { - ticker := time.NewTicker(5 * time.Second) - for t := range ticker.C { - reply := pb.LogReply{Log: t.String()} - server.BroadcastLog(&reply) - } - }() + pb.RegisterGrpcCliServer(cliControlServer, srv) if err := cliControlServer.Serve(cliControlListener); err != nil { log.Fatal(err)