mirror of
https://github.com/PurpleI2P/pyseeder
synced 2025-01-30 08:34:22 +00:00
add yggdrasil seeds amount option
This commit is contained in:
parent
0c798550d1
commit
e5e39fe77e
@ -33,7 +33,7 @@ def reseed(args):
|
||||
priv_key_password = input().encode("utf-8")
|
||||
|
||||
su3file = SU3File(args.signer_id)
|
||||
su3file.reseed(args.netdb)
|
||||
su3file.reseed(args.netdb, args.yggseeds)
|
||||
su3file.write(args.outfile, args.private_key, priv_key_password)
|
||||
|
||||
def transport_pull(args):
|
||||
|
@ -55,6 +55,8 @@ echo $YOUR_PASSWORD | %(prog)s --netdb /path/to/netDb \\
|
||||
help="Path to netDb folder (example: ~/.i2pd/netDb)")
|
||||
rs_parser.add_argument("--no-encryption", action="store_true",
|
||||
help="Disable private key encryption")
|
||||
rs_parser.add_argument("--yggseeds", type=int, default=0,
|
||||
help="Amount of yggdrasil seeds to include to reseed")
|
||||
rs_parser.set_defaults(func=pyseeder.actions.reseed)
|
||||
|
||||
|
||||
|
@ -50,22 +50,52 @@ class SU3File:
|
||||
|
||||
pyseeder.crypto.append_signature(filename, priv_key, priv_key_password)
|
||||
|
||||
def reseed(self, netdb):
|
||||
def reseed(self, netdb, yggseeds):
|
||||
"""Compress netdb entries and set content"""
|
||||
seeds = 75
|
||||
zip_file = io.BytesIO()
|
||||
dat_files = []
|
||||
dat_yggfiles = []
|
||||
|
||||
if yggseeds > 0:
|
||||
import re
|
||||
pattern = re.compile(b'host=.[23]..:')
|
||||
|
||||
timelimit = time.time() - float(3600 * 10) # current time minus 10 hours
|
||||
|
||||
for root, dirs, files in os.walk(netdb):
|
||||
for f in files:
|
||||
if f.endswith(".dat"):
|
||||
# TODO check modified time
|
||||
# may be not older than 10h
|
||||
dat_files.append(os.path.join(root, f))
|
||||
path = os.path.join(root, f)
|
||||
file_added = False
|
||||
|
||||
if os.path.getmtime(path) < timelimit: # modified time older than 10h
|
||||
continue
|
||||
|
||||
if yggseeds > 0:
|
||||
for line in open(path, "rb"):
|
||||
if pattern.search(line):
|
||||
dat_yggfiles.append(path)
|
||||
file_added = True
|
||||
break
|
||||
|
||||
if not file_added:
|
||||
dat_files.append(path)
|
||||
|
||||
|
||||
if yggseeds > 0:
|
||||
if len(dat_yggfiles) == 0:
|
||||
raise PyseederException("Can't get enough netDb entries with yggdrasil addresses")
|
||||
elif len(dat_yggfiles) > yggseeds:
|
||||
dat_yggfiles = random.sample(dat_yggfiles, yggseeds)
|
||||
seeds = seeds - len(dat_yggfiles)
|
||||
|
||||
if len(dat_files) == 0:
|
||||
raise PyseederException("Can't get enough netDb entries")
|
||||
elif len(dat_files) > 75:
|
||||
dat_files = random.sample(dat_files, 75)
|
||||
elif len(dat_files) > seeds:
|
||||
dat_files = random.sample(dat_files, seeds)
|
||||
|
||||
dat_files.extend(dat_yggfiles)
|
||||
|
||||
with ZipFile(zip_file, "w", compression=ZIP_DEFLATED) as zf:
|
||||
for f in dat_files:
|
||||
|
Loading…
x
Reference in New Issue
Block a user