Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit 8bc6e7d

Browse files
committed
Add TODO for odds and ends
1 parent e7edf35 commit 8bc6e7d

6 files changed

Lines changed: 32 additions & 16 deletions

File tree

constants.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from os.path import expanduser
22

3-
# This should be turned into a more formal context module
3+
# TODO: this can be loaded from a config file
44

55
DATA_FOLDER = expanduser("~") + "/OpenBazaar/"
66
SEED_NODE = ("205.186.154.163", 18467)
77
SEED_NODE_TESTNET = ("205.186.154.163", 28467)
8-
8+
KSIZE = 20
9+
ALPHA = 3

dht/constants.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

dht/network.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ def loadState(cls, fname, ip_address, port, multiplexer, db, callback=None, stor
353353
s.bootstrap(data['neighbors']).addCallback(callback)
354354
else:
355355
s.bootstrap(data['neighbors'])
356+
357+
# TODO: if bootstrapping fails because all our cached nodes are dead, then query the seed again
356358
return s
357359

358360
def saveStateRegularly(self, fname, frequency=600):

dht/tests/test_crawling.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
__author__ = 'chris'
22
from binascii import unhexlify
33

4-
import dht.constants
54
import mock
65
import nacl.signing
76
import nacl.hash
@@ -16,6 +15,7 @@
1615
from protos.objects import Value
1716
from wireprotocol import OpenBazaarProtocol
1817
from db.datastore import Database
18+
from constants import ALPHA, KSIZE
1919

2020

2121
class ValueSpiderCrawlTest(unittest.TestCase):
@@ -80,8 +80,7 @@ def test_find(self):
8080

8181
node = Node(digest("s"))
8282
nearest = self.protocol.router.findNeighbors(node)
83-
spider = ValueSpiderCrawl(self.protocol, node, nearest,
84-
dht.constants.KSIZE, dht.constants.ALPHA)
83+
spider = ValueSpiderCrawl(self.protocol, node, nearest, KSIZE, ALPHA)
8584
spider.find()
8685

8786
self.clock.advance(100 * constants.PACKET_TIMEOUT)
@@ -101,7 +100,7 @@ def test_nodesFound(self):
101100
# test resonse with uncontacted nodes
102101
node = Node(digest("s"))
103102
nearest = self.protocol.router.findNeighbors(node)
104-
spider = ValueSpiderCrawl(self.protocol, node, nearest, dht.constants.KSIZE, dht.constants.ALPHA)
103+
spider = ValueSpiderCrawl(self.protocol, node, nearest, KSIZE, ALPHA)
105104
response = (True, (self.node1.getProto().SerializeToString(), self.node2.getProto().SerializeToString(),
106105
self.node3.getProto().SerializeToString()))
107106
responses = {self.node1.id: response}
@@ -111,7 +110,7 @@ def test_nodesFound(self):
111110
self.assertEqual(len(self.proto_mock.send_datagram.call_args_list), 4)
112111

113112
# test all been contacted
114-
spider = ValueSpiderCrawl(self.protocol, node, nearest, dht.constants.KSIZE, dht.constants.ALPHA)
113+
spider = ValueSpiderCrawl(self.protocol, node, nearest, KSIZE, ALPHA)
115114
for peer in spider.nearest.getUncontacted():
116115
spider.nearest.markContacted(peer)
117116
response = (True, (self.node1.getProto().SerializeToString(), self.node2.getProto().SerializeToString(),
@@ -121,7 +120,7 @@ def test_nodesFound(self):
121120
self.assertTrue(resp is None)
122121

123122
# test didn't happen
124-
spider = ValueSpiderCrawl(self.protocol, node, nearest, dht.constants.KSIZE, dht.constants.ALPHA)
123+
spider = ValueSpiderCrawl(self.protocol, node, nearest, KSIZE, ALPHA)
125124
response = (False, (self.node1.getProto().SerializeToString(), self.node2.getProto().SerializeToString(),
126125
self.node3.getProto().SerializeToString()))
127126
responses = {self.node1.id: response}
@@ -148,7 +147,7 @@ def test_handleFoundValues(self):
148147

149148
node = Node(digest("s"))
150149
nearest = self.protocol.router.findNeighbors(node)
151-
spider = ValueSpiderCrawl(self.protocol, node, nearest, dht.constants.KSIZE, dht.constants.ALPHA)
150+
spider = ValueSpiderCrawl(self.protocol, node, nearest, KSIZE, ALPHA)
152151
val = Value()
153152
val.valueKey = digest("contractID")
154153
val.serializedData = self.node1.getProto().SerializeToString()

openbazaard.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
import requests
1313
from autobahn.twisted.websocket import listenWS
1414

15-
import dht.constants
1615
import obelisk
1716
from db.datastore import Database
1817
from keyutils.keys import KeyChain
1918
from dht.network import Server
2019
from dht.node import Node
2120
from wireprotocol import OpenBazaarProtocol
22-
from constants import DATA_FOLDER
21+
from constants import DATA_FOLDER, KSIZE, ALPHA
2322
from market import network
2423
from market.listeners import MessageListenerImpl, NotificationListenerImpl
2524
from 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:

wireprotocol.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from log import Logger
99
from dht.node import Node
1010

11+
1112
class OpenBazaarProtocol(ConnectionMultiplexer):
1213
"""
1314
A protocol extending the txrudp datagram protocol. This is the main protocol
@@ -59,7 +60,7 @@ def receive_message(self, datagram):
5960
return False
6061

6162
def handle_shutdown(self):
62-
del self.active_connections[self.connection.dest_addr]
63+
self.connection.unregister()
6364
if self.node is not None:
6465
for processor in self.processors:
6566
if FIND_VALUE in processor:

0 commit comments

Comments
 (0)