1212import requests
1313from autobahn .twisted .websocket import listenWS
1414
15- import dht .constants
1615import obelisk
1716from db .datastore import Database
1817from keyutils .keys import KeyChain
1918from dht .network import Server
2019from dht .node import Node
2120from wireprotocol import OpenBazaarProtocol
22- from constants import DATA_FOLDER
21+ from constants import DATA_FOLDER , KSIZE , ALPHA
2322from market import network
2423from market .listeners import MessageListenerImpl , NotificationListenerImpl
2524from api .ws import WSFactory , WSProtocol
@@ -37,18 +36,27 @@ def run(*args):
3736 keys = KeyChain (db )
3837
3938 # logging
39+ # TODO: prune this log file and prevent it from getting too large?
4040 logFile = logfile .LogFile .fromFullPath (DATA_FOLDER + "debug.log" )
4141 log .addObserver (log .FileLogObserver (logFile ).emit )
4242 log .startLogging (sys .stdout )
4343
4444 # stun
45+ # TODO: accept port from command line
4546 port = 18467 if not TESTNET else 28467
4647 print "Finding NAT Type.."
48+ # TODO: maintain a list of backup STUN servers and try them if ours fails
4749 response = stun .get_ip_info (stun_host = "seed.openbazaar.org" , source_port = port )
4850 print "%s on %s:%s" % (response [0 ], response [1 ], response [2 ])
4951 ip_address = response [1 ]
5052 port = response [2 ]
5153
54+ # TODO: try UPnP if restricted NAT
55+
56+ # TODO: maintain open connection to seed node if STUN/UPnP fail
57+
58+ # TODO: use TURN of symmetric NAT
59+
5260 def on_bootstrap_complete (resp ):
5361 mlistener = MessageListenerImpl (ws_factory , db )
5462 mserver .get_messages (mlistener )
@@ -65,13 +73,13 @@ def on_bootstrap_complete(resp):
6573 kserver = Server .loadState (DATA_FOLDER + 'cache.pickle' , ip_address , port , protocol , db ,
6674 on_bootstrap_complete , storage = PersistentStorage (db .DATABASE ))
6775 except Exception :
68- kserver = Server (node , db , dht . constants . KSIZE , dht . constants . ALPHA , storage = PersistentStorage (db .DATABASE ))
76+ kserver = Server (node , db , KSIZE , ALPHA , storage = PersistentStorage (db .DATABASE ))
6977 kserver .protocol .connect_multiplexer (protocol )
7078 kserver .bootstrap (
7179 kserver .querySeed ("seed.openbazaar.org:8080" ,
7280 "ddd862778e3ed71af06db0e3619a4c6269ec7468c745132dbb73982b319fc572" ))\
7381 .addCallback (on_bootstrap_complete )
74-
82+ # TODO: load seeds from config file
7583 kserver .saveStateRegularly (DATA_FOLDER + 'cache.pickle' , 10 )
7684 protocol .register_processor (kserver .protocol )
7785
@@ -96,7 +104,10 @@ def on_bootstrap_complete(resp):
96104 site = Site (api , timeout = None )
97105 reactor .listenTCP (18469 , site , interface = "127.0.0.1" )
98106
107+ # TODO: add optional SSL on rest and websocket servers
108+
99109 # blockchain
110+ # TODO: listen on the libbitcoin heartbeat port instead fetching height
100111 def height_fetched (ec , height ):
101112 print "Libbitcoin server online"
102113 try :
@@ -112,6 +123,9 @@ def timeout(client):
112123 libbitcoin_client = obelisk .ObeliskOfLightClient ("tcp://libbitcoin2.openbazaar.org:9091" )
113124 else :
114125 libbitcoin_client = obelisk .ObeliskOfLightClient ("tcp://libbitcoin1.openbazaar.org:9091" )
126+
127+ # TODO: load libbitcoin server url from config file
128+
115129 libbitcoin_client .fetch_last_height (height_fetched )
116130 timeout = reactor .callLater (5 , timeout , libbitcoin_client )
117131
@@ -168,6 +182,7 @@ def start(self):
168182 print
169183 print "OpenBazaar Server v0.1 starting..."
170184 unix = ("linux" , "linux2" , "darwin" )
185+ # TODO: run as windows service (also for STOP and RESTART)
171186 if args .daemon and platform .system ().lower () in unix :
172187 self .daemon .start (args .testnet )
173188 else :
0 commit comments