From 22309e99c249be8fbb30660452133eaf7b21e73f Mon Sep 17 00:00:00 2001 From: Aleksander Ogurtsov Date: Wed, 4 Mar 2026 04:19:48 +0300 Subject: [PATCH] Add UnregisterClient RPC method --- proto/agent.pb.go | 147 +++++++++++++++++++++++++++++++++++------ proto/agent.proto | 10 +++ proto/agent_grpc.pb.go | 40 ++++++++++- 3 files changed, 176 insertions(+), 21 deletions(-) diff --git a/proto/agent.pb.go b/proto/agent.pb.go index ddbd633..815a8d9 100644 --- a/proto/agent.pb.go +++ b/proto/agent.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.36.11 -// protoc v3.21.12 +// protoc v7.34.0 // source: proto/agent.proto package proto @@ -313,6 +313,102 @@ func (x *RegisterClientResponse) GetClient() *ClientConfig { return nil } +type UnregisterClientRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + PublicKey string `protobuf:"bytes,1,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *UnregisterClientRequest) Reset() { + *x = UnregisterClientRequest{} + mi := &file_proto_agent_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *UnregisterClientRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UnregisterClientRequest) ProtoMessage() {} + +func (x *UnregisterClientRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_agent_proto_msgTypes[5] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UnregisterClientRequest.ProtoReflect.Descriptor instead. +func (*UnregisterClientRequest) Descriptor() ([]byte, []int) { + return file_proto_agent_proto_rawDescGZIP(), []int{5} +} + +func (x *UnregisterClientRequest) GetPublicKey() string { + if x != nil { + return x.PublicKey + } + return "" +} + +type UnregisterClientResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Success bool `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"` + Error string `protobuf:"bytes,2,opt,name=error,proto3" json:"error,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *UnregisterClientResponse) Reset() { + *x = UnregisterClientResponse{} + mi := &file_proto_agent_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *UnregisterClientResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UnregisterClientResponse) ProtoMessage() {} + +func (x *UnregisterClientResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_agent_proto_msgTypes[6] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UnregisterClientResponse.ProtoReflect.Descriptor instead. +func (*UnregisterClientResponse) Descriptor() ([]byte, []int) { + return file_proto_agent_proto_rawDescGZIP(), []int{6} +} + +func (x *UnregisterClientResponse) GetSuccess() bool { + if x != nil { + return x.Success + } + return false +} + +func (x *UnregisterClientResponse) GetError() string { + if x != nil { + return x.Error + } + return "" +} + type GetServerStatusRequest struct { state protoimpl.MessageState `protogen:"open.v1"` unknownFields protoimpl.UnknownFields @@ -321,7 +417,7 @@ type GetServerStatusRequest struct { func (x *GetServerStatusRequest) Reset() { *x = GetServerStatusRequest{} - mi := &file_proto_agent_proto_msgTypes[5] + mi := &file_proto_agent_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -333,7 +429,7 @@ func (x *GetServerStatusRequest) String() string { func (*GetServerStatusRequest) ProtoMessage() {} func (x *GetServerStatusRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_agent_proto_msgTypes[5] + mi := &file_proto_agent_proto_msgTypes[7] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -346,7 +442,7 @@ func (x *GetServerStatusRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GetServerStatusRequest.ProtoReflect.Descriptor instead. func (*GetServerStatusRequest) Descriptor() ([]byte, []int) { - return file_proto_agent_proto_rawDescGZIP(), []int{5} + return file_proto_agent_proto_rawDescGZIP(), []int{7} } type GetServerStatusResponse struct { @@ -363,7 +459,7 @@ type GetServerStatusResponse struct { func (x *GetServerStatusResponse) Reset() { *x = GetServerStatusResponse{} - mi := &file_proto_agent_proto_msgTypes[6] + mi := &file_proto_agent_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -375,7 +471,7 @@ func (x *GetServerStatusResponse) String() string { func (*GetServerStatusResponse) ProtoMessage() {} func (x *GetServerStatusResponse) ProtoReflect() protoreflect.Message { - mi := &file_proto_agent_proto_msgTypes[6] + mi := &file_proto_agent_proto_msgTypes[8] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -388,7 +484,7 @@ func (x *GetServerStatusResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use GetServerStatusResponse.ProtoReflect.Descriptor instead. func (*GetServerStatusResponse) Descriptor() ([]byte, []int) { - return file_proto_agent_proto_rawDescGZIP(), []int{6} + return file_proto_agent_proto_rawDescGZIP(), []int{8} } func (x *GetServerStatusResponse) GetSuccess() bool { @@ -461,7 +557,13 @@ const file_proto_agent_proto_rawDesc = "" + "\x16RegisterClientResponse\x12\x18\n" + "\asuccess\x18\x01 \x01(\bR\asuccess\x12\x14\n" + "\x05error\x18\x02 \x01(\tR\x05error\x12+\n" + - "\x06client\x18\x03 \x01(\v2\x13.agent.ClientConfigR\x06client\"\x18\n" + + "\x06client\x18\x03 \x01(\v2\x13.agent.ClientConfigR\x06client\"8\n" + + "\x17UnregisterClientRequest\x12\x1d\n" + + "\n" + + "public_key\x18\x01 \x01(\tR\tpublicKey\"J\n" + + "\x18UnregisterClientResponse\x12\x18\n" + + "\asuccess\x18\x01 \x01(\bR\asuccess\x12\x14\n" + + "\x05error\x18\x02 \x01(\tR\x05error\"\x18\n" + "\x16GetServerStatusRequest\"\xd7\x01\n" + "\x17GetServerStatusResponse\x12\x18\n" + "\asuccess\x18\x01 \x01(\bR\asuccess\x12\x14\n" + @@ -471,10 +573,11 @@ const file_proto_agent_proto_rawDesc = "" + "public_key\x18\x04 \x01(\tR\tpublicKey\x12%\n" + "\x0elistening_port\x18\x05 \x01(\tR\rlisteningPort\x12\x1f\n" + "\vpeers_count\x18\x06 \x01(\x05R\n" + - "peersCount2\x86\x02\n" + + "peersCount2\xdb\x02\n" + "\x0eWireGuardAgent\x12S\n" + "\x10GetClientConfigs\x12\x1e.agent.GetClientConfigsRequest\x1a\x1f.agent.GetClientConfigsResponse\x12M\n" + - "\x0eRegisterClient\x12\x1c.agent.RegisterClientRequest\x1a\x1d.agent.RegisterClientResponse\x12P\n" + + "\x0eRegisterClient\x12\x1c.agent.RegisterClientRequest\x1a\x1d.agent.RegisterClientResponse\x12S\n" + + "\x10UnregisterClient\x12\x1e.agent.UnregisterClientRequest\x1a\x1f.agent.UnregisterClientResponse\x12P\n" + "\x0fGetServerStatus\x12\x1d.agent.GetServerStatusRequest\x1a\x1e.agent.GetServerStatusResponseB\x13Z\x11l_vpn_proto/protob\x06proto3" var ( @@ -489,27 +592,31 @@ func file_proto_agent_proto_rawDescGZIP() []byte { return file_proto_agent_proto_rawDescData } -var file_proto_agent_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_proto_agent_proto_msgTypes = make([]protoimpl.MessageInfo, 9) var file_proto_agent_proto_goTypes = []any{ (*GetClientConfigsRequest)(nil), // 0: agent.GetClientConfigsRequest (*ClientConfig)(nil), // 1: agent.ClientConfig (*GetClientConfigsResponse)(nil), // 2: agent.GetClientConfigsResponse (*RegisterClientRequest)(nil), // 3: agent.RegisterClientRequest (*RegisterClientResponse)(nil), // 4: agent.RegisterClientResponse - (*GetServerStatusRequest)(nil), // 5: agent.GetServerStatusRequest - (*GetServerStatusResponse)(nil), // 6: agent.GetServerStatusResponse + (*UnregisterClientRequest)(nil), // 5: agent.UnregisterClientRequest + (*UnregisterClientResponse)(nil), // 6: agent.UnregisterClientResponse + (*GetServerStatusRequest)(nil), // 7: agent.GetServerStatusRequest + (*GetServerStatusResponse)(nil), // 8: agent.GetServerStatusResponse } var file_proto_agent_proto_depIdxs = []int32{ 1, // 0: agent.GetClientConfigsResponse.clients:type_name -> agent.ClientConfig 1, // 1: agent.RegisterClientResponse.client:type_name -> agent.ClientConfig 0, // 2: agent.WireGuardAgent.GetClientConfigs:input_type -> agent.GetClientConfigsRequest 3, // 3: agent.WireGuardAgent.RegisterClient:input_type -> agent.RegisterClientRequest - 5, // 4: agent.WireGuardAgent.GetServerStatus:input_type -> agent.GetServerStatusRequest - 2, // 5: agent.WireGuardAgent.GetClientConfigs:output_type -> agent.GetClientConfigsResponse - 4, // 6: agent.WireGuardAgent.RegisterClient:output_type -> agent.RegisterClientResponse - 6, // 7: agent.WireGuardAgent.GetServerStatus:output_type -> agent.GetServerStatusResponse - 5, // [5:8] is the sub-list for method output_type - 2, // [2:5] is the sub-list for method input_type + 5, // 4: agent.WireGuardAgent.UnregisterClient:input_type -> agent.UnregisterClientRequest + 7, // 5: agent.WireGuardAgent.GetServerStatus:input_type -> agent.GetServerStatusRequest + 2, // 6: agent.WireGuardAgent.GetClientConfigs:output_type -> agent.GetClientConfigsResponse + 4, // 7: agent.WireGuardAgent.RegisterClient:output_type -> agent.RegisterClientResponse + 6, // 8: agent.WireGuardAgent.UnregisterClient:output_type -> agent.UnregisterClientResponse + 8, // 9: agent.WireGuardAgent.GetServerStatus:output_type -> agent.GetServerStatusResponse + 6, // [6:10] is the sub-list for method output_type + 2, // [2:6] is the sub-list for method input_type 2, // [2:2] is the sub-list for extension type_name 2, // [2:2] is the sub-list for extension extendee 0, // [0:2] is the sub-list for field type_name @@ -526,7 +633,7 @@ func file_proto_agent_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_proto_agent_proto_rawDesc), len(file_proto_agent_proto_rawDesc)), NumEnums: 0, - NumMessages: 7, + NumMessages: 9, NumExtensions: 0, NumServices: 1, }, diff --git a/proto/agent.proto b/proto/agent.proto index 2a767ee..8a7c09b 100644 --- a/proto/agent.proto +++ b/proto/agent.proto @@ -7,6 +7,7 @@ option go_package = "l_vpn_proto/proto"; service WireGuardAgent { rpc GetClientConfigs(GetClientConfigsRequest) returns (GetClientConfigsResponse); rpc RegisterClient(RegisterClientRequest) returns (RegisterClientResponse); + rpc UnregisterClient(UnregisterClientRequest) returns (UnregisterClientResponse); rpc GetServerStatus(GetServerStatusRequest) returns (GetServerStatusResponse); } @@ -38,6 +39,15 @@ message RegisterClientResponse { ClientConfig client = 3; } +message UnregisterClientRequest { + string public_key = 1; +} + +message UnregisterClientResponse { + bool success = 1; + string error = 2; +} + message GetServerStatusRequest {} message GetServerStatusResponse { diff --git a/proto/agent_grpc.pb.go b/proto/agent_grpc.pb.go index b487eef..1999e4f 100644 --- a/proto/agent_grpc.pb.go +++ b/proto/agent_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.6.1 -// - protoc v3.21.12 +// - protoc v7.34.0 // source: proto/agent.proto package proto @@ -21,6 +21,7 @@ const _ = grpc.SupportPackageIsVersion9 const ( WireGuardAgent_GetClientConfigs_FullMethodName = "/agent.WireGuardAgent/GetClientConfigs" WireGuardAgent_RegisterClient_FullMethodName = "/agent.WireGuardAgent/RegisterClient" + WireGuardAgent_UnregisterClient_FullMethodName = "/agent.WireGuardAgent/UnregisterClient" WireGuardAgent_GetServerStatus_FullMethodName = "/agent.WireGuardAgent/GetServerStatus" ) @@ -30,6 +31,7 @@ const ( type WireGuardAgentClient interface { GetClientConfigs(ctx context.Context, in *GetClientConfigsRequest, opts ...grpc.CallOption) (*GetClientConfigsResponse, error) RegisterClient(ctx context.Context, in *RegisterClientRequest, opts ...grpc.CallOption) (*RegisterClientResponse, error) + UnregisterClient(ctx context.Context, in *UnregisterClientRequest, opts ...grpc.CallOption) (*UnregisterClientResponse, error) GetServerStatus(ctx context.Context, in *GetServerStatusRequest, opts ...grpc.CallOption) (*GetServerStatusResponse, error) } @@ -61,6 +63,16 @@ func (c *wireGuardAgentClient) RegisterClient(ctx context.Context, in *RegisterC return out, nil } +func (c *wireGuardAgentClient) UnregisterClient(ctx context.Context, in *UnregisterClientRequest, opts ...grpc.CallOption) (*UnregisterClientResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(UnregisterClientResponse) + err := c.cc.Invoke(ctx, WireGuardAgent_UnregisterClient_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *wireGuardAgentClient) GetServerStatus(ctx context.Context, in *GetServerStatusRequest, opts ...grpc.CallOption) (*GetServerStatusResponse, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(GetServerStatusResponse) @@ -77,6 +89,7 @@ func (c *wireGuardAgentClient) GetServerStatus(ctx context.Context, in *GetServe type WireGuardAgentServer interface { GetClientConfigs(context.Context, *GetClientConfigsRequest) (*GetClientConfigsResponse, error) RegisterClient(context.Context, *RegisterClientRequest) (*RegisterClientResponse, error) + UnregisterClient(context.Context, *UnregisterClientRequest) (*UnregisterClientResponse, error) GetServerStatus(context.Context, *GetServerStatusRequest) (*GetServerStatusResponse, error) mustEmbedUnimplementedWireGuardAgentServer() } @@ -94,6 +107,9 @@ func (UnimplementedWireGuardAgentServer) GetClientConfigs(context.Context, *GetC func (UnimplementedWireGuardAgentServer) RegisterClient(context.Context, *RegisterClientRequest) (*RegisterClientResponse, error) { return nil, status.Error(codes.Unimplemented, "method RegisterClient not implemented") } +func (UnimplementedWireGuardAgentServer) UnregisterClient(context.Context, *UnregisterClientRequest) (*UnregisterClientResponse, error) { + return nil, status.Error(codes.Unimplemented, "method UnregisterClient not implemented") +} func (UnimplementedWireGuardAgentServer) GetServerStatus(context.Context, *GetServerStatusRequest) (*GetServerStatusResponse, error) { return nil, status.Error(codes.Unimplemented, "method GetServerStatus not implemented") } @@ -154,6 +170,24 @@ func _WireGuardAgent_RegisterClient_Handler(srv interface{}, ctx context.Context return interceptor(ctx, in, info, handler) } +func _WireGuardAgent_UnregisterClient_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UnregisterClientRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WireGuardAgentServer).UnregisterClient(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: WireGuardAgent_UnregisterClient_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WireGuardAgentServer).UnregisterClient(ctx, req.(*UnregisterClientRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _WireGuardAgent_GetServerStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(GetServerStatusRequest) if err := dec(in); err != nil { @@ -187,6 +221,10 @@ var WireGuardAgent_ServiceDesc = grpc.ServiceDesc{ MethodName: "RegisterClient", Handler: _WireGuardAgent_RegisterClient_Handler, }, + { + MethodName: "UnregisterClient", + Handler: _WireGuardAgent_UnregisterClient_Handler, + }, { MethodName: "GetServerStatus", Handler: _WireGuardAgent_GetServerStatus_Handler,