mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 17:12:13 -06:00
fix NetMap -j0
compat
would crash on startup if `-j0` was combined with `--ipa` or `--ipu`
This commit is contained in:
parent
cb81f0ad6d
commit
3a0d882c5e
|
@ -223,7 +223,7 @@ class SvcHub(object):
|
||||||
args.chpw_no = noch
|
args.chpw_no = noch
|
||||||
|
|
||||||
if args.ipu:
|
if args.ipu:
|
||||||
iu, nm = load_ipu(self.log, args.ipu)
|
iu, nm = load_ipu(self.log, args.ipu, True)
|
||||||
setattr(args, "ipu_iu", iu)
|
setattr(args, "ipu_iu", iu)
|
||||||
setattr(args, "ipu_nm", nm)
|
setattr(args, "ipu_nm", nm)
|
||||||
|
|
||||||
|
@ -378,6 +378,14 @@ class SvcHub(object):
|
||||||
|
|
||||||
self.broker = Broker(self)
|
self.broker = Broker(self)
|
||||||
|
|
||||||
|
# create netmaps early to avoid firewall gaps,
|
||||||
|
# but the mutex blocks multiprocessing startup
|
||||||
|
for zs in "ipu_iu ftp_ipa_nm tftp_ipa_nm".split():
|
||||||
|
try:
|
||||||
|
getattr(args, zs).mutex = threading.Lock()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
def setup_session_db(self) -> None:
|
def setup_session_db(self) -> None:
|
||||||
if not HAVE_SQLITE3:
|
if not HAVE_SQLITE3:
|
||||||
self.args.no_ses = True
|
self.args.no_ses = True
|
||||||
|
@ -761,8 +769,8 @@ class SvcHub(object):
|
||||||
al.idp_h_grp = al.idp_h_grp.lower()
|
al.idp_h_grp = al.idp_h_grp.lower()
|
||||||
al.idp_h_key = al.idp_h_key.lower()
|
al.idp_h_key = al.idp_h_key.lower()
|
||||||
|
|
||||||
al.ftp_ipa_nm = build_netmap(al.ftp_ipa or al.ipa)
|
al.ftp_ipa_nm = build_netmap(al.ftp_ipa or al.ipa, True)
|
||||||
al.tftp_ipa_nm = build_netmap(al.tftp_ipa or al.ipa)
|
al.tftp_ipa_nm = build_netmap(al.tftp_ipa or al.ipa, True)
|
||||||
|
|
||||||
mte = ODict.fromkeys(DEF_MTE.split(","), True)
|
mte = ODict.fromkeys(DEF_MTE.split(","), True)
|
||||||
al.mte = odfusion(mte, al.mte)
|
al.mte = odfusion(mte, al.mte)
|
||||||
|
|
|
@ -669,13 +669,20 @@ class HLog(logging.Handler):
|
||||||
|
|
||||||
class NetMap(object):
|
class NetMap(object):
|
||||||
def __init__(
|
def __init__(
|
||||||
self, ips: list[str], cidrs: list[str], keep_lo=False, strict_cidr=False
|
self,
|
||||||
|
ips: list[str],
|
||||||
|
cidrs: list[str],
|
||||||
|
keep_lo=False,
|
||||||
|
strict_cidr=False,
|
||||||
|
defer_mutex=False,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
ips: list of plain ipv4/ipv6 IPs, not cidr
|
ips: list of plain ipv4/ipv6 IPs, not cidr
|
||||||
cidrs: list of cidr-notation IPs (ip/prefix)
|
cidrs: list of cidr-notation IPs (ip/prefix)
|
||||||
"""
|
"""
|
||||||
self.mutex = threading.Lock()
|
|
||||||
|
# fails multiprocessing; defer assignment
|
||||||
|
self.mutex: Optional[threading.Lock] = None if defer_mutex else threading.Lock()
|
||||||
|
|
||||||
if "::" in ips:
|
if "::" in ips:
|
||||||
ips = [x for x in ips if x != "::"] + list(
|
ips = [x for x in ips if x != "::"] + list(
|
||||||
|
@ -714,6 +721,9 @@ class NetMap(object):
|
||||||
try:
|
try:
|
||||||
return self.cache[ip]
|
return self.cache[ip]
|
||||||
except:
|
except:
|
||||||
|
# intentionally crash the calling thread if unset:
|
||||||
|
assert self.mutex # type: ignore # !rm
|
||||||
|
|
||||||
with self.mutex:
|
with self.mutex:
|
||||||
return self._map(ip)
|
return self._map(ip)
|
||||||
|
|
||||||
|
@ -2654,7 +2664,7 @@ def list_ips() -> list[str]:
|
||||||
return list(ret)
|
return list(ret)
|
||||||
|
|
||||||
|
|
||||||
def build_netmap(csv: str):
|
def build_netmap(csv: str, defer_mutex: bool = False):
|
||||||
csv = csv.lower().strip()
|
csv = csv.lower().strip()
|
||||||
|
|
||||||
if csv in ("any", "all", "no", ",", ""):
|
if csv in ("any", "all", "no", ",", ""):
|
||||||
|
@ -2689,10 +2699,12 @@ def build_netmap(csv: str):
|
||||||
cidrs.append(zs)
|
cidrs.append(zs)
|
||||||
|
|
||||||
ips = [x.split("/")[0] for x in cidrs]
|
ips = [x.split("/")[0] for x in cidrs]
|
||||||
return NetMap(ips, cidrs, True)
|
return NetMap(ips, cidrs, True, False, defer_mutex)
|
||||||
|
|
||||||
|
|
||||||
def load_ipu(log: "RootLogger", ipus: list[str]) -> tuple[dict[str, str], NetMap]:
|
def load_ipu(
|
||||||
|
log: "RootLogger", ipus: list[str], defer_mutex: bool = False
|
||||||
|
) -> tuple[dict[str, str], NetMap]:
|
||||||
ip_u = {"": "*"}
|
ip_u = {"": "*"}
|
||||||
cidr_u = {}
|
cidr_u = {}
|
||||||
for ipu in ipus:
|
for ipu in ipus:
|
||||||
|
@ -2709,7 +2721,7 @@ def load_ipu(log: "RootLogger", ipus: list[str]) -> tuple[dict[str, str], NetMap
|
||||||
cidr_u[cidr] = uname
|
cidr_u[cidr] = uname
|
||||||
ip_u[cip] = uname
|
ip_u[cip] = uname
|
||||||
try:
|
try:
|
||||||
nm = NetMap(["::"], list(cidr_u.keys()), True, True)
|
nm = NetMap(["::"], list(cidr_u.keys()), True, True, defer_mutex)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
t = "failed to translate --ipu into netmap, probably due to invalid config: %r"
|
t = "failed to translate --ipu into netmap, probably due to invalid config: %r"
|
||||||
log("root", t % (ex,), 1)
|
log("root", t % (ex,), 1)
|
||||||
|
|
Loading…
Reference in a new issue