Skip to content

Commit

Permalink
server: add options to choose the address to bind to
Browse files Browse the repository at this point in the history
Sometimes a user might want to bind to localhost only for testing
or have multiple interfaces per IP version and only one must be used.
  • Loading branch information
powerjungle committed Jan 26, 2023
1 parent 0123325 commit fe758de
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 2 deletions.
7 changes: 5 additions & 2 deletions syncplay/ep_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def failed4(f):
def main():
argsGetter = ConfigurationGetter()
args = argsGetter.getConfiguration()

factory = SyncFactory(
args.port,
args.password,
Expand All @@ -53,12 +54,14 @@ def main():
args.stats_db_file,
args.tls
)

if args.disable_ipv6 is False:
endpoint6 = TCP6ServerEndpoint(reactor, int(args.port))
endpoint6 = TCP6ServerEndpoint(reactor, int(args.port), interface=args.interface_ipv6)
endpoint6.listen(factory).addCallbacks(isListening6, failed6)
if args.disable_ipv4 is False:
endpoint4 = TCP4ServerEndpoint(reactor, int(args.port))
endpoint4 = TCP4ServerEndpoint(reactor, int(args.port), interface=args.interface_ipv4)
endpoint4.listen(factory).addCallbacks(isListening4, failed4)

if ServerStatus.listening6 or ServerStatus.listening4:
reactor.run()
else:
Expand Down
2 changes: 2 additions & 0 deletions syncplay/messages_de.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@
"server-messed-up-motd-too-long": "Die Nachricht des Tages ist zu lang - Maximal {} Zeichen, aktuell {}.",
"server-do-not-listen-on-ipv4": "Don't listen on IPv4 when starting the server.",
"server-do-not-listen-on-ipv6": "Don't listen on IPv6 when starting the server.",
"server-interface-ipv4": "The IP address to bind to for IPv4. Leaving it empty defaults to using all.",
"server-interface-ipv6": "The IP address to bind to for IPv6. Leaving it empty defaults to using all.",

# Server errors
"unknown-command-server-error": "Unbekannter Befehl {}", # message
Expand Down
2 changes: 2 additions & 0 deletions syncplay/messages_en.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@
"server-messed-up-motd-too-long": "Message of the Day is too long - maximum of {} chars, {} given.",
"server-do-not-listen-on-ipv4": "Don't listen on IPv4 when starting the server.",
"server-do-not-listen-on-ipv6": "Don't listen on IPv6 when starting the server.",
"server-interface-ipv4": "The IP address to bind to for IPv4. Leaving it empty defaults to using all.",
"server-interface-ipv6": "The IP address to bind to for IPv6. Leaving it empty defaults to using all.",

# Server errors
"unknown-command-server-error": "Unknown command {}", # message
Expand Down
2 changes: 2 additions & 0 deletions syncplay/messages_eo.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@
"server-messed-up-motd-too-long": "Mesaĝo de tago estas tro longa – maksimuma kvanto estas {} signoj, sed {} estas donitaj.",
"server-do-not-listen-on-ipv4": "Don't listen on IPv4 when starting the server.",
"server-do-not-listen-on-ipv6": "Don't listen on IPv6 when starting the server.",
"server-interface-ipv4": "The IP address to bind to for IPv4. Leaving it empty defaults to using all.",
"server-interface-ipv6": "The IP address to bind to for IPv6. Leaving it empty defaults to using all.",

# Server errors
"unknown-command-server-error": "Nekonata ordono {}", # message
Expand Down
2 changes: 2 additions & 0 deletions syncplay/messages_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@
"server-messed-up-motd-too-long": "El mensaje del día es muy largo - máximo de {} caracteres, se recibieron {}.",
"server-do-not-listen-on-ipv4": "Don't listen on IPv4 when starting the server.",
"server-do-not-listen-on-ipv6": "Don't listen on IPv6 when starting the server.",
"server-interface-ipv4": "The IP address to bind to for IPv4. Leaving it empty defaults to using all.",
"server-interface-ipv6": "The IP address to bind to for IPv6. Leaving it empty defaults to using all.",

# Server errors
"unknown-command-server-error": "Comando desconocido {}", # message
Expand Down
2 changes: 2 additions & 0 deletions syncplay/messages_fr.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@
"server-messed-up-motd-too-long": "Le message du jour est trop long: {}caractères maximum, {} donnés.",
"server-do-not-listen-on-ipv4": "Don't listen on IPv4 when starting the server.",
"server-do-not-listen-on-ipv6": "Don't listen on IPv6 when starting the server.",
"server-interface-ipv4": "The IP address to bind to for IPv4. Leaving it empty defaults to using all.",
"server-interface-ipv6": "The IP address to bind to for IPv6. Leaving it empty defaults to using all.",

# Server errors
"unknown-command-server-error": "Commande inconnue {}", # message
Expand Down
2 changes: 2 additions & 0 deletions syncplay/messages_it.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@
"server-messed-up-motd-too-long": "Il messaggio del giorno è troppo lungo - numero massimo di caratteri è {}, {} trovati.",
"server-do-not-listen-on-ipv4": "Don't listen on IPv4 when starting the server.",
"server-do-not-listen-on-ipv6": "Don't listen on IPv6 when starting the server.",
"server-interface-ipv4": "The IP address to bind to for IPv4. Leaving it empty defaults to using all.",
"server-interface-ipv6": "The IP address to bind to for IPv6. Leaving it empty defaults to using all.",

# Server errors
"unknown-command-server-error": "Comando non riconosciuto {}", # message
Expand Down
2 changes: 2 additions & 0 deletions syncplay/messages_pt_BR.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@
"server-messed-up-motd-too-long": "A Mensagem do Dia é muito longa - máximo de {} caracteres, {} foram dados.",
"server-do-not-listen-on-ipv4": "Don't listen on IPv4 when starting the server.",
"server-do-not-listen-on-ipv6": "Don't listen on IPv6 when starting the server.",
"server-interface-ipv4": "The IP address to bind to for IPv4. Leaving it empty defaults to using all.",
"server-interface-ipv6": "The IP address to bind to for IPv6. Leaving it empty defaults to using all.",

# Server errors
"unknown-command-server-error": "Comando desconhecido: {}", # message
Expand Down
2 changes: 2 additions & 0 deletions syncplay/messages_pt_PT.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@
"server-messed-up-motd-too-long": "A Mensagem do Dia é muito longa - máximo de {} caracteres, {} foram dados.",
"server-do-not-listen-on-ipv4": "Don't listen on IPv4 when starting the server.",
"server-do-not-listen-on-ipv6": "Don't listen on IPv6 when starting the server.",
"server-interface-ipv4": "The IP address to bind to for IPv4. Leaving it empty defaults to using all.",
"server-interface-ipv6": "The IP address to bind to for IPv6. Leaving it empty defaults to using all.",

# Server errors
"unknown-command-server-error": "Comando desconhecido: {}", # message
Expand Down
2 changes: 2 additions & 0 deletions syncplay/messages_ru.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,8 @@
"server-messed-up-motd-too-long": "MOTD-сообщение слишком длинное: максимальная длина - {} символ(ов), текущая длина - {} символ(ов).",
"server-do-not-listen-on-ipv4": "Don't listen on IPv4 when starting the server.",
"server-do-not-listen-on-ipv6": "Don't listen on IPv6 when starting the server.",
"server-interface-ipv4": "The IP address to bind to for IPv4. Leaving it empty defaults to using all.",
"server-interface-ipv6": "The IP address to bind to for IPv6. Leaving it empty defaults to using all.",

# Server errors
"unknown-command-server-error": "Неизвестная команда: {}", # message
Expand Down
2 changes: 2 additions & 0 deletions syncplay/messages_tr.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@
"server-messed-up-motd-too-long": "Günün Mesajı çok uzun - maksimum {} karakter olmalı, {} verildi.",
"server-do-not-listen-on-ipv4": "Don't listen on IPv4 when starting the server.",
"server-do-not-listen-on-ipv6": "Don't listen on IPv6 when starting the server.",
"server-interface-ipv4": "The IP address to bind to for IPv4. Leaving it empty defaults to using all.",
"server-interface-ipv6": "The IP address to bind to for IPv6. Leaving it empty defaults to using all.",

# Server errors
"unknown-command-server-error": "Bilinmeyen komut {}", # message
Expand Down
2 changes: 2 additions & 0 deletions syncplay/messages_zh_CN.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@
"server-messed-up-motd-too-long": "每日信息过长 - 最大{}个chars, 给出的长度{}",
"server-do-not-listen-on-ipv4": "Don't listen on IPv4 when starting the server.",
"server-do-not-listen-on-ipv6": "Don't listen on IPv6 when starting the server.",
"server-interface-ipv4": "The IP address to bind to for IPv4. Leaving it empty defaults to using all.",
"server-interface-ipv6": "The IP address to bind to for IPv6. Leaving it empty defaults to using all.",

# Server errors
"unknown-command-server-error": "未知命令 {}", # message
Expand Down
2 changes: 2 additions & 0 deletions syncplay/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,3 +891,5 @@ def _prepareArgParser(self):
self._argparser.add_argument('--tls', metavar='path', type=str, nargs='?', help=getMessage("server-startTLS-argument"))
self._argparser.add_argument('--disable-ipv4', action='store_true', help=getMessage("server-do-not-listen-on-ipv4"))
self._argparser.add_argument('--disable-ipv6', action='store_true', help=getMessage("server-do-not-listen-on-ipv6"))
self._argparser.add_argument('--interface-ipv4', metavar='interfaceIPv4', type=str, nargs='?', help=getMessage("server-interface-ipv4"), default='')
self._argparser.add_argument('--interface-ipv6', metavar='interfaceIPv6', type=str, nargs='?', help=getMessage("server-interface-ipv6"), default='')

0 comments on commit fe758de

Please sign in to comment.