Changeset - 095908159393
[Not reviewed]
default
0 3 0
Laman - 8 years ago 2017-10-28 12:26:02

handled connection error, skipped needless tree rebuild
3 files changed with 16 insertions and 3 deletions:
0 comments (0 inline, 0 general) First comment
src/client.py
Show inline comments
 
@@ -25,7 +25,7 @@ class Connection(BaseConnection):
 
		try:
 
			self._socket.connect((conf.hosts[0], conf.port))
 
		except ConnectionRefusedError:
 
			print("Couldn't connect to {0}".format(conf.hosts[0]))
 
			print("Couldn't connect to {0}:{1}".format(conf.hosts[0],conf.port))
 
			sys.exit(1)
 

	
 
		self.createNetworkers()
 
@@ -81,6 +81,9 @@ class Client(NetNode):
 
			nodeStack.extend(reversed(frontier))
 
		progress.done()
 

	
 
		size=stats.formatBytes(len(blocksToTransfer)*self._tree.BLOCK_SIZE)
 
		print(datetime.now(), "{0} to transfer".format(size))
 

	
 
		return blocksToTransfer
 

	
 
	def sendData(self,blocksToTransfer):
src/morevna.py
Show inline comments
 
@@ -19,6 +19,12 @@ def _checkFile(f):
 

	
 
def buildTree(args):
 
	_checkFile(args.datafile)
 
	if os.path.isfile(args.treefile):
 
		treeMod=os.stat(args.treefile).st_mtime
 
		dataMod=os.stat(args.datafile).st_mtime
 
		if dataMod<treeMod and not args.force:
 
			print("tree file is up to date")
 
			return
 

	
 
	tree=HashTree.fromFile(args.datafile)
 
	tree.save(args.treefile)
 
@@ -71,6 +77,7 @@ parser=ArgumentParser()
 
subparsers=parser.add_subparsers()
 

	
 
pBuild=subparsers.add_parser("build")
 
pBuild.add_argument("-f","--force",action="store_true",help="force tree rebuild")
 
pBuild.add_argument("treefile", help="stored hash tree location")
 
pBuild.add_argument("datafile")
 
pBuild.set_defaults(func=buildTree)
src/netnode.py
Show inline comments
 
@@ -22,8 +22,11 @@ class BaseConnection: # abstract
 
		return self.incoming,self.outcoming
 

	
 
	def __exit__(self, exc_type, exc_val, exc_tb):
 
		self._socket.shutdown(socket.SHUT_RDWR)
 
		self._socket.close()
 
		try:
 
			self._socket.shutdown(socket.SHUT_RDWR)
 
			self._socket.close()
 
		except OSError:
 
			log.warning("encountered an error when shutting down the connection")
 

	
 

	
 
class NetNode:
0 comments (0 inline, 0 general) First comment
You need to be logged in to comment. Login now