diff --git a/src/server.py b/src/server.py --- a/src/server.py +++ b/src/server.py @@ -71,9 +71,12 @@ class Server(NetNode): jsonData,binData=self._incoming.readMsg() if jsonData["command"]=="init": - assert jsonData["blockSize"]==self.BLOCK_SIZE - assert jsonData["blockCount"]==self._tree.leafCount - self._outcoming.writeMsg({"command": "ack"}) + if jsonData["blockSize"]!=self.BLOCK_SIZE or jsonData["blockCount"]!=self._tree.leafCount: + self._outcoming.writeMsg({"command":"deny"}) + if jsonData["action"]=="pull" and self.isLocked(): + self._outcoming.writeMsg({"command":"deny"}) + + self._outcoming.writeMsg({"command":"init", "version":conf.version}) elif jsonData["command"]=="req": if jsonData["dataType"]=="data": @@ -86,7 +89,7 @@ class Server(NetNode): elif jsonData["command"]=="end": self._finalize() - self._locked=False + if jsonData.get("action")=="push": self._unlock() return False else: @@ -115,6 +118,7 @@ class Server(NetNode): return (jsonResponse,binResponse) def _receiveData(self,jsonData,binData): + if not self.isLocked(): self._lock() log.info("received data block #{0}: {1}...{2}".format(jsonData["index"],binData[:5],binData[-5:])) i=jsonData["index"]