From 9c18d3930bf87bc0c866d14983f8ed4748d60e6a Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Sun, 12 Jan 2020 19:31:08 -0500 Subject: [PATCH] #6 Add support for IPv6. --- README.md | 10 ++++++++++ jetforce.py | 12 +++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 757ef5d..67aa376 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,16 @@ receive traffic from. For example, if your jetforce server is running on that do not match this hostname will be refused by the server, including URLs that use a direct IP address such as "gemini://174.138.124.169". +### Setting the ``host`` + +The server's host should be set to the local socket address that you want to +bind to: + +- ``--host 127.0.0.1`` - Accept local connections only +- ``--host 0.0.0.0`` - Accept remote connections over IPv4 +- ``--host ::`` - Accept remote connections over IPv6 +- ``--host ""`` - Accept remote connections over any interface (IPv4 + IPv6) + ### TLS Certificates The gemini specification *requires* that all connections be sent over TLS. diff --git a/jetforce.py b/jetforce.py index 12e01b1..5d0a8b7 100755 --- a/jetforce.py +++ b/jetforce.py @@ -9,6 +9,7 @@ import mimetypes import os import pathlib import re +import socket import ssl import subprocess import sys @@ -579,12 +580,13 @@ class GeminiServer: self.accept_connection, self.host, self.port, ssl=self.ssl_context ) - if server.sockets: - socket_host, socket_port = server.sockets[0].getsockname() - else: - socket_host, socket_port = None, None self.log_message(f"Server hostname is {self.hostname}") - self.log_message(f"Listening on {socket_host}:{socket_port}") + for sock in server.sockets: + sock_ip, sock_port, *_ = sock.getsockname() + if sock.family == socket.AF_INET: + self.log_message(f"Listening on {sock_ip}:{sock_port}") + else: + self.log_message(f"Listening on [{sock_ip}]:{sock_port}") async with server: await server.serve_forever()