diff --git a/src/client.py b/src/client.py --- a/src/client.py +++ b/src/client.py @@ -109,20 +109,24 @@ class Client(NetNode): print(datetime.now(), "sending data:") progress=Progress(len(blocksToTransfer)) - for (k,i2) in enumerate(blocksToTransfer): - jsonData={"command":"send", "index":i2, "dataType":"data"} - if i1+1!=i2: - dataFile.seek(i2*HashTree.BLOCK_SIZE) - binData=dataFile.read(HashTree.BLOCK_SIZE) - log.info("block #{0}: {1}...{2}".format(i2,binData[:5],binData[-5:])) + for k in range(0,len(blocksToTransfer),conf.batchSize): + indices=[] + blocks=[] + for j in range(conf.batchSize): + if k+j>=len(blocksToTransfer): break + i2=blocksToTransfer[k+j] + if i1+1!=i2: + dataFile.seek(i2*HashTree.BLOCK_SIZE) + block=dataFile.read(HashTree.BLOCK_SIZE) - self._outcoming.writeMsg(jsonData,binData) - stats.logTransferredBlock() - jsonData,binData=self._incoming.readMsg() - assert jsonData["command"]=="ack" and jsonData["index"]==i2, jsonData - i1=i2 - progress.p(k) + indices.append(i2) + blocks.append(block) + log.info("block #{0}: {1}...{2}".format(i2,block[:5],block[-5:])) + + i1=i2 + progress.p(k+j) + if indices: self._sendData(indices,blocks) progress.done() self._outcoming.writeMsg({"command":"end","action":"push"}) @@ -171,5 +175,13 @@ class Client(NetNode): if self._treeFile: self._updateTree() + def _sendData(self,indices,blocks): + jsonData={"command":"send", "index":indices, "dataType":"data"} + binData=b"".join(blocks) + self._outcoming.writeMsg(jsonData,binData) + stats.logTransferredBlock(len(indices)) + jsonData,binData=self._incoming.readMsg() + assert jsonData["command"]=="ack" and jsonData["index"]==indices, jsonData + def setConnection(self,connection): (self._incoming,self._outcoming)=connection