Browse Source

add yggdrasil seeds amount option

master
R4SAS 3 years ago
parent
commit
e5e39fe77e
  1. 2
      pyseeder/actions.py
  2. 2
      pyseeder/cli.py
  3. 42
      pyseeder/su3file.py

2
pyseeder/actions.py

@ -33,7 +33,7 @@ def reseed(args):
priv_key_password = input().encode("utf-8") priv_key_password = input().encode("utf-8")
su3file = SU3File(args.signer_id) 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) su3file.write(args.outfile, args.private_key, priv_key_password)
def transport_pull(args): def transport_pull(args):

2
pyseeder/cli.py

@ -55,6 +55,8 @@ echo $YOUR_PASSWORD | %(prog)s --netdb /path/to/netDb \\
help="Path to netDb folder (example: ~/.i2pd/netDb)") help="Path to netDb folder (example: ~/.i2pd/netDb)")
rs_parser.add_argument("--no-encryption", action="store_true", rs_parser.add_argument("--no-encryption", action="store_true",
help="Disable private key encryption") 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) rs_parser.set_defaults(func=pyseeder.actions.reseed)

42
pyseeder/su3file.py

@ -50,22 +50,52 @@ class SU3File:
pyseeder.crypto.append_signature(filename, priv_key, priv_key_password) 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""" """Compress netdb entries and set content"""
seeds = 75
zip_file = io.BytesIO() zip_file = io.BytesIO()
dat_files = [] 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 root, dirs, files in os.walk(netdb):
for f in files: for f in files:
if f.endswith(".dat"): if f.endswith(".dat"):
# TODO check modified time path = os.path.join(root, f)
# may be not older than 10h file_added = False
dat_files.append(os.path.join(root, f))
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: if len(dat_files) == 0:
raise PyseederException("Can't get enough netDb entries") raise PyseederException("Can't get enough netDb entries")
elif len(dat_files) > 75: elif len(dat_files) > seeds:
dat_files = random.sample(dat_files, 75) dat_files = random.sample(dat_files, seeds)
dat_files.extend(dat_yggfiles)
with ZipFile(zip_file, "w", compression=ZIP_DEFLATED) as zf: with ZipFile(zip_file, "w", compression=ZIP_DEFLATED) as zf:
for f in dat_files: for f in dat_files:

Loading…
Cancel
Save