ota_mesh_push.py --resume: continue a stopped transfer; a lost missing reply no longer ends it
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d9c7b9c008
commit
f7bd88c1c8
1 file changed
+45
-9
+45
-9
@@ -31,6 +31,9 @@
|
|||||||
unanswered, missing ones found by a bitmap query). Falls
|
unanswered, missing ones found by a bitmap query). Falls
|
||||||
back to text by itself when the node does not answer the
|
back to text by itself when the node does not answer the
|
||||||
binary query (older firmware, or the sensor build).
|
binary query (older firmware, or the sensor build).
|
||||||
|
--resume continue a transfer that stopped (the node keeps what it got
|
||||||
|
until the next `fw begin` or a reboot): no begin, only the
|
||||||
|
chunks `fw missing` lists, as text, then verify (and --apply)
|
||||||
--wait S how long to wait for the dest's advert if the companion
|
--wait S how long to wait for the dest's advert if the companion
|
||||||
does not know it yet (default 120 s); send `advert.zerohop`
|
does not know it yet (default 120 s); send `advert.zerohop`
|
||||||
on the dest meanwhile
|
on the dest meanwhile
|
||||||
@@ -375,12 +378,20 @@ async def run(args: argparse.Namespace) -> int:
|
|||||||
t0 = time.time()
|
t0 = time.time()
|
||||||
|
|
||||||
print("status:", await link.cmd("fw status"))
|
print("status:", await link.cmd("fw status"))
|
||||||
sid = random.randint(1, 0xFFFF) # chunks of an earlier transfer are dropped
|
if args.resume:
|
||||||
r = await link.cmd(f"fw begin {len(data)} {sid}")
|
# `fw begin` would wipe what the node has; text chunks need no session
|
||||||
print("begin:", r)
|
r = await link.cmd("fw missing")
|
||||||
if not r.startswith("OK"):
|
print("missing:", r)
|
||||||
return 1
|
if not r.startswith(">"):
|
||||||
binary = None if args.text else Binary(link)
|
return 1
|
||||||
|
sid = 0
|
||||||
|
else:
|
||||||
|
sid = random.randint(1, 0xFFFF) # chunks of an earlier transfer are dropped
|
||||||
|
r = await link.cmd(f"fw begin {len(data)} {sid}")
|
||||||
|
print("begin:", r)
|
||||||
|
if not r.startswith("OK"):
|
||||||
|
return 1
|
||||||
|
binary = None if (args.text or args.resume) else Binary(link)
|
||||||
if binary:
|
if binary:
|
||||||
binary.sid = sid
|
binary.sid = sid
|
||||||
text_todo: list[int] | None = None
|
text_todo: list[int] | None = None
|
||||||
@@ -395,8 +406,15 @@ async def run(args: argparse.Namespace) -> int:
|
|||||||
last_miss = 1 << 30
|
last_miss = 1 << 30
|
||||||
|
|
||||||
async def settled():
|
async def settled():
|
||||||
|
lost = 0
|
||||||
for _ in range(10):
|
for _ in range(10):
|
||||||
st = await binary.missing()
|
st = await binary.missing()
|
||||||
|
if st is None and lost < 4:
|
||||||
|
# a lost query or reply after a 40-minute round must not
|
||||||
|
# throw the round away (14. 11. 2026, mast-three: it did)
|
||||||
|
lost += 1
|
||||||
|
await asyncio.sleep(10)
|
||||||
|
continue
|
||||||
if st is None or st[0] != 4: # 4 = busy (manifest check)
|
if st is None or st[0] != 4: # 4 = busy (manifest check)
|
||||||
return st
|
return st
|
||||||
await asyncio.sleep(3)
|
await asyncio.sleep(3)
|
||||||
@@ -426,7 +444,7 @@ async def run(args: argparse.Namespace) -> int:
|
|||||||
print()
|
print()
|
||||||
st = await settled()
|
st = await settled()
|
||||||
if st is None:
|
if st is None:
|
||||||
print("missing: no answer")
|
print("missing: no answer (the node keeps what it has: --resume)")
|
||||||
return 1
|
return 1
|
||||||
state, miss = st
|
state, miss = st
|
||||||
print(f"missing: state {state}, {len(miss)} units")
|
print(f"missing: state {state}, {len(miss)} units")
|
||||||
@@ -447,9 +465,15 @@ async def run(args: argparse.Namespace) -> int:
|
|||||||
todo = []
|
todo = []
|
||||||
elif text_todo is not None:
|
elif text_todo is not None:
|
||||||
todo = text_todo # only what the binary rounds did not deliver
|
todo = text_todo # only what the binary rounds did not deliver
|
||||||
|
elif args.resume:
|
||||||
|
# `fw missing` lists ~23 offsets per reply: rounds go on while they help
|
||||||
|
todo = []
|
||||||
|
if not r.endswith("none"):
|
||||||
|
todo = [int(x) // CHUNK for x in r.lstrip(">").split()]
|
||||||
else:
|
else:
|
||||||
todo = list(range((len(data) + CHUNK - 1) // CHUNK))
|
todo = list(range((len(data) + CHUNK - 1) // CHUNK))
|
||||||
for rnd in range(4 if todo else 0):
|
stuck = 0
|
||||||
|
for rnd in range(40 if todo else 0):
|
||||||
for k, i in enumerate(todo):
|
for k, i in enumerate(todo):
|
||||||
off = i * CHUNK
|
off = i * CHUNK
|
||||||
r = await link.cmd(
|
r = await link.cmd(
|
||||||
@@ -469,7 +493,18 @@ async def run(args: argparse.Namespace) -> int:
|
|||||||
print("missing:", r)
|
print("missing:", r)
|
||||||
if r.endswith("none"):
|
if r.endswith("none"):
|
||||||
break
|
break
|
||||||
todo = [int(x) // CHUNK for x in r.lstrip(">").split()]
|
if not r.startswith(">"):
|
||||||
|
stuck += 1 # a lost reply: ask again next round
|
||||||
|
if stuck > 3:
|
||||||
|
print("fw missing does not answer, giving up (--resume continues)")
|
||||||
|
return 1
|
||||||
|
continue
|
||||||
|
new = [int(x) // CHUNK for x in r.lstrip(">").split()]
|
||||||
|
stuck = stuck + 1 if new == todo else 0
|
||||||
|
if stuck > 3:
|
||||||
|
print("the same chunks keep missing, giving up")
|
||||||
|
return 1
|
||||||
|
todo = new
|
||||||
r = await link.cmd("fw verify", timeout=40)
|
r = await link.cmd("fw verify", timeout=40)
|
||||||
for _ in range(20): # the node runs it in loop(), not in the handler
|
for _ in range(20): # the node runs it in loop(), not in the handler
|
||||||
if "verifying" not in r:
|
if "verifying" not in r:
|
||||||
@@ -512,6 +547,7 @@ def main() -> None:
|
|||||||
ap.add_argument("--gap", type=float, default=5.0)
|
ap.add_argument("--gap", type=float, default=5.0)
|
||||||
ap.add_argument("--via")
|
ap.add_argument("--via")
|
||||||
ap.add_argument("--text", action="store_true")
|
ap.add_argument("--text", action="store_true")
|
||||||
|
ap.add_argument("--resume", action="store_true")
|
||||||
sys.exit(asyncio.run(run(ap.parse_args())))
|
sys.exit(asyncio.run(run(ap.parse_args())))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user