From a7d425bbda25c2a73cc98d40ecec024d69f0b17a Mon Sep 17 00:00:00 2001 From: Grzegorz Baranski Date: Thu, 16 Jan 2025 12:52:53 +0100 Subject: [PATCH] feat: notifying about actual ip update through protobuf --- daemon/job_actual_ip.go | 7 ++++++- daemon/pb/state.pb.go | 16 ++++++++++------ daemon/state/state.go | 10 ++++++++++ protobuf/daemon/state.proto | 2 +- test/qa/lib/protobuf/daemon/state_pb2.py | 4 ++-- test/qa/lib/protobuf/daemon/state_pb2.pyi | 2 ++ 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/daemon/job_actual_ip.go b/daemon/job_actual_ip.go index c6c3f0a9..a7774111 100644 --- a/daemon/job_actual_ip.go +++ b/daemon/job_actual_ip.go @@ -92,7 +92,12 @@ func updateActualIP(dm *DataManager, api core.InsightsAPI, ctx context.Context, func JobActualIP(statePublisher *state.StatePublisher, dm *DataManager, api core.InsightsAPI) { call := func(ctx context.Context, isConnected bool) { err := updateActualIP(dm, api, ctx, isConnected) - if err != nil { + if err == nil { + err := statePublisher.NotifyActualIPUpdate() + if err != nil { + log.Println(internal.ErrorPrefix, "notify about actual ip update failed: ", err) + } + } else { if err == context.Canceled { return } diff --git a/daemon/pb/state.pb.go b/daemon/pb/state.pb.go index 58922bf8..e65f551f 100644 --- a/daemon/pb/state.pb.go +++ b/daemon/pb/state.pb.go @@ -162,15 +162,18 @@ type UpdateEvent int32 const ( UpdateEvent_SERVERS_LIST_UPDATE UpdateEvent = 0 + UpdateEvent_ACTUAL_IP_UPDATE UpdateEvent = 1 ) // Enum value maps for UpdateEvent. var ( UpdateEvent_name = map[int32]string{ 0: "SERVERS_LIST_UPDATE", + 1: "ACTUAL_IP_UPDATE", } UpdateEvent_value = map[string]int32{ "SERVERS_LIST_UPDATE": 0, + "ACTUAL_IP_UPDATE": 1, } ) @@ -591,13 +594,14 @@ var file_state_proto_rawDesc = []byte{ 0x0a, 0x09, 0x43, 0x4f, 0x4e, 0x4e, 0x45, 0x43, 0x54, 0x45, 0x44, 0x10, 0x02, 0x2a, 0x27, 0x0a, 0x0e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x09, 0x0a, 0x05, 0x4c, 0x4f, 0x47, 0x49, 0x4e, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x4c, 0x4f, - 0x47, 0x4f, 0x55, 0x54, 0x10, 0x01, 0x2a, 0x26, 0x0a, 0x0b, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x47, 0x4f, 0x55, 0x54, 0x10, 0x01, 0x2a, 0x3c, 0x0a, 0x0b, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x17, 0x0a, 0x13, 0x53, 0x45, 0x52, 0x56, 0x45, 0x52, 0x53, - 0x5f, 0x4c, 0x49, 0x53, 0x54, 0x5f, 0x55, 0x50, 0x44, 0x41, 0x54, 0x45, 0x10, 0x00, 0x42, 0x31, - 0x5a, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x4e, 0x6f, 0x72, - 0x64, 0x53, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x2f, 0x6e, 0x6f, 0x72, 0x64, 0x76, 0x70, - 0x6e, 0x2d, 0x6c, 0x69, 0x6e, 0x75, 0x78, 0x2f, 0x64, 0x61, 0x65, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, - 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x5f, 0x4c, 0x49, 0x53, 0x54, 0x5f, 0x55, 0x50, 0x44, 0x41, 0x54, 0x45, 0x10, 0x00, 0x12, 0x14, + 0x0a, 0x10, 0x41, 0x43, 0x54, 0x55, 0x41, 0x4c, 0x5f, 0x49, 0x50, 0x5f, 0x55, 0x50, 0x44, 0x41, + 0x54, 0x45, 0x10, 0x01, 0x42, 0x31, 0x5a, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, + 0x6f, 0x6d, 0x2f, 0x4e, 0x6f, 0x72, 0x64, 0x53, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x2f, + 0x6e, 0x6f, 0x72, 0x64, 0x76, 0x70, 0x6e, 0x2d, 0x6c, 0x69, 0x6e, 0x75, 0x78, 0x2f, 0x64, 0x61, + 0x65, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/daemon/state/state.go b/daemon/state/state.go index c6281715..3a537aa9 100644 --- a/daemon/state/state.go +++ b/daemon/state/state.go @@ -117,6 +117,16 @@ func (s *StatePublisher) NotifyServersListUpdate(any) error { return nil } +func (s *StatePublisher) NotifyActualIPUpdate() error { + s.mu.Lock() + defer s.mu.Unlock() + + log.Println(internal.DebugPrefix, "notifying actual ip update") + s.notify(pb.UpdateEvent_ACTUAL_IP_UPDATE) + + return nil +} + func (s *StatePublisher) NotifySubscriptionChanged(e *pb.AccountModification) error { s.mu.Lock() defer s.mu.Unlock() diff --git a/protobuf/daemon/state.proto b/protobuf/daemon/state.proto index 6a4a1838..a54a66da 100644 --- a/protobuf/daemon/state.proto +++ b/protobuf/daemon/state.proto @@ -38,6 +38,7 @@ enum LoginEventType { enum UpdateEvent { SERVERS_LIST_UPDATE = 0; + ACTUAL_IP_UPDATE = 1; } message AccountModification { @@ -54,4 +55,3 @@ message AppState { AccountModification account_modification = 6; } } - diff --git a/test/qa/lib/protobuf/daemon/state_pb2.py b/test/qa/lib/protobuf/daemon/state_pb2.py index da010aa0..8a5e45f3 100644 --- a/test/qa/lib/protobuf/daemon/state_pb2.py +++ b/test/qa/lib/protobuf/daemon/state_pb2.py @@ -25,7 +25,7 @@ import settings_pb2 as settings__pb2 -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0bstate.proto\x12\x02pb\x1a\x0esettings.proto\"\xcb\x01\n\x10\x43onnectionStatus\x12\"\n\x05state\x18\x01 \x01(\x0e\x32\x13.pb.ConnectionState\x12\x11\n\tserver_ip\x18\x02 \x01(\t\x12\x16\n\x0eserver_country\x18\x03 \x01(\t\x12\x13\n\x0bserver_city\x18\x04 \x01(\t\x12\x17\n\x0fserver_hostname\x18\x05 \x01(\t\x12\x13\n\x0bserver_name\x18\x06 \x01(\t\x12\x14\n\x0cis_mesh_peer\x18\x07 \x01(\x08\x12\x0f\n\x07\x62y_user\x18\x08 \x01(\x08\".\n\nLoginEvent\x12 \n\x04type\x18\x01 \x01(\x0e\x32\x12.pb.LoginEventType\"=\n\x13\x41\x63\x63ountModification\x12\x17\n\nexpires_at\x18\x01 \x01(\tH\x00\x88\x01\x01\x42\r\n\x0b_expires_at\"\x9c\x02\n\x08\x41ppState\x12\"\n\x05\x65rror\x18\x01 \x01(\x0e\x32\x11.pb.AppStateErrorH\x00\x12\x31\n\x11\x63onnection_status\x18\x02 \x01(\x0b\x32\x14.pb.ConnectionStatusH\x00\x12%\n\x0blogin_event\x18\x03 \x01(\x0b\x32\x0e.pb.LoginEventH\x00\x12\'\n\x0fsettings_change\x18\x04 \x01(\x0b\x32\x0c.pb.SettingsH\x00\x12\'\n\x0cupdate_event\x18\x05 \x01(\x0e\x32\x0f.pb.UpdateEventH\x00\x12\x37\n\x14\x61\x63\x63ount_modification\x18\x06 \x01(\x0b\x32\x17.pb.AccountModificationH\x00\x42\x07\n\x05state*&\n\rAppStateError\x12\x15\n\x11\x46\x41ILED_TO_GET_UID\x10\x00*B\n\x0f\x43onnectionState\x12\x10\n\x0c\x44ISCONNECTED\x10\x00\x12\x0e\n\nCONNECTING\x10\x01\x12\r\n\tCONNECTED\x10\x02*\'\n\x0eLoginEventType\x12\t\n\x05LOGIN\x10\x00\x12\n\n\x06LOGOUT\x10\x01*&\n\x0bUpdateEvent\x12\x17\n\x13SERVERS_LIST_UPDATE\x10\x00\x42\x31Z/github.com/NordSecurity/nordvpn-linux/daemon/pbb\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0bstate.proto\x12\x02pb\x1a\x0esettings.proto\"\xcb\x01\n\x10\x43onnectionStatus\x12\"\n\x05state\x18\x01 \x01(\x0e\x32\x13.pb.ConnectionState\x12\x11\n\tserver_ip\x18\x02 \x01(\t\x12\x16\n\x0eserver_country\x18\x03 \x01(\t\x12\x13\n\x0bserver_city\x18\x04 \x01(\t\x12\x17\n\x0fserver_hostname\x18\x05 \x01(\t\x12\x13\n\x0bserver_name\x18\x06 \x01(\t\x12\x14\n\x0cis_mesh_peer\x18\x07 \x01(\x08\x12\x0f\n\x07\x62y_user\x18\x08 \x01(\x08\".\n\nLoginEvent\x12 \n\x04type\x18\x01 \x01(\x0e\x32\x12.pb.LoginEventType\"=\n\x13\x41\x63\x63ountModification\x12\x17\n\nexpires_at\x18\x01 \x01(\tH\x00\x88\x01\x01\x42\r\n\x0b_expires_at\"\x9c\x02\n\x08\x41ppState\x12\"\n\x05\x65rror\x18\x01 \x01(\x0e\x32\x11.pb.AppStateErrorH\x00\x12\x31\n\x11\x63onnection_status\x18\x02 \x01(\x0b\x32\x14.pb.ConnectionStatusH\x00\x12%\n\x0blogin_event\x18\x03 \x01(\x0b\x32\x0e.pb.LoginEventH\x00\x12\'\n\x0fsettings_change\x18\x04 \x01(\x0b\x32\x0c.pb.SettingsH\x00\x12\'\n\x0cupdate_event\x18\x05 \x01(\x0e\x32\x0f.pb.UpdateEventH\x00\x12\x37\n\x14\x61\x63\x63ount_modification\x18\x06 \x01(\x0b\x32\x17.pb.AccountModificationH\x00\x42\x07\n\x05state*&\n\rAppStateError\x12\x15\n\x11\x46\x41ILED_TO_GET_UID\x10\x00*B\n\x0f\x43onnectionState\x12\x10\n\x0c\x44ISCONNECTED\x10\x00\x12\x0e\n\nCONNECTING\x10\x01\x12\r\n\tCONNECTED\x10\x02*\'\n\x0eLoginEventType\x12\t\n\x05LOGIN\x10\x00\x12\n\n\x06LOGOUT\x10\x01*<\n\x0bUpdateEvent\x12\x17\n\x13SERVERS_LIST_UPDATE\x10\x00\x12\x14\n\x10\x41\x43TUAL_IP_UPDATE\x10\x01\x42\x31Z/github.com/NordSecurity/nordvpn-linux/daemon/pbb\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) @@ -40,7 +40,7 @@ _globals['_LOGINEVENTTYPE']._serialized_start=747 _globals['_LOGINEVENTTYPE']._serialized_end=786 _globals['_UPDATEEVENT']._serialized_start=788 - _globals['_UPDATEEVENT']._serialized_end=826 + _globals['_UPDATEEVENT']._serialized_end=848 _globals['_CONNECTIONSTATUS']._serialized_start=36 _globals['_CONNECTIONSTATUS']._serialized_end=239 _globals['_LOGINEVENT']._serialized_start=241 diff --git a/test/qa/lib/protobuf/daemon/state_pb2.pyi b/test/qa/lib/protobuf/daemon/state_pb2.pyi index 0282605d..67379e47 100644 --- a/test/qa/lib/protobuf/daemon/state_pb2.pyi +++ b/test/qa/lib/protobuf/daemon/state_pb2.pyi @@ -24,6 +24,7 @@ class LoginEventType(int, metaclass=_enum_type_wrapper.EnumTypeWrapper): class UpdateEvent(int, metaclass=_enum_type_wrapper.EnumTypeWrapper): __slots__ = () SERVERS_LIST_UPDATE: _ClassVar[UpdateEvent] + ACTUAL_IP_UPDATE: _ClassVar[UpdateEvent] FAILED_TO_GET_UID: AppStateError DISCONNECTED: ConnectionState CONNECTING: ConnectionState @@ -31,6 +32,7 @@ CONNECTED: ConnectionState LOGIN: LoginEventType LOGOUT: LoginEventType SERVERS_LIST_UPDATE: UpdateEvent +ACTUAL_IP_UPDATE: UpdateEvent class ConnectionStatus(_message.Message): __slots__ = ("state", "server_ip", "server_country", "server_city", "server_hostname", "server_name", "is_mesh_peer", "by_user")