Changeset - 870c5c6c334f
[Not reviewed]
default
0 3 0
Laman - 5 years ago 2020-05-24 21:55:14

reacquiring old locks
3 files changed with 15 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/client.py
Show inline comments
 
@@ -163,14 +163,16 @@ class Client(NetNode):
 

	
 
				log.info("block #{0}: {1}...{2}".format(i, block[:5], block[-5:]))
 
				if self._tree_file:
 
					self._new_leaves[i+self._tree.leaf_start] = hash_block(block)
 

	
 
					t = datetime.now().timestamp()
 
					if t-last_flushed >= 60 and self._tree_file:
 
					if t-last_flushed >= 60:
 
						if self._tree_file:
 
						self._update_tree()
 
						self._refresh_lock()
 
						last_flushed = t
 

	
 
				stats.log_transferred_block()
 
				progress.p(k+j)
 
		progress.done()
 

	
src/netnode.py
Show inline comments
 
import os
 
from datetime import datetime
 
import socket
 
import logging as log
 

	
 
import config as conf
 
from networkers import NetworkReader, NetworkWriter
 
from hashtree import HashTree
 
@@ -59,13 +60,21 @@ class NetNode:
 

	
 
	def _lock(self):
 
		try:
 
			f = open(lock_file, "x")
 
			f.close()
 
		except FileExistsError:
 
			stat = os.stat(lock_file)
 
			dt = datetime.now().timestamp()-stat.st_mtime
 
			if dt<5*60:
 
			raise LockedException()
 
			log.warning("Found an old lock file ({0}s), ignoring it.".format(round(dt)))
 
			self._refresh_lock()
 

	
 
	def _refresh_lock(self):
 
		os.utime(lock_file)
 

	
 
	def _unlock(self):
 
		os.remove(lock_file)
 

	
 
	def _update_tree(self):
 
		log.info("updating hash tree...")
src/server.py
Show inline comments
 
@@ -147,14 +147,16 @@ class Server(NetNode):
 
			block = bin_data[i*self.BLOCK_SIZE:(i+1)*self.BLOCK_SIZE]
 
			self._data_file.write_at(k, block)
 
			if self._tree_file:
 
				self._new_leaves[k+self._tree.leaf_start] = hash_block(block)
 

	
 
		t = datetime.now().timestamp()
 
		if t-self._last_flushed>=60 and self._tree_file:
 
		if t-self._last_flushed>=60:
 
			if self._tree_file:
 
			self._update_tree()
 
			self._refresh_lock()
 
			self._last_flushed = t
 

	
 
		return ({"command": "ack", "index": indices},)
 

	
 
	def _finalize(self):
 
		log.info("closing session...")
0 comments (0 inline, 0 general)