Changeset - 9f2b0a4f3538
[Not reviewed]
default
0 6 0
Laman - 7 years ago 2017-10-31 19:45:36

push to multiple servers
6 files changed with 23 insertions and 16 deletions:
0 comments (0 inline, 0 general)
src/client.py
Show inline comments
 
@@ -13,7 +13,7 @@ from netnode import BaseConnection,NetNo
 

	
 

	
 
class Connection(BaseConnection):
 
	def __init__(self):
 
	def __init__(self,host,port):
 
		super().__init__()
 
		sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 

	
 
@@ -23,7 +23,7 @@ class Connection(BaseConnection):
 

	
 
		self._socket=sslContext.wrap_socket(sock)
 
		try:
 
			self._socket.connect((conf.hosts[0], conf.port))
 
			self._socket.connect((host,port))
 
		except ConnectionRefusedError:
 
			print("Couldn't connect to {0}:{1}".format(conf.hosts[0],conf.port))
 
			sys.exit(1)
src/morevna.py
Show inline comments
 
@@ -3,7 +3,7 @@ import os.path
 
import logging as log
 
from argparse import ArgumentParser
 

	
 
from util import spawnDaemon
 
from util import spawnDaemon, splitHost
 
import config as conf
 
import stats
 
from hashtree import HashTree
 
@@ -33,26 +33,27 @@ def push(args):
 
	_checkFile(args.datafile)
 
	if args.tree:
 
		_checkFile(args.tree)
 
	if args.host: conf.hosts.insert(0,args.host)
 
	if args.host: conf.hosts=[args.host]
 
	if args.port: conf.port=args.port
 

	
 
	c=Client(args.datafile,args.tree)
 
	with ClientConnection() as con:
 
		c.setConnection(con)
 
		blocksToTransfer=c.negotiate()
 
		c.sendData(blocksToTransfer)
 
	print()
 
	print(stats.report())
 
	for host in conf.hosts:
 
		with ClientConnection(*splitHost(host,conf.port)) as con:
 
			c.setConnection(con)
 
			blocksToTransfer=c.negotiate()
 
			c.sendData(blocksToTransfer)
 
		print()
 
		print(stats.report())
 

	
 
def pull(args):
 
	_checkFile(args.datafile)
 
	if args.tree:
 
		_checkFile(args.tree)
 
	if args.host: conf.hosts.insert(0,args.host)
 
	if args.host: conf.hosts=[args.host]
 
	if args.port: conf.port=args.port
 

	
 
	c=Client(args.datafile,args.tree)
 
	with ClientConnection() as con:
 
	with ClientConnection(*splitHost(conf.hosts[0],conf.port)) as con:
 
		c.setConnection(con)
 
		blocksToTransfer=c.negotiate()
 
		c.pullData(blocksToTransfer)
src/netnode.py
Show inline comments
 
@@ -26,7 +26,7 @@ class BaseConnection: # abstract
 
			self._socket.shutdown(socket.SHUT_RDWR)
 
			self._socket.close()
 
		except OSError:
 
			log.warning("encountered an error when shutting down the connection")
 
			log.warning("broken connection")
 

	
 

	
 
class NetNode:
src/server.py
Show inline comments
 
@@ -64,7 +64,7 @@ class Server(NetNode):
 
	def serve(self):
 
		try:
 
			while self._serveOne(): pass
 
		except AssertionError as e:
 
		except (AssertionError,ConnectionResetError) as e:
 
			log.warning(e)
 

	
 
	def _serveOne(self):
src/tests/test_overall.py
Show inline comments
 
@@ -68,7 +68,7 @@ class TestMorevna(TestCase):
 
		for clientFile in ("test2.img","test3.img","test4.img"):
 
			clientFile=os.path.join(dataDir,clientFile)
 
			c=Client(clientFile)
 
			with ClientConnection() as con:
 
			with ClientConnection("127.0.0.1",config.port) as con:
 
				c.setConnection(con)
 
				blocksToTransfer=c.negotiate()
 
				c.sendData(blocksToTransfer)
 
@@ -85,7 +85,7 @@ class TestMorevna(TestCase):
 
		p.start()
 

	
 
		c=Client(filename)
 
		with ClientConnection() as con:
 
		with ClientConnection("127.0.0.1",config.port) as con:
 
			c.setConnection(con)
 
			blocksToTransfer=c.negotiate()
 
			c.pullData(blocksToTransfer)
src/util.py
Show inline comments
 
@@ -33,6 +33,12 @@ def spawnDaemon(fun):
 
	os._exit(os.EX_OK)
 

	
 

	
 
def splitHost(host,defaultPort=0):
 
	address,_,port=host.partition(":")
 
	if not port: port=defaultPort
 
	return (address,port)
 

	
 

	
 
class Progress:
 
	def __init__(self,n,i0=0):
 
		self._n=n
0 comments (0 inline, 0 general)