Changeset - e3c116b7dc5c
[Not reviewed]
default
0 2 0
Laman - 7 years ago 2018-03-03 12:40:20

bugfix: really recover from a failed ssl connection
2 files changed with 9 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/morevna.py
Show inline comments
 
@@ -84,11 +84,12 @@ def serve(args):
 
	if args.host: conf.hosts.insert(0,args.host)
 
	if args.port: conf.port=args.port
 

	
 
	s=Miniserver(args.datafile,args.tree)
 
	try:
 
		s=Miniserver(args.datafile,args.tree)
 
		spawnDaemon(s.serve)
 
	except Exception as e:
 
		log.exception("exception: %s",e)
 
		print("Failed to start:\n  ",e)
 

	
 

	
 
parser=ArgumentParser()
src/server.py
Show inline comments
 
@@ -15,9 +15,11 @@ class Connection(BaseConnection):
 
		super().__init__()
 

	
 
		sock, address = serverSocket.accept()
 
		try: self._socket=sslContext.wrap_socket(sock,server_side=True)
 
		peer=sock.getpeername()
 
		try:
 
			self._socket=sslContext.wrap_socket(sock,server_side=True)
 
		except ssl.SSLError as e:
 
			log.warning("Failed to establish an SSL connection from {0}.".format(sock.getpeername()))
 
			log.warning("Failed to establish an SSL connection from {0}.".format(peer))
 
			raise e
 

	
 
		log.info('Connected by {0}'.format(address))
 
@@ -114,7 +116,7 @@ class Server(NetNode):
 
		return True
 

	
 
	def _requestHash(self,indices):
 
		log.info("received request for nodes #{0}".format(",".join(str(i) for i in indices)))
 
		log.info("received request for nodes {0}".format(indices))
 
		assert all(i<len(self._tree.store) for i in indices)
 
		hashes=[self._tree.store[i] for i in indices]
 

	
 
@@ -124,7 +126,7 @@ class Server(NetNode):
 
		return (jsonResponse,binResponse)
 

	
 
	def _requestData(self,index):
 
		log.info("received request for data block #{0}".format(index))
 
		log.info("received request for data blocks {0}".format(index))
 

	
 
		jsonResponse={"command":"send", "index":index, "dataType":"data"}
 
		blocks=[]
 
@@ -135,7 +137,7 @@ class Server(NetNode):
 

	
 
	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:]))
 
		log.info("received data blocks {0}: {1}...{2}".format(jsonData["index"],binData[:5],binData[-5:]))
 

	
 
		indices=jsonData["index"]
 
		for (i,k) in enumerate(indices):
0 comments (0 inline, 0 general)