#6 Add support for IPv6.

This commit is contained in:
Michael Lazar 2020-01-12 19:31:08 -05:00
parent b3b6061086
commit 9c18d3930b
2 changed files with 17 additions and 5 deletions

View File

@ -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 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". 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 ### TLS Certificates
The gemini specification *requires* that all connections be sent over TLS. The gemini specification *requires* that all connections be sent over TLS.

View File

@ -9,6 +9,7 @@ import mimetypes
import os import os
import pathlib import pathlib
import re import re
import socket
import ssl import ssl
import subprocess import subprocess
import sys import sys
@ -579,12 +580,13 @@ class GeminiServer:
self.accept_connection, self.host, self.port, ssl=self.ssl_context 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"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: async with server:
await server.serve_forever() await server.serve_forever()