From 3aa28ba484355d7e792f0f941af2c1ffe56c3f25 Mon Sep 17 00:00:00 2001 From: Bartosz Oleaczek Date: Thu, 10 Oct 2024 11:22:26 +0200 Subject: [PATCH 1/2] Fix connection to a DIP server --- auth/auth.go | 11 +++-- auth/auth_test.go | 43 +++++++++++++++----- daemon/pb/account.pb.go | 76 +++++++++++++++++------------------ daemon/rpc_account.go | 2 +- daemon/rpc_connect_test.go | 24 +++++++++-- daemon/servers.go | 8 ++-- protobuf/daemon/account.proto | 2 +- 7 files changed, 103 insertions(+), 63 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index dffe2eed..b5360894 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -18,7 +18,7 @@ import ( type DedicatedIPService struct { ExpiresAt string // ServerID will be set to NoServerSelected if server was not selected by the user - ServerID int64 + ServerIDs []int64 } // Checker provides information about current authentication. @@ -37,7 +37,6 @@ type Checker interface { const ( VPNServiceID = 1 DedicatedIPServiceID = 11 - NoServerSelected = -1 ) type expirationChecker interface { @@ -172,12 +171,12 @@ func (r *RenewingChecker) GetDedicatedIPServices() ([]DedicatedIPService, error) dipServices := []DedicatedIPService{} for _, service := range services { if service.Service.ID == DedicatedIPServiceID && !r.expChecker.isExpired(service.ExpiresAt) { - var serverID int64 = NoServerSelected - if len(service.Details.Servers) != 0 { - serverID = service.Details.Servers[0].ID + serverIDs := []int64{} + for _, server := range service.Details.Servers { + serverIDs = append(serverIDs, server.ID) } dipServices = append(dipServices, - DedicatedIPService{ExpiresAt: service.ExpiresAt, ServerID: serverID}) + DedicatedIPService{ExpiresAt: service.ExpiresAt, ServerIDs: serverIDs}) } } diff --git a/auth/auth_test.go b/auth/auth_test.go index 00c05e72..8417f334 100644 --- a/auth/auth_test.go +++ b/auth/auth_test.go @@ -250,7 +250,7 @@ func TestGetDedicatedIPServices(t *testing.T) { category.Set(t, category.Unit) dipService1ExpDate := "2050-06-04 00:00:00" - var dipSercice1ServerID int64 = 11111 + var dipService1ServerID int64 = 11111 dipService1 := core.ServiceData{ ExpiresAt: dipService1ExpDate, Service: core.Service{ @@ -258,13 +258,13 @@ func TestGetDedicatedIPServices(t *testing.T) { }, Details: core.ServiceDetails{ Servers: []core.ServiceServer{ - {ID: dipSercice1ServerID}, + {ID: dipService1ServerID}, }, }, } dipService2ExpDate := "2050-08-22 00:00:00" - var dipSercice2ServerID int64 = 11111 + var dipService2ServerID int64 = 222222 dipService2 := core.ServiceData{ ExpiresAt: dipService2ExpDate, Service: core.Service{ @@ -272,7 +272,21 @@ func TestGetDedicatedIPServices(t *testing.T) { }, Details: core.ServiceDetails{ Servers: []core.ServiceServer{ - {ID: dipSercice2ServerID}, + {ID: dipService2ServerID}, + }, + }, + } + + dipService3ExpDate := "2050-08-22 00:00:00" + dipService3 := core.ServiceData{ + ExpiresAt: dipService3ExpDate, + Service: core.Service{ + ID: DedicatedIPServiceID, + }, + Details: core.ServiceDetails{ + Servers: []core.ServiceServer{ + {ID: dipService1ServerID}, + {ID: dipService2ServerID}, }, }, } @@ -328,7 +342,7 @@ func TestGetDedicatedIPServices(t *testing.T) { dipService1, }, expectedDIPSerivces: []DedicatedIPService{ - {ExpiresAt: dipService1ExpDate, ServerID: dipSercice1ServerID}, + {ExpiresAt: dipService1ExpDate, ServerIDs: []int64{dipService1ServerID}}, }, }, { @@ -338,8 +352,17 @@ func TestGetDedicatedIPServices(t *testing.T) { dipService2, }, expectedDIPSerivces: []DedicatedIPService{ - {ExpiresAt: dipService1ExpDate, ServerID: dipSercice1ServerID}, - {ExpiresAt: dipService2ExpDate, ServerID: dipSercice2ServerID}, + {ExpiresAt: dipService1ExpDate, ServerIDs: []int64{dipService1ServerID}}, + {ExpiresAt: dipService2ExpDate, ServerIDs: []int64{dipService2ServerID}}, + }, + }, + { + name: "multiple dip servers in single service", + servicesResponse: []core.ServiceData{ + dipService3, + }, + expectedDIPSerivces: []DedicatedIPService{ + {ExpiresAt: dipService3ExpDate, ServerIDs: []int64{dipService1ServerID, dipService2ServerID}}, }, }, { @@ -356,7 +379,7 @@ func TestGetDedicatedIPServices(t *testing.T) { dipService1, }, expectedDIPSerivces: []DedicatedIPService{ - {ExpiresAt: dipService1ExpDate, ServerID: dipSercice1ServerID}, + {ExpiresAt: dipService1ExpDate, ServerIDs: []int64{dipService1ServerID}}, }, }, { @@ -368,7 +391,7 @@ func TestGetDedicatedIPServices(t *testing.T) { dipService1, }, expectedDIPSerivces: []DedicatedIPService{ - {ExpiresAt: dipService1ExpDate, ServerID: dipSercice1ServerID}, + {ExpiresAt: dipService1ExpDate, ServerIDs: []int64{dipService1ServerID}}, }, }, { @@ -396,7 +419,7 @@ func TestGetDedicatedIPServices(t *testing.T) { dipServiceNoServer, }, expectedDIPSerivces: []DedicatedIPService{ - {ExpiresAt: dipServiceNoServerExpirationDate, ServerID: NoServerSelected}, + {ExpiresAt: dipServiceNoServerExpirationDate, ServerIDs: []int64{}}, }, }, } diff --git a/daemon/pb/account.pb.go b/daemon/pb/account.pb.go index 6217b1f6..75240a99 100644 --- a/daemon/pb/account.pb.go +++ b/daemon/pb/account.pb.go @@ -25,8 +25,8 @@ type DedidcatedIPService struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - ServerId int64 `protobuf:"varint,1,opt,name=server_id,json=serverId,proto3" json:"server_id,omitempty"` - DedicatedIpExpiresAt string `protobuf:"bytes,2,opt,name=dedicated_ip_expires_at,json=dedicatedIpExpiresAt,proto3" json:"dedicated_ip_expires_at,omitempty"` + ServerIds []int64 `protobuf:"varint,1,rep,packed,name=server_ids,json=serverIds,proto3" json:"server_ids,omitempty"` + DedicatedIpExpiresAt string `protobuf:"bytes,2,opt,name=dedicated_ip_expires_at,json=dedicatedIpExpiresAt,proto3" json:"dedicated_ip_expires_at,omitempty"` } func (x *DedidcatedIPService) Reset() { @@ -59,11 +59,11 @@ func (*DedidcatedIPService) Descriptor() ([]byte, []int) { return file_account_proto_rawDescGZIP(), []int{0} } -func (x *DedidcatedIPService) GetServerId() int64 { +func (x *DedidcatedIPService) GetServerIds() []int64 { if x != nil { - return x.ServerId + return x.ServerIds } - return 0 + return nil } func (x *DedidcatedIPService) GetDedicatedIpExpiresAt() string { @@ -179,39 +179,39 @@ var File_account_proto protoreflect.FileDescriptor var file_account_proto_rawDesc = []byte{ 0x0a, 0x0d, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x02, 0x70, 0x62, 0x1a, 0x0c, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x22, 0x69, 0x0a, 0x13, 0x44, 0x65, 0x64, 0x69, 0x64, 0x63, 0x61, 0x74, 0x65, 0x64, 0x49, - 0x50, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x65, 0x72, 0x76, - 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x65, 0x72, - 0x76, 0x65, 0x72, 0x49, 0x64, 0x12, 0x35, 0x0a, 0x17, 0x64, 0x65, 0x64, 0x69, 0x63, 0x61, 0x74, - 0x65, 0x64, 0x5f, 0x69, 0x70, 0x5f, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x5f, 0x61, 0x74, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x14, 0x64, 0x65, 0x64, 0x69, 0x63, 0x61, 0x74, 0x65, - 0x64, 0x49, 0x70, 0x45, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x41, 0x74, 0x22, 0xe0, 0x02, 0x0a, - 0x0f, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, - 0x74, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, - 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x1d, 0x0a, 0x0a, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, - 0x73, 0x5f, 0x61, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x65, 0x78, 0x70, 0x69, - 0x72, 0x65, 0x73, 0x41, 0x74, 0x12, 0x2e, 0x0a, 0x13, 0x64, 0x65, 0x64, 0x69, 0x63, 0x61, 0x74, - 0x65, 0x64, 0x5f, 0x69, 0x70, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x05, 0x20, 0x01, - 0x28, 0x03, 0x52, 0x11, 0x64, 0x65, 0x64, 0x69, 0x63, 0x61, 0x74, 0x65, 0x64, 0x49, 0x70, 0x53, - 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x3e, 0x0a, 0x1c, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x64, 0x65, - 0x64, 0x69, 0x63, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x69, 0x70, 0x5f, 0x65, 0x78, 0x70, 0x69, 0x72, - 0x65, 0x73, 0x5f, 0x61, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x18, 0x6c, 0x61, 0x73, - 0x74, 0x44, 0x65, 0x64, 0x69, 0x63, 0x61, 0x74, 0x65, 0x64, 0x49, 0x70, 0x45, 0x78, 0x70, 0x69, - 0x72, 0x65, 0x73, 0x41, 0x74, 0x12, 0x4b, 0x0a, 0x15, 0x64, 0x65, 0x64, 0x69, 0x63, 0x61, 0x74, - 0x65, 0x64, 0x5f, 0x69, 0x70, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x18, 0x07, - 0x20, 0x03, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x70, 0x62, 0x2e, 0x44, 0x65, 0x64, 0x69, 0x64, 0x63, - 0x61, 0x74, 0x65, 0x64, 0x49, 0x50, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x13, 0x64, - 0x65, 0x64, 0x69, 0x63, 0x61, 0x74, 0x65, 0x64, 0x49, 0x70, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, - 0x65, 0x73, 0x12, 0x2b, 0x0a, 0x0a, 0x6d, 0x66, 0x61, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, - 0x18, 0x08, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x70, 0x62, 0x2e, 0x54, 0x72, 0x69, 0x53, - 0x74, 0x61, 0x74, 0x65, 0x52, 0x09, 0x6d, 0x66, 0x61, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 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, + 0x6f, 0x22, 0x6b, 0x0a, 0x13, 0x44, 0x65, 0x64, 0x69, 0x64, 0x63, 0x61, 0x74, 0x65, 0x64, 0x49, + 0x50, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x65, 0x72, 0x76, + 0x65, 0x72, 0x5f, 0x69, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x03, 0x52, 0x09, 0x73, 0x65, + 0x72, 0x76, 0x65, 0x72, 0x49, 0x64, 0x73, 0x12, 0x35, 0x0a, 0x17, 0x64, 0x65, 0x64, 0x69, 0x63, + 0x61, 0x74, 0x65, 0x64, 0x5f, 0x69, 0x70, 0x5f, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x5f, + 0x61, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x14, 0x64, 0x65, 0x64, 0x69, 0x63, 0x61, + 0x74, 0x65, 0x64, 0x49, 0x70, 0x45, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x41, 0x74, 0x22, 0xe0, + 0x02, 0x0a, 0x0f, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, + 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, + 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x1d, 0x0a, 0x0a, 0x65, 0x78, 0x70, 0x69, + 0x72, 0x65, 0x73, 0x5f, 0x61, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x65, 0x78, + 0x70, 0x69, 0x72, 0x65, 0x73, 0x41, 0x74, 0x12, 0x2e, 0x0a, 0x13, 0x64, 0x65, 0x64, 0x69, 0x63, + 0x61, 0x74, 0x65, 0x64, 0x5f, 0x69, 0x70, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x05, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x11, 0x64, 0x65, 0x64, 0x69, 0x63, 0x61, 0x74, 0x65, 0x64, 0x49, + 0x70, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x3e, 0x0a, 0x1c, 0x6c, 0x61, 0x73, 0x74, 0x5f, + 0x64, 0x65, 0x64, 0x69, 0x63, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x69, 0x70, 0x5f, 0x65, 0x78, 0x70, + 0x69, 0x72, 0x65, 0x73, 0x5f, 0x61, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x18, 0x6c, + 0x61, 0x73, 0x74, 0x44, 0x65, 0x64, 0x69, 0x63, 0x61, 0x74, 0x65, 0x64, 0x49, 0x70, 0x45, 0x78, + 0x70, 0x69, 0x72, 0x65, 0x73, 0x41, 0x74, 0x12, 0x4b, 0x0a, 0x15, 0x64, 0x65, 0x64, 0x69, 0x63, + 0x61, 0x74, 0x65, 0x64, 0x5f, 0x69, 0x70, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, + 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x70, 0x62, 0x2e, 0x44, 0x65, 0x64, 0x69, + 0x64, 0x63, 0x61, 0x74, 0x65, 0x64, 0x49, 0x50, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, + 0x13, 0x64, 0x65, 0x64, 0x69, 0x63, 0x61, 0x74, 0x65, 0x64, 0x49, 0x70, 0x53, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x73, 0x12, 0x2b, 0x0a, 0x0a, 0x6d, 0x66, 0x61, 0x5f, 0x73, 0x74, 0x61, 0x74, + 0x75, 0x73, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x70, 0x62, 0x2e, 0x54, 0x72, + 0x69, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x09, 0x6d, 0x66, 0x61, 0x53, 0x74, 0x61, 0x74, 0x75, + 0x73, 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/rpc_account.go b/daemon/rpc_account.go index c13a8336..cda6a675 100644 --- a/daemon/rpc_account.go +++ b/daemon/rpc_account.go @@ -44,7 +44,7 @@ func dipServicesToProtobuf(dipServices []auth.DedicatedIPService) []*pb.Dedidcat dipServicesProtobuf := []*pb.DedidcatedIPService{} for _, dipService := range dipServices { dipServicesProtobuf = append(dipServicesProtobuf, &pb.DedidcatedIPService{ - ServerId: dipService.ServerID, + ServerIds: dipService.ServerIDs, DedicatedIpExpiresAt: dipService.ExpiresAt, }) } diff --git a/daemon/rpc_connect_test.go b/daemon/rpc_connect_test.go index 591da038..2723bf6c 100644 --- a/daemon/rpc_connect_test.go +++ b/daemon/rpc_connect_test.go @@ -173,7 +173,7 @@ func TestRpcConnect(t *testing.T) { rpc.ac = &workingLoginChecker{ isDedicatedIPExpired: false, dedicatedIPService: []auth.DedicatedIPService{ - {ExpiresAt: "", ServerID: 7}, + {ExpiresAt: "", ServerIDs: []int64{7}}, }, } }, @@ -189,7 +189,23 @@ func TestRpcConnect(t *testing.T) { rpc.ac = &workingLoginChecker{ isDedicatedIPExpired: false, dedicatedIPService: []auth.DedicatedIPService{ - {ExpiresAt: "", ServerID: 7}, + {ExpiresAt: "", ServerIDs: []int64{7}}, + }, + } + }, + resp: internal.CodeConnected, + }, + { + name: "Dedicated IP with server name multiple servers in service works", + serverTag: "lt7", + factory: func(config.Technology) (vpn.VPN, error) { + return &mock.WorkingVPN{}, nil + }, + setup: func(rpc *RPC) { + rpc.ac = &workingLoginChecker{ + isDedicatedIPExpired: false, + dedicatedIPService: []auth.DedicatedIPService{ + {ExpiresAt: "", ServerIDs: []int64{7, 8}}, }, } }, @@ -229,7 +245,7 @@ func TestRpcConnect(t *testing.T) { rpc.ac = &workingLoginChecker{ isDedicatedIPExpired: false, dedicatedIPService: []auth.DedicatedIPService{ - {ExpiresAt: "", ServerID: 7}, + {ExpiresAt: "", ServerIDs: []int64{7}}, }, } }, @@ -245,7 +261,7 @@ func TestRpcConnect(t *testing.T) { rpc.ac = &workingLoginChecker{ isDedicatedIPExpired: false, dedicatedIPService: []auth.DedicatedIPService{ - {ExpiresAt: "", ServerID: auth.NoServerSelected}, + {ExpiresAt: "", ServerIDs: []int64{}}, }, } }, diff --git a/daemon/servers.go b/daemon/servers.go index 3d21c272..4ef375ec 100644 --- a/daemon/servers.go +++ b/daemon/servers.go @@ -449,7 +449,7 @@ func selectFilter(tag string, group config.ServerGroup, obfuscated bool) core.Pr // isAnyDIPServersAvailable returns true if dedicated IP server is selected for any of the provided services func isAnyDIPServersAvailable(dedicatedIPServices []auth.DedicatedIPService) bool { index := slices.IndexFunc(dedicatedIPServices, func(dipService auth.DedicatedIPService) bool { - return dipService.ServerID != auth.NoServerSelected + return len(dipService.ServerIDs) > 0 }) return index != -1 @@ -516,7 +516,8 @@ func selectServer(r *RPC, insights *core.Insights, cfg config.Config, tag string } index := slices.IndexFunc(dedicatedIPServices, func(s auth.DedicatedIPService) bool { - return s.ServerID == server.ID + index := slices.Index(s.ServerIDs, server.ID) + return index != -1 }) if index == -1 { log.Println(internal.ErrorPrefix, "server is not in the DIP servers list") @@ -561,7 +562,8 @@ func selectDedicatedIPServer(authChecker auth.Checker, servers core.Servers) (*c } service := dedicatedIPServices[rand.Intn(len(dedicatedIPServices))] - server, err := getServerByID(servers, service.ServerID) + serverID := service.ServerIDs[rand.Intn(len(service.ServerIDs))] + server, err := getServerByID(servers, serverID) if err != nil { log.Println(internal.ErrorPrefix, "DIP server not found:", err) return nil, internal.ErrServerIsUnavailable diff --git a/protobuf/daemon/account.proto b/protobuf/daemon/account.proto index ed97ba74..12416c74 100644 --- a/protobuf/daemon/account.proto +++ b/protobuf/daemon/account.proto @@ -7,7 +7,7 @@ option go_package = "github.com/NordSecurity/nordvpn-linux/daemon/pb"; import "common.proto"; message DedidcatedIPService { - int64 server_id = 1; + repeated int64 server_ids = 1; string dedicated_ip_expires_at = 2; } From e7947ece7267d3a40bd4056af8ecaf0b098cb858 Mon Sep 17 00:00:00 2001 From: Bartosz Oleaczek Date: Fri, 11 Oct 2024 13:17:28 +0200 Subject: [PATCH 2/2] fix lint --- auth/auth_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auth/auth_test.go b/auth/auth_test.go index 8417f334..95bfc0e9 100644 --- a/auth/auth_test.go +++ b/auth/auth_test.go @@ -263,7 +263,7 @@ func TestGetDedicatedIPServices(t *testing.T) { }, } - dipService2ExpDate := "2050-08-22 00:00:00" + dipService2ExpDate := "2050-01-25 00:00:00" var dipService2ServerID int64 = 222222 dipService2 := core.ServiceData{ ExpiresAt: dipService2ExpDate, @@ -277,7 +277,7 @@ func TestGetDedicatedIPServices(t *testing.T) { }, } - dipService3ExpDate := "2050-08-22 00:00:00" + dipService3ExpDate := "2043-05-10 00:00:00" dipService3 := core.ServiceData{ ExpiresAt: dipService3ExpDate, Service: core.Service{