From 08b4b28645e6f04c620a093d5dec820a4bacc933 Mon Sep 17 00:00:00 2001 From: Kumi Date: Fri, 12 Jul 2024 10:59:11 +0200 Subject: [PATCH] fix: ensure unique VPN port assignment Updated the port assignment logic to guarantee that a newly assigned port is unique by avoiding conflicts with existing port assignments. This addresses potential issues with port collisions that could disrupt VPN operations. --- coldbrew/vpn/models.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/coldbrew/vpn/models.py b/coldbrew/vpn/models.py index adcbabe..8ec957a 100644 --- a/coldbrew/vpn/models.py +++ b/coldbrew/vpn/models.py @@ -33,8 +33,11 @@ class VPN(models.Model): self.public_key = get_public_key(self.private_key) - if not self.port: - self.port = random.randint(10000, 40000) + while not self.port: + port = random.randint(10000, 40000) + + if not VPN.objects.filter(port=port).exists(): + self.port = port super().save(*args, **kwargs)