diff --git a/src/server.py b/src/server.py --- a/src/server.py +++ b/src/server.py @@ -133,15 +133,16 @@ class Server(NetNode): if not self.isLocked(): self._lock() log.info("received data block #{0}: {1}...{2}".format(jsonData["index"],binData[:5],binData[-5:])) - i=jsonData["index"] - if self._lastIndex+1!=i: - self._dataFile.seek(i*self.BLOCK_SIZE) - self._dataFile.write(binData) - self._lastIndex=i - if self._treeFile: - self._newLeaves[i+self._tree.leafStart]=hashBlock(binData) + indices=jsonData["index"] + for (i,k) in enumerate(indices): + if self._lastIndex+1!=k: + self._dataFile.seek(k*self.BLOCK_SIZE) + self._dataFile.write(binData[i*self.BLOCK_SIZE:(i+1)*self.BLOCK_SIZE]) + self._lastIndex=k + if self._treeFile: + self._newLeaves[k+self._tree.leafStart]=hashBlock(binData) - return ({"command": "ack", "index": i},) + return ({"command": "ack", "index": indices},) def _finalize(self): log.info("closing session...")