Skip to content

Commit

Permalink
Dual stack (IPv4/IPv6) support
Browse files Browse the repository at this point in the history
  • Loading branch information
FallenSky2077 committed Aug 25, 2024
1 parent 64f8574 commit db0b025
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 10 additions & 4 deletions olah/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.

from typing import List, Optional
from typing import List, Optional, Union
import toml
import re
import fnmatch
Expand Down Expand Up @@ -78,7 +78,7 @@ class OlahConfig(object):
def __init__(self, path: Optional[str] = None) -> None:

# basic
self.host = "localhost"
self.host: Union[List[str], str] = "localhost"
self.port = 8090
self.ssl_key = None
self.ssl_cert = None
Expand All @@ -90,10 +90,10 @@ def __init__(self, path: Optional[str] = None) -> None:

self.mirror_scheme: str = "http" if self.ssl_key is None else "https"
self.mirror_netloc: str = (
f"{self.host if self.host != '0.0.0.0' else 'localhost'}:{self.port}"
f"{self.host if self._is_specific_addr(self.host) else 'localhost'}:{self.port}"
)
self.mirror_lfs_netloc: str = (
f"{self.host if self.host != '0.0.0.0' else 'localhost'}:{self.port}"
f"{self.host if self._is_specific_addr(self.host) else 'localhost'}:{self.port}"
)

self.mirrors_path: List[str] = []
Expand All @@ -105,6 +105,12 @@ def __init__(self, path: Optional[str] = None) -> None:

if path is not None:
self.read_toml(path)

def _is_specific_addr(self, host: Union[List[str], str]) -> bool:
if isinstance(host, str):
return host not in ['0.0.0.0', '::']
else:
return False

def hf_url_base(self) -> str:
return f"{self.hf_scheme}://{self.hf_netloc}"
Expand Down
4 changes: 4 additions & 0 deletions olah/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,10 @@ def is_default_value(args, arg_name):
args.ssl_cert = config.ssl_cert
if is_default_value(args, "repos_path"):
args.repos_path = config.repos_path

# Post processing
if "," in args.host:
args.host = args.host.split(",")

app.app_settings = AppSettings(
config=config,
Expand Down

0 comments on commit db0b025

Please sign in to comment.