From 58ef8a15d0228277bfdd76effa290b6abba1c07e Mon Sep 17 00:00:00 2001 From: sitzmaa Date: Sat, 15 Feb 2025 13:54:44 -0800 Subject: [PATCH] program starts with new build strategy --- core/run.py | 7 +- frontend/go_server/go.mod | 7 +- frontend/go_server/go.sum | 22 ++- frontend/go_server/grpc_client.go | 3 +- frontend/go_server/main.go | 45 ++++-- frontend/go_server/proto/netmap.pb.go | 153 ++++++++++----------- frontend/go_server/proto/netmap.proto | 21 +++ frontend/go_server/proto/netmap_grpc.pb.go | 75 ++++------ frontend/gui/grpc_client.py | 5 +- frontend/{ => gui/proto}/__init__.py | 0 frontend/gui/proto/netmap.proto | 21 +++ frontend/gui/proto/netmap_pb2.py | 16 +-- frontend/gui/proto/netmap_pb2_grpc.py | 78 +++-------- frontend/proto/netmap.proto | 16 --- 14 files changed, 235 insertions(+), 234 deletions(-) create mode 100644 frontend/go_server/proto/netmap.proto rename frontend/{ => gui/proto}/__init__.py (100%) create mode 100644 frontend/gui/proto/netmap.proto delete mode 100644 frontend/proto/netmap.proto diff --git a/core/run.py b/core/run.py index df71d25..299659f 100644 --- a/core/run.py +++ b/core/run.py @@ -36,11 +36,14 @@ def main(): time.sleep(0.5) if not args.server_only: if not args.no_cli: - cli_cmd = f"./frontend/netmap_cli/build/netmap_cli -H localhost {port}" + cli_cmd = f"./frontend/netmap_cli/build/netmap_cli -H localhost -p {port}" open_terminal(cli_cmd) if not args.no_gui: - gui_cmd = f"source venv/bin/activate && python3 ./frontend/gui.py --port {port}" + go_server_cmd ="cd ./frontend/go_server && go run main.go" + open_terminal(go_server_cmd) + time.sleep(0.5) + gui_cmd = "source venv/bin/activate && python3 ./frontend/gui/main.py" open_terminal(gui_cmd) if __name__ == "__main__": diff --git a/frontend/go_server/go.mod b/frontend/go_server/go.mod index a9a0eab..6757629 100644 --- a/frontend/go_server/go.mod +++ b/frontend/go_server/go.mod @@ -2,11 +2,14 @@ module netmap go 1.23.6 +require ( + google.golang.org/grpc v1.70.0 + google.golang.org/protobuf v1.36.5 +) + require ( golang.org/x/net v0.32.0 // indirect golang.org/x/sys v0.28.0 // indirect golang.org/x/text v0.21.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a // indirect - google.golang.org/grpc v1.70.0 // indirect - google.golang.org/protobuf v1.36.5 // indirect ) diff --git a/frontend/go_server/go.sum b/frontend/go_server/go.sum index 8c1a3f0..fb2a058 100644 --- a/frontend/go_server/go.sum +++ b/frontend/go_server/go.sum @@ -1,3 +1,23 @@ +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +go.opentelemetry.io/otel v1.32.0 h1:WnBN+Xjcteh0zdk01SVqV55d/m62NJLJdIyb4y/WO5U= +go.opentelemetry.io/otel v1.32.0/go.mod h1:00DCVSB0RQcnzlwyTfqtxSm+DRr9hpYrHjNGiBHVQIg= +go.opentelemetry.io/otel/metric v1.32.0 h1:xV2umtmNcThh2/a/aCP+h64Xx5wsj8qqnkYZktzNa0M= +go.opentelemetry.io/otel/metric v1.32.0/go.mod h1:jH7CIbbK6SH2V2wE16W05BHCtIDzauciCRLoc/SyMv8= +go.opentelemetry.io/otel/sdk v1.32.0 h1:RNxepc9vK59A8XsgZQouW8ue8Gkb4jpWtJm9ge5lEG4= +go.opentelemetry.io/otel/sdk v1.32.0/go.mod h1:LqgegDBjKMmb2GC6/PrTnteJG39I8/vJCAP9LlJXEjU= +go.opentelemetry.io/otel/sdk/metric v1.32.0 h1:rZvFnvmvawYb0alrYkjraqJq0Z4ZUJAiyYCU9snn1CU= +go.opentelemetry.io/otel/sdk/metric v1.32.0/go.mod h1:PWeZlq0zt9YkYAp3gjKZ0eicRYvOh1Gd+X99x6GHpCQ= +go.opentelemetry.io/otel/trace v1.32.0 h1:WIC9mYrXf8TmY/EXuULKc8hR17vE+Hjv2cssQDe03fM= +go.opentelemetry.io/otel/trace v1.32.0/go.mod h1:+i4rkvCraA+tG6AzwloGaCtkx53Fa+L+V8e9a7YvhT8= golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI= golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs= golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= @@ -8,7 +28,5 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a h1: google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU= google.golang.org/grpc v1.70.0 h1:pWFv03aZoHzlRKHWicjsZytKAiYCtNS0dHbXnIdq7jQ= google.golang.org/grpc v1.70.0/go.mod h1:ofIJqVKDXx/JiXrwr2IG4/zwdH9txy3IlF40RmcJSQw= -google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io= -google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM= google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= diff --git a/frontend/go_server/grpc_client.go b/frontend/go_server/grpc_client.go index 1ff28ba..8bc11aa 100644 --- a/frontend/go_server/grpc_client.go +++ b/frontend/go_server/grpc_client.go @@ -7,8 +7,7 @@ import ( "net" "google.golang.org/grpc" - "your_project_path/proto" // replace with the correct path to your generated proto files -) + "netmap/proto" const ( serverAddress = "localhost:50051" // Python gRPC server address diff --git a/frontend/go_server/main.go b/frontend/go_server/main.go index f1ef6e0..64e7983 100644 --- a/frontend/go_server/main.go +++ b/frontend/go_server/main.go @@ -2,34 +2,47 @@ package main import ( "context" + "encoding/json" "fmt" "log" "net" - "encoding/json" - pb "path/to/generated/proto" + pb "netmap/proto" // Ensure this is the correct relative path to your generated proto file "google.golang.org/grpc" ) -// NetMapServer struct +// NetMapServer struct implements the gRPC server interface type NetMapServer struct { pb.UnimplementedNetMapServer } -// GetState: Fetch current netmap state -func (s *NetMapServer) GetState(ctx context.Context, req *pb.Request) (*pb.Response, error) { - // Fetch network state from C++ server +// GetState: Fetch current netmap state and send it to the Python client +func (s *NetMapServer) GetState(ctx context.Context, req *pb.NetworkDataRequest) (*pb.NetworkDataResponse, error) { + // Fetch network state from the C++ backend data := queryCPlusPlusBackend() // Convert to JSON for Python GUI - jsonData, _ := json.Marshal(data) + jsonData, err := json.Marshal(data) + if err != nil { + return nil, fmt.Errorf("failed to marshal data: %v", err) + } - return &pb.Response{JsonData: string(jsonData)}, nil + // Return the response with the JSON data + return &pb.NetworkDataResponse{Message: string(jsonData)}, nil } -// Function to query C++ backend over socket +func (s *NetMapServer) SendNetworkData(ctx context.Context, req *pb.NetworkDataRequest) (*pb.NetworkDataResponse, error) { + // Handle the request and return a response + fmt.Println("Received network data:", req.GetNetworkData()) + return &pb.NetworkDataResponse{ + Message: "Network data received successfully", + }, nil +} + +// Function to query C++ backend (over a socket or another method) func queryCPlusPlusBackend() map[string]interface{} { - // Implement socket connection to C++ here + // Placeholder: Implement the actual socket or inter-process communication with C++ backend + // Example mock data returned from the C++ backend for demonstration return map[string]interface{}{ "nodes": []map[string]string{ {"ip": "192.168.1.1", "mac": "AA:BB:CC:DD:EE:FF"}, @@ -41,16 +54,22 @@ func queryCPlusPlusBackend() map[string]interface{} { } func main() { + // Listen for incoming connections on TCP port 50051 lis, err := net.Listen("tcp", ":50051") if err != nil { - log.Fatalf("Failed to listen: %v", err) + log.Fatalf("Failed to listen on port 50051: %v", err) } + // Create a new gRPC server grpcServer := grpc.NewServer() + + // Register the NetMapServer with the gRPC server pb.RegisterNetMapServer(grpcServer, &NetMapServer{}) - fmt.Println("gRPC Server running on port 50051") + fmt.Println("gRPC Server is running on port 50051") + + // Start serving requests if err := grpcServer.Serve(lis); err != nil { - log.Fatalf("Failed to serve: %v", err) + log.Fatalf("Failed to serve gRPC server: %v", err) } } \ No newline at end of file diff --git a/frontend/go_server/proto/netmap.pb.go b/frontend/go_server/proto/netmap.pb.go index 847501b..3733b28 100644 --- a/frontend/go_server/proto/netmap.pb.go +++ b/frontend/go_server/proto/netmap.pb.go @@ -2,9 +2,9 @@ // versions: // protoc-gen-go v1.36.5 // protoc v5.29.3 -// source: netmap.proto +// source: proto/netmap.proto -package netmap +package proto import ( protoreflect "google.golang.org/protobuf/reflect/protoreflect" @@ -21,28 +21,29 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -type Request struct { +// Define the NetworkDataRequest message +type NetworkDataRequest struct { state protoimpl.MessageState `protogen:"open.v1"` - Command string `protobuf:"bytes,1,opt,name=command,proto3" json:"command,omitempty"` + NetworkData string `protobuf:"bytes,1,opt,name=network_data,json=networkData,proto3" json:"network_data,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } -func (x *Request) Reset() { - *x = Request{} - mi := &file_netmap_proto_msgTypes[0] +func (x *NetworkDataRequest) Reset() { + *x = NetworkDataRequest{} + mi := &file_proto_netmap_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *Request) String() string { +func (x *NetworkDataRequest) String() string { return protoimpl.X.MessageStringOf(x) } -func (*Request) ProtoMessage() {} +func (*NetworkDataRequest) ProtoMessage() {} -func (x *Request) ProtoReflect() protoreflect.Message { - mi := &file_netmap_proto_msgTypes[0] +func (x *NetworkDataRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_netmap_proto_msgTypes[0] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -53,40 +54,41 @@ func (x *Request) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use Request.ProtoReflect.Descriptor instead. -func (*Request) Descriptor() ([]byte, []int) { - return file_netmap_proto_rawDescGZIP(), []int{0} +// Deprecated: Use NetworkDataRequest.ProtoReflect.Descriptor instead. +func (*NetworkDataRequest) Descriptor() ([]byte, []int) { + return file_proto_netmap_proto_rawDescGZIP(), []int{0} } -func (x *Request) GetCommand() string { +func (x *NetworkDataRequest) GetNetworkData() string { if x != nil { - return x.Command + return x.NetworkData } return "" } -type Response struct { +// Define the NetworkDataResponse message +type NetworkDataResponse struct { state protoimpl.MessageState `protogen:"open.v1"` - JsonData string `protobuf:"bytes,1,opt,name=json_data,json=jsonData,proto3" json:"json_data,omitempty"` // Optimized network state update in JSON format + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } -func (x *Response) Reset() { - *x = Response{} - mi := &file_netmap_proto_msgTypes[1] +func (x *NetworkDataResponse) Reset() { + *x = NetworkDataResponse{} + mi := &file_proto_netmap_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *Response) String() string { +func (x *NetworkDataResponse) String() string { return protoimpl.X.MessageStringOf(x) } -func (*Response) ProtoMessage() {} +func (*NetworkDataResponse) ProtoMessage() {} -func (x *Response) ProtoReflect() protoreflect.Message { - mi := &file_netmap_proto_msgTypes[1] +func (x *NetworkDataResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_netmap_proto_msgTypes[1] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -97,89 +99,86 @@ func (x *Response) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use Response.ProtoReflect.Descriptor instead. -func (*Response) Descriptor() ([]byte, []int) { - return file_netmap_proto_rawDescGZIP(), []int{1} +// Deprecated: Use NetworkDataResponse.ProtoReflect.Descriptor instead. +func (*NetworkDataResponse) Descriptor() ([]byte, []int) { + return file_proto_netmap_proto_rawDescGZIP(), []int{1} } -func (x *Response) GetJsonData() string { +func (x *NetworkDataResponse) GetMessage() string { if x != nil { - return x.JsonData + return x.Message } return "" } -var File_netmap_proto protoreflect.FileDescriptor - -var file_netmap_proto_rawDesc = string([]byte{ - 0x0a, 0x0c, 0x6e, 0x65, 0x74, 0x6d, 0x61, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, - 0x6e, 0x65, 0x74, 0x6d, 0x61, 0x70, 0x22, 0x23, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x22, 0x27, 0x0a, 0x08, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x6a, 0x73, 0x6f, 0x6e, 0x5f, - 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6a, 0x73, 0x6f, 0x6e, - 0x44, 0x61, 0x74, 0x61, 0x32, 0x72, 0x0a, 0x06, 0x4e, 0x65, 0x74, 0x4d, 0x61, 0x70, 0x12, 0x2d, - 0x0a, 0x08, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x0f, 0x2e, 0x6e, 0x65, 0x74, - 0x6d, 0x61, 0x70, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x6e, 0x65, - 0x74, 0x6d, 0x61, 0x70, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x39, 0x0a, - 0x10, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, - 0x73, 0x12, 0x0f, 0x2e, 0x6e, 0x65, 0x74, 0x6d, 0x61, 0x70, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x6e, 0x65, 0x74, 0x6d, 0x61, 0x70, 0x2e, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x28, 0x01, 0x30, 0x01, 0x42, 0x22, 0x5a, 0x20, 0x67, 0x69, 0x74, 0x68, - 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x69, 0x74, 0x7a, 0x6d, 0x61, 0x61, 0x2f, 0x6e, - 0x65, 0x74, 0x6d, 0x61, 0x70, 0x3b, 0x6e, 0x65, 0x74, 0x6d, 0x61, 0x70, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, +var File_proto_netmap_proto protoreflect.FileDescriptor + +var file_proto_netmap_proto_rawDesc = string([]byte{ + 0x0a, 0x12, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6e, 0x65, 0x74, 0x6d, 0x61, 0x70, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x6e, 0x65, 0x74, 0x6d, 0x61, 0x70, 0x22, 0x37, 0x0a, 0x12, + 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x21, 0x0a, 0x0c, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x5f, 0x64, 0x61, + 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, + 0x6b, 0x44, 0x61, 0x74, 0x61, 0x22, 0x2f, 0x0a, 0x13, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, + 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, + 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x54, 0x0a, 0x06, 0x4e, 0x65, 0x74, 0x4d, 0x61, 0x70, + 0x12, 0x4a, 0x0a, 0x0f, 0x53, 0x65, 0x6e, 0x64, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x44, + 0x61, 0x74, 0x61, 0x12, 0x1a, 0x2e, 0x6e, 0x65, 0x74, 0x6d, 0x61, 0x70, 0x2e, 0x4e, 0x65, 0x74, + 0x77, 0x6f, 0x72, 0x6b, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x1b, 0x2e, 0x6e, 0x65, 0x74, 0x6d, 0x61, 0x70, 0x2e, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, + 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x0f, 0x5a, 0x0d, + 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, }) var ( - file_netmap_proto_rawDescOnce sync.Once - file_netmap_proto_rawDescData []byte + file_proto_netmap_proto_rawDescOnce sync.Once + file_proto_netmap_proto_rawDescData []byte ) -func file_netmap_proto_rawDescGZIP() []byte { - file_netmap_proto_rawDescOnce.Do(func() { - file_netmap_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_netmap_proto_rawDesc), len(file_netmap_proto_rawDesc))) +func file_proto_netmap_proto_rawDescGZIP() []byte { + file_proto_netmap_proto_rawDescOnce.Do(func() { + file_proto_netmap_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_proto_netmap_proto_rawDesc), len(file_proto_netmap_proto_rawDesc))) }) - return file_netmap_proto_rawDescData + return file_proto_netmap_proto_rawDescData } -var file_netmap_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_netmap_proto_goTypes = []any{ - (*Request)(nil), // 0: netmap.Request - (*Response)(nil), // 1: netmap.Response +var file_proto_netmap_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_proto_netmap_proto_goTypes = []any{ + (*NetworkDataRequest)(nil), // 0: netmap.NetworkDataRequest + (*NetworkDataResponse)(nil), // 1: netmap.NetworkDataResponse } -var file_netmap_proto_depIdxs = []int32{ - 0, // 0: netmap.NetMap.GetState:input_type -> netmap.Request - 0, // 1: netmap.NetMap.SubscribeUpdates:input_type -> netmap.Request - 1, // 2: netmap.NetMap.GetState:output_type -> netmap.Response - 1, // 3: netmap.NetMap.SubscribeUpdates:output_type -> netmap.Response - 2, // [2:4] is the sub-list for method output_type - 0, // [0:2] is the sub-list for method input_type +var file_proto_netmap_proto_depIdxs = []int32{ + 0, // 0: netmap.NetMap.SendNetworkData:input_type -> netmap.NetworkDataRequest + 1, // 1: netmap.NetMap.SendNetworkData:output_type -> netmap.NetworkDataResponse + 1, // [1:2] is the sub-list for method output_type + 0, // [0:1] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name } -func init() { file_netmap_proto_init() } -func file_netmap_proto_init() { - if File_netmap_proto != nil { +func init() { file_proto_netmap_proto_init() } +func file_proto_netmap_proto_init() { + if File_proto_netmap_proto != nil { return } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: unsafe.Slice(unsafe.StringData(file_netmap_proto_rawDesc), len(file_netmap_proto_rawDesc)), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_proto_netmap_proto_rawDesc), len(file_proto_netmap_proto_rawDesc)), NumEnums: 0, NumMessages: 2, NumExtensions: 0, NumServices: 1, }, - GoTypes: file_netmap_proto_goTypes, - DependencyIndexes: file_netmap_proto_depIdxs, - MessageInfos: file_netmap_proto_msgTypes, + GoTypes: file_proto_netmap_proto_goTypes, + DependencyIndexes: file_proto_netmap_proto_depIdxs, + MessageInfos: file_proto_netmap_proto_msgTypes, }.Build() - File_netmap_proto = out.File - file_netmap_proto_goTypes = nil - file_netmap_proto_depIdxs = nil + File_proto_netmap_proto = out.File + file_proto_netmap_proto_goTypes = nil + file_proto_netmap_proto_depIdxs = nil } diff --git a/frontend/go_server/proto/netmap.proto b/frontend/go_server/proto/netmap.proto new file mode 100644 index 0000000..d63238d --- /dev/null +++ b/frontend/go_server/proto/netmap.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; + +package netmap; + +// Add the Go import path for the generated code +option go_package = "./proto;proto"; // Adjust this path based on your folder structure + +// Define the NetworkDataRequest message +message NetworkDataRequest { + string network_data = 1; +} + +// Define the NetworkDataResponse message +message NetworkDataResponse { + string message = 1; +} + +// Define the service +service NetMap { + rpc SendNetworkData(NetworkDataRequest) returns (NetworkDataResponse); +} \ No newline at end of file diff --git a/frontend/go_server/proto/netmap_grpc.pb.go b/frontend/go_server/proto/netmap_grpc.pb.go index e4881d6..2ac2cd7 100644 --- a/frontend/go_server/proto/netmap_grpc.pb.go +++ b/frontend/go_server/proto/netmap_grpc.pb.go @@ -2,9 +2,9 @@ // versions: // - protoc-gen-go-grpc v1.5.1 // - protoc v5.29.3 -// source: netmap.proto +// source: proto/netmap.proto -package netmap +package proto import ( context "context" @@ -19,16 +19,16 @@ import ( const _ = grpc.SupportPackageIsVersion9 const ( - NetMap_GetState_FullMethodName = "/netmap.NetMap/GetState" - NetMap_SubscribeUpdates_FullMethodName = "/netmap.NetMap/SubscribeUpdates" + NetMap_SendNetworkData_FullMethodName = "/netmap.NetMap/SendNetworkData" ) // NetMapClient is the client API for NetMap service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +// +// Define the service type NetMapClient interface { - GetState(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) - SubscribeUpdates(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[Request, Response], error) + SendNetworkData(ctx context.Context, in *NetworkDataRequest, opts ...grpc.CallOption) (*NetworkDataResponse, error) } type netMapClient struct { @@ -39,35 +39,23 @@ func NewNetMapClient(cc grpc.ClientConnInterface) NetMapClient { return &netMapClient{cc} } -func (c *netMapClient) GetState(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) { +func (c *netMapClient) SendNetworkData(ctx context.Context, in *NetworkDataRequest, opts ...grpc.CallOption) (*NetworkDataResponse, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(Response) - err := c.cc.Invoke(ctx, NetMap_GetState_FullMethodName, in, out, cOpts...) + out := new(NetworkDataResponse) + err := c.cc.Invoke(ctx, NetMap_SendNetworkData_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } return out, nil } -func (c *netMapClient) SubscribeUpdates(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[Request, Response], error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - stream, err := c.cc.NewStream(ctx, &NetMap_ServiceDesc.Streams[0], NetMap_SubscribeUpdates_FullMethodName, cOpts...) - if err != nil { - return nil, err - } - x := &grpc.GenericClientStream[Request, Response]{ClientStream: stream} - return x, nil -} - -// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. -type NetMap_SubscribeUpdatesClient = grpc.BidiStreamingClient[Request, Response] - // NetMapServer is the server API for NetMap service. // All implementations must embed UnimplementedNetMapServer // for forward compatibility. +// +// Define the service type NetMapServer interface { - GetState(context.Context, *Request) (*Response, error) - SubscribeUpdates(grpc.BidiStreamingServer[Request, Response]) error + SendNetworkData(context.Context, *NetworkDataRequest) (*NetworkDataResponse, error) mustEmbedUnimplementedNetMapServer() } @@ -78,11 +66,8 @@ type NetMapServer interface { // pointer dereference when methods are called. type UnimplementedNetMapServer struct{} -func (UnimplementedNetMapServer) GetState(context.Context, *Request) (*Response, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetState not implemented") -} -func (UnimplementedNetMapServer) SubscribeUpdates(grpc.BidiStreamingServer[Request, Response]) error { - return status.Errorf(codes.Unimplemented, "method SubscribeUpdates not implemented") +func (UnimplementedNetMapServer) SendNetworkData(context.Context, *NetworkDataRequest) (*NetworkDataResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SendNetworkData not implemented") } func (UnimplementedNetMapServer) mustEmbedUnimplementedNetMapServer() {} func (UnimplementedNetMapServer) testEmbeddedByValue() {} @@ -105,31 +90,24 @@ func RegisterNetMapServer(s grpc.ServiceRegistrar, srv NetMapServer) { s.RegisterService(&NetMap_ServiceDesc, srv) } -func _NetMap_GetState_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(Request) +func _NetMap_SendNetworkData_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(NetworkDataRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(NetMapServer).GetState(ctx, in) + return srv.(NetMapServer).SendNetworkData(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: NetMap_GetState_FullMethodName, + FullMethod: NetMap_SendNetworkData_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(NetMapServer).GetState(ctx, req.(*Request)) + return srv.(NetMapServer).SendNetworkData(ctx, req.(*NetworkDataRequest)) } return interceptor(ctx, in, info, handler) } -func _NetMap_SubscribeUpdates_Handler(srv interface{}, stream grpc.ServerStream) error { - return srv.(NetMapServer).SubscribeUpdates(&grpc.GenericServerStream[Request, Response]{ServerStream: stream}) -} - -// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. -type NetMap_SubscribeUpdatesServer = grpc.BidiStreamingServer[Request, Response] - // NetMap_ServiceDesc is the grpc.ServiceDesc for NetMap service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -138,17 +116,10 @@ var NetMap_ServiceDesc = grpc.ServiceDesc{ HandlerType: (*NetMapServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "GetState", - Handler: _NetMap_GetState_Handler, - }, - }, - Streams: []grpc.StreamDesc{ - { - StreamName: "SubscribeUpdates", - Handler: _NetMap_SubscribeUpdates_Handler, - ServerStreams: true, - ClientStreams: true, + MethodName: "SendNetworkData", + Handler: _NetMap_SendNetworkData_Handler, }, }, - Metadata: "netmap.proto", + Streams: []grpc.StreamDesc{}, + Metadata: "proto/netmap.proto", } diff --git a/frontend/gui/grpc_client.py b/frontend/gui/grpc_client.py index 2090831..39d11ec 100644 --- a/frontend/gui/grpc_client.py +++ b/frontend/gui/grpc_client.py @@ -1,10 +1,13 @@ import grpc +import sys +import os +sys.path.append(os.path.join(os.path.dirname(__file__), 'proto')) import proto.netmap_pb2 import proto.netmap_pb2_grpc class NetworkClient: def __init__(self, channel): - self.client = proto.netmap_pb2_grpc.NetworkServiceStub(channel) + self.client = proto.netmap_pb2_grpc.NetMapStub(channel) def send_network_data(self, network_data): request = proto.netmap_pb2.NetworkDataRequest(network_data=network_data) diff --git a/frontend/__init__.py b/frontend/gui/proto/__init__.py similarity index 100% rename from frontend/__init__.py rename to frontend/gui/proto/__init__.py diff --git a/frontend/gui/proto/netmap.proto b/frontend/gui/proto/netmap.proto new file mode 100644 index 0000000..d63238d --- /dev/null +++ b/frontend/gui/proto/netmap.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; + +package netmap; + +// Add the Go import path for the generated code +option go_package = "./proto;proto"; // Adjust this path based on your folder structure + +// Define the NetworkDataRequest message +message NetworkDataRequest { + string network_data = 1; +} + +// Define the NetworkDataResponse message +message NetworkDataResponse { + string message = 1; +} + +// Define the service +service NetMap { + rpc SendNetworkData(NetworkDataRequest) returns (NetworkDataResponse); +} \ No newline at end of file diff --git a/frontend/gui/proto/netmap_pb2.py b/frontend/gui/proto/netmap_pb2.py index b85308e..9da94dc 100644 --- a/frontend/gui/proto/netmap_pb2.py +++ b/frontend/gui/proto/netmap_pb2.py @@ -24,18 +24,18 @@ -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0cnetmap.proto\x12\x06netmap\"\x1a\n\x07Request\x12\x0f\n\x07\x63ommand\x18\x01 \x01(\t\"\x1d\n\x08Response\x12\x11\n\tjson_data\x18\x01 \x01(\t2r\n\x06NetMap\x12-\n\x08GetState\x12\x0f.netmap.Request\x1a\x10.netmap.Response\x12\x39\n\x10SubscribeUpdates\x12\x0f.netmap.Request\x1a\x10.netmap.Response(\x01\x30\x01\x42\"Z github.com/sitzmaa/netmap;netmapb\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0cnetmap.proto\x12\x06netmap\"*\n\x12NetworkDataRequest\x12\x14\n\x0cnetwork_data\x18\x01 \x01(\t\"&\n\x13NetworkDataResponse\x12\x0f\n\x07message\x18\x01 \x01(\t2T\n\x06NetMap\x12J\n\x0fSendNetworkData\x12\x1a.netmap.NetworkDataRequest\x1a\x1b.netmap.NetworkDataResponseB\x0fZ\r./proto;protob\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'netmap_pb2', _globals) if not _descriptor._USE_C_DESCRIPTORS: _globals['DESCRIPTOR']._loaded_options = None - _globals['DESCRIPTOR']._serialized_options = b'Z github.com/sitzmaa/netmap;netmap' - _globals['_REQUEST']._serialized_start=24 - _globals['_REQUEST']._serialized_end=50 - _globals['_RESPONSE']._serialized_start=52 - _globals['_RESPONSE']._serialized_end=81 - _globals['_NETMAP']._serialized_start=83 - _globals['_NETMAP']._serialized_end=197 + _globals['DESCRIPTOR']._serialized_options = b'Z\r./proto;proto' + _globals['_NETWORKDATAREQUEST']._serialized_start=24 + _globals['_NETWORKDATAREQUEST']._serialized_end=66 + _globals['_NETWORKDATARESPONSE']._serialized_start=68 + _globals['_NETWORKDATARESPONSE']._serialized_end=106 + _globals['_NETMAP']._serialized_start=108 + _globals['_NETMAP']._serialized_end=192 # @@protoc_insertion_point(module_scope) diff --git a/frontend/gui/proto/netmap_pb2_grpc.py b/frontend/gui/proto/netmap_pb2_grpc.py index 9842047..7937ca4 100644 --- a/frontend/gui/proto/netmap_pb2_grpc.py +++ b/frontend/gui/proto/netmap_pb2_grpc.py @@ -26,7 +26,8 @@ class NetMapStub(object): - """Missing associated documentation comment in .proto file.""" + """Define the service + """ def __init__(self, channel): """Constructor. @@ -34,28 +35,18 @@ def __init__(self, channel): Args: channel: A grpc.Channel. """ - self.GetState = channel.unary_unary( - '/netmap.NetMap/GetState', - request_serializer=netmap__pb2.Request.SerializeToString, - response_deserializer=netmap__pb2.Response.FromString, - _registered_method=True) - self.SubscribeUpdates = channel.stream_stream( - '/netmap.NetMap/SubscribeUpdates', - request_serializer=netmap__pb2.Request.SerializeToString, - response_deserializer=netmap__pb2.Response.FromString, + self.SendNetworkData = channel.unary_unary( + '/netmap.NetMap/SendNetworkData', + request_serializer=netmap__pb2.NetworkDataRequest.SerializeToString, + response_deserializer=netmap__pb2.NetworkDataResponse.FromString, _registered_method=True) class NetMapServicer(object): - """Missing associated documentation comment in .proto file.""" + """Define the service + """ - def GetState(self, request, context): - """Missing associated documentation comment in .proto file.""" - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def SubscribeUpdates(self, request_iterator, context): + def SendNetworkData(self, request, context): """Missing associated documentation comment in .proto file.""" context.set_code(grpc.StatusCode.UNIMPLEMENTED) context.set_details('Method not implemented!') @@ -64,15 +55,10 @@ def SubscribeUpdates(self, request_iterator, context): def add_NetMapServicer_to_server(servicer, server): rpc_method_handlers = { - 'GetState': grpc.unary_unary_rpc_method_handler( - servicer.GetState, - request_deserializer=netmap__pb2.Request.FromString, - response_serializer=netmap__pb2.Response.SerializeToString, - ), - 'SubscribeUpdates': grpc.stream_stream_rpc_method_handler( - servicer.SubscribeUpdates, - request_deserializer=netmap__pb2.Request.FromString, - response_serializer=netmap__pb2.Response.SerializeToString, + 'SendNetworkData': grpc.unary_unary_rpc_method_handler( + servicer.SendNetworkData, + request_deserializer=netmap__pb2.NetworkDataRequest.FromString, + response_serializer=netmap__pb2.NetworkDataResponse.SerializeToString, ), } generic_handler = grpc.method_handlers_generic_handler( @@ -83,10 +69,11 @@ def add_NetMapServicer_to_server(servicer, server): # This class is part of an EXPERIMENTAL API. class NetMap(object): - """Missing associated documentation comment in .proto file.""" + """Define the service + """ @staticmethod - def GetState(request, + def SendNetworkData(request, target, options=(), channel_credentials=None, @@ -99,36 +86,9 @@ def GetState(request, return grpc.experimental.unary_unary( request, target, - '/netmap.NetMap/GetState', - netmap__pb2.Request.SerializeToString, - netmap__pb2.Response.FromString, - options, - channel_credentials, - insecure, - call_credentials, - compression, - wait_for_ready, - timeout, - metadata, - _registered_method=True) - - @staticmethod - def SubscribeUpdates(request_iterator, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.stream_stream( - request_iterator, - target, - '/netmap.NetMap/SubscribeUpdates', - netmap__pb2.Request.SerializeToString, - netmap__pb2.Response.FromString, + '/netmap.NetMap/SendNetworkData', + netmap__pb2.NetworkDataRequest.SerializeToString, + netmap__pb2.NetworkDataResponse.FromString, options, channel_credentials, insecure, diff --git a/frontend/proto/netmap.proto b/frontend/proto/netmap.proto deleted file mode 100644 index 342c625..0000000 --- a/frontend/proto/netmap.proto +++ /dev/null @@ -1,16 +0,0 @@ -syntax = "proto3"; -option go_package = "netmap;netmap"; -package netmap; - -service NetMap { - rpc GetState (Request) returns (Response); - rpc SubscribeUpdates (stream Request) returns (stream Response); -} - -message Request { - string command = 1; -} - -message Response { - string json_data = 1; // Optimized network state update in JSON format -} \ No newline at end of file