Let peers connect to a remote WireGuard endpoint

This commit is contained in:
Eduardo Silva
2026-11-23 20:30:11 -03:00
parent a5ad9c4bae
commit 2fee9ebd6a
13 changed files with 337 additions and 43 deletions
@@ -0,0 +1,25 @@
# Generated by Django 5.2.19 on 2026-11-23 21:01
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('cluster', '0020_workerstatus_gateway_sessions_and_more'),
('wireguard', '0034_wireguardinstance_worker'),
]
operations = [
migrations.AddField(
model_name='peer',
name='active_worker',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='endpoint_peers', to='cluster.worker'),
),
migrations.AddField(
model_name='peer',
name='endpoint',
field=models.CharField(blank=True, default='', max_length=255),
),
]
+19
View File
@@ -211,6 +211,13 @@ class Peer(models.Model):
'routing_templates.RoutingTemplate', on_delete=models.SET_NULL, blank=True, null=True, related_name='peers'
)
# Remote address (host:port) for peers that this server connects to, instead of waiting for them to connect
endpoint = models.CharField(max_length=255, blank=True, default='')
# Cluster worker that keeps the connection of an endpoint peer in the mirror mode. Empty means the primary server.
active_worker = models.ForeignKey(
'cluster.Worker', on_delete=models.SET_NULL, blank=True, null=True, related_name='endpoint_peers'
)
disabled_by_schedule = models.BooleanField(default=False)
suspended = models.BooleanField(default=False)
suspend_reason = models.TextField(blank=True, null=True)
@@ -225,6 +232,18 @@ class Peer(models.Model):
else:
return self.public_key[:16] + "..."
@property
def endpoint_worker(self):
"""
Worker that runs an endpoint peer, or None when it runs on the primary server. Only one server connects to the
remote endpoint: in the mirror mode it is the active worker, in the distributed mode the server of the instance.
"""
if not self.endpoint or not ClusterSettings.cluster_enabled():
return None
if ClusterSettings.is_distributed():
return self.wireguard_instance.hosting_worker
return self.active_worker
@property
def enabled(self) -> bool:
return not self.disabled_by_schedule and not self.suspended