Esempio n. 1
0
	def setUp(self):
		self.redisInstance = None
		with tempfile.NamedTemporaryFile() as fout:
			testSocket = os.tempnam() + os.urandom(4).encode('hex')
			fout.write('unixsocket ' + testSocket)
			fout.write(os.linesep)
			fout.write('loglevel warning')
			fout.write(os.linesep)
			fout.write('logfile ' + os.devnull)
			fout.write(os.linesep)
			fout.write('port 0')
			fout.write(os.linesep)
			fout.flush()
			self.redisInstance = subprocess.Popen(['redis-server',fout.name])
			
			for i in xrange(0,16):
				if os.path.exists(testSocket):
					break
				time.sleep(1)
			else:
				raise RuntimeError('redis-server did not start')
		
		self.peers = peers.Peers(vanilla.buildRedisConnectionPool(unix_socket_path=testSocket),0)
Esempio n. 2
0
    def setUp(self):
        self.redisInstance = None
        with tempfile.NamedTemporaryFile() as fout:
            testSocket = os.tempnam() + os.urandom(4).encode('hex')
            fout.write('unixsocket ' + testSocket)
            fout.write(os.linesep)
            fout.write('loglevel warning')
            fout.write(os.linesep)
            fout.write('logfile ' + os.devnull)
            fout.write(os.linesep)
            fout.write('port 0')
            fout.write(os.linesep)
            fout.flush()
            self.redisInstance = subprocess.Popen(['redis-server', fout.name])

            for i in xrange(0, 16):
                if os.path.exists(testSocket):
                    break
                time.sleep(1)
            else:
                raise RuntimeError('redis-server did not start')

        self.peers = peers.Peers(
            vanilla.buildRedisConnectionPool(unix_socket_path=testSocket), 0)
Esempio n. 3
0
if __name__ == '__main__':
	with open(sys.argv[1],'r') as fin:
		conf = json.load(fin)
	
	if 'logging' in conf['tracker']:	
		logging.config.dictConfig(conf['tracker']['logging'])
	
	authmgr = Auth(conf['salt'])
	connPool = vanilla.buildConnectionPool(psycopg2,**conf['tracker']['postgresql'])
	authmgr.setConnectionPool(connPool)
	
	httpListenIp = conf['tracker'].get('ip',DEFAULT_LISTEN_IP)
	httpListenPort = conf['tracker'].get('port',DEFAULT_LISTEN_PORT)
	httpPathDepth = conf.get('pathDepth',DEFAULT_PATH_DEPTH)
	
	#Use a six hour period for flushing expired peers
	redisConnPool = vanilla.buildRedisConnectionPool(**conf['redis'])
	peerList = Peers(redisConnPool,60*60*6)
	tracker = Tracker(authmgr,peerList,httpPathDepth)
	
	swarmConnPool = vanilla.buildConnectionPool(psycopg2,**conf['tracker']['postgresql'])
	swarm = swarm.Swarm()
	swarm.setConnectionPool(swarmConnPool)
	eventlet.spawn_n(swarm)
	
	tracker.addAfterAnnounce(swarm.pushPeer)
	
	eventlet.spawn_n(peerList)
	wsgi.server(eventlet.listen((httpListenIp, httpListenPort)), tracker)
Esempio n. 4
0
	connPool = vanilla.buildConnectionPool(psycopg2,**conf['webapi']['postgresql'])
	
	authmgr = Auth(conf['salt'])
	authmgr.setConnectionPool(connPool)
	
	torrents = TorrentStore(conf['trackerUrl'])
	torrents.setConnectionPool(connPool)
		
	httpListenIp = conf['webapi'].get('ip',DEFAULT_LISTEN_IP)
	httpListenPort = conf['webapi'].get('port',DEFAULT_LISTEN_PORT)
	httpPathDepth = conf.get('pathDepth',DEFAULT_PATH_DEPTH)

	users = Users(conf['salt'])
	users.setConnectionPool(connPool)
	
	redisConnPool = vanilla.buildRedisConnectionPool(**conf['redis'])
	
	#Pass in zero and do not spawn the thread associated with the Peers
	#object. It is not needed in this process as it runs in the tracker
	#process.
	peerList = peers.Peers(redisConnPool,0)
	
	swarmConnPool = vanilla.buildConnectionPool(psycopg2,**conf['webapi']['postgresql'])
	swarm = swarm.Swarm()
	swarm.setConnectionPool(swarmConnPool)
	
	webapi = Webapi(swarm,peerList,users,authmgr,torrents,httpPathDepth,conf['webapi']['secure'])
	
	users.createRoles(webapi.getRoles())
	
	wsgi.server(eventlet.listen((httpListenIp, httpListenPort)), webapi)