diff --git a/src/client.py b/src/client.py --- a/src/client.py +++ b/src/client.py @@ -4,7 +4,7 @@ import logging as log from datetime import datetime import config as conf -from util import progress +from util import Progress from hashtree import HashTree from networkers import NetworkReader,NetworkWriter @@ -45,6 +45,7 @@ class Client: # determine which blocks to send print(datetime.now(), "negotiating:") + progress=Progress(localTree.leafCount) while len(nodeStack)>0: i=nodeStack.pop() outcoming.writeMsg({"command":"req", "index":i}) @@ -59,8 +60,8 @@ class Client: nodeStack.append(2*i+1) else: blocksToTransfer.append(i-localTree.leafStart) # leaf - progress(i-localTree.leafStart, localTree.leafCount) - print("100%") + progress.p(i-localTree.leafStart) + progress.done() return blocksToTransfer @@ -71,6 +72,7 @@ class Client: print(datetime.now(), "sending data:") with Connection() as (incoming,outcoming): + progress=Progress(len(blocksToTransfer)) for (k,i2) in enumerate(blocksToTransfer): jsonData={"command":"send", "index":i2, "dataType":"data"} if i1+1!=i2: @@ -83,8 +85,8 @@ class Client: jsonData,binData=incoming.readMsg() assert jsonData["command"]=="ack" and jsonData["index"]==i2, jsonData i1=i2 - progress(k,len(blocksToTransfer)) - print("100%") + progress.p(k) + progress.done() with Connection() as (incoming,outcoming): outcoming.writeMsg({"command":"end"})