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.
This commit is contained in:
parent
ed86554e54
commit
08b4b28645
1 changed files with 5 additions and 2 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue