-
Notifications
You must be signed in to change notification settings - Fork 17
/
standalone_tracker.py
47 lines (38 loc) · 1.35 KB
/
standalone_tracker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import eventlet
eventlet.monkey_patch()
import eventlet.backdoor
from eventlet import wsgi
from tracker import Tracker
from auth import *
from peers import *
import swarm
import vanilla
import psycopg2
import sys
import json
import logging.config
DEFAULT_LISTEN_IP ='127.0.0.1'
DEFAULT_LISTEN_PORT = 8080
DEFAULT_PATH_DEPTH = 1
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)