Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#31 Relay servers #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions wg_meshconf/database_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def init(self):
database = self.read_database()

# check values that cannot be generated automatically
for key in ["Address", "Endpoint"]:
for key in ["Address"]:
for peer in database["peers"]:
if database["peers"][peer].get(key) is None:
print(f"The value of {key} cannot be automatically generated")
Expand Down Expand Up @@ -341,6 +341,7 @@ def genconfig(self, Name: str, output: pathlib.Path):
# for every peer in the database
for peer in peers:
local_peer = database["peers"][peer]
local_peer_endpoint = local_peer.get("Endpoint")

with (output / f"{peer}.conf").open("w") as config:
config.write("[Interface]\n")
Expand All @@ -355,6 +356,16 @@ def genconfig(self, Name: str, output: pathlib.Path):
# generate [Peer] sections for all other peers
for p in [i for i in database["peers"] if i != peer]:
remote_peer = database["peers"][p]
remote_peer_endpoint = remote_peer.get("Endpoint")

peers_can_connect_directly = (
remote_peer_endpoint is not None
or local_peer_endpoint is not None
)
if not peers_can_connect_directly:
# See https://github.com/pirate/wireguard-docs#how-public-relay-servers-work
# In short: Only direct connections between clients should be configured.
continue

config.write("\n[Peer]\n")
config.write("# Name: {}\n".format(p))
Expand All @@ -364,7 +375,7 @@ def genconfig(self, Name: str, output: pathlib.Path):
)
)

if remote_peer.get("Endpoint") is not None:
if remote_peer_endpoint is not None:
config.write(
"Endpoint = {}:{}\n".format(
remote_peer["Endpoint"],
Expand Down