Browse Source

random timing for minimail

PYADPT-55
Volker Birk 5 years ago
parent
commit
dcbbbca020
  1. 20
      test/minimail.py
  2. 11
      test/sync_handshake.py
  3. 6
      test/sync_test.py
  4. 2
      utils/pEp

20
test/minimail.py

@ -13,8 +13,8 @@ delete the marker file to re-read all messages
""" """
# Minimail 1.1 # Minimail 1.2
# Copyleft 2019, p≡p foundation # Copyleft 2019, 2020, p≡p foundation
# this file is under GNU General Public License 3.0 # this file is under GNU General Public License 3.0
@ -22,11 +22,19 @@ delete the marker file to re-read all messages
import os import os
from secrets import token_urlsafe from secrets import token_urlsafe
from time import sleep from time import sleep
from random import random
timing = .1 # set timing to None for random timing
timing = None
def snooze():
if timing is None:
sleep(random()/2)
else:
sleep(timing)
def unlock(inbox): def unlock(inbox):
"clear the inbox from lockfile" "clear the inbox from lockfile"
@ -49,14 +57,14 @@ class Lock:
def __enter__(self): def __enter__(self):
lockfile = self.inbox / "lock" lockfile = self.inbox / "lock"
while lockfile.is_file(): while lockfile.is_file():
sleep(timing) snooze()
lockfile.touch() lockfile.touch()
def send(inbox, msg, marker): def send(inbox, msg, marker):
"send msg to inbox in MIME format" "send msg to inbox in MIME format"
sleep(timing) snooze()
with Lock(inbox): with Lock(inbox):
name = marker + "_" + token_urlsafe(16) + ".eml" name = marker + "_" + token_urlsafe(16) + ".eml"
with open(inbox / name, "wb") as f: with open(inbox / name, "wb") as f:
@ -95,7 +103,7 @@ def recv_all(inbox, marker):
txt = f.read(-1) txt = f.read(-1)
r.append((p, txt)) r.append((p, txt))
if not r: if not r:
sleep(timing) snooze()
return r return r

11
test/sync_handshake.py

@ -130,10 +130,11 @@ class UserInterface(pEp.UserInterface):
]) ])
sleep(.5) # user is reading message sleep(.5) # user is reading message
try: try:
if options.reject: if not options.noanswer:
self.deliverHandshakeResult(SYNC_HANDSHAKE_REJECTED) if options.reject:
else: self.deliverHandshakeResult(SYNC_HANDSHAKE_REJECTED)
self.deliverHandshakeResult(SYNC_HANDSHAKE_ACCEPTED) else:
self.deliverHandshakeResult(SYNC_HANDSHAKE_ACCEPTED)
except NameError: except NameError:
self.deliverHandshakeResult(SYNC_HANDSHAKE_ACCEPTED) self.deliverHandshakeResult(SYNC_HANDSHAKE_ACCEPTED)
@ -234,6 +235,8 @@ if __name__=="__main__":
help="reject device group") help="reject device group")
optParser.add_option("--accept", action="store_false", dest="reject", optParser.add_option("--accept", action="store_false", dest="reject",
help="accept device group (default)") help="accept device group (default)")
optParser.add_option("--no-answer", action="store_true", dest="noanswer",
help="do not answer device group handshake")
optParser.add_option("-E", "--end-on", dest="notifications", optParser.add_option("-E", "--end-on", dest="notifications",
help="end test on these notifications") help="end test on these notifications")
optParser.add_option("-j", "--multi-threaded", action="store_true", optParser.add_option("-j", "--multi-threaded", action="store_true",

6
test/sync_test.py

@ -102,6 +102,10 @@ if __name__ == "__main__":
optParser.add_option("-i", "--imap", action="store_true", optParser.add_option("-i", "--imap", action="store_true",
dest="imap", dest="imap",
help="use imap instead of minimail") help="use imap instead of minimail")
optParser.add_option("-A", "--add-account-after-sync", action="store_true",
dest="add_account",
help="after sync add an account")
options, args = optParser.parse_args() options, args = optParser.parse_args()
if options.imap: if options.imap:
@ -207,7 +211,7 @@ if __name__ == "__main__":
# Phone runs with own_ident = 2 # Phone runs with own_ident = 2
Phone = Process(target=test_for, args=("Phone", "red", end_on, Phone = Process(target=test_for, args=("Phone", "red", end_on,
options.multithreaded, options.imap, 2)) options.multithreaded, options.imap, 1))
# others run with own_ident = 1 # others run with own_ident = 1
Laptop = Process(target=test_for, args=("Laptop", "green", end_on, Laptop = Process(target=test_for, args=("Laptop", "green", end_on,

2
utils/pEp

@ -72,7 +72,7 @@ try:
dst = src.encrypt() dst = src.encrypt()
else: else:
src.dir = 0 src.dir = 0
dst, keys, rating, consumed, flags = src.decrypt() dst, keys, rating, flags = src.decrypt()
print(str(dst)) print(str(dst))

Loading…
Cancel
Save