Skip to content

Commit

Permalink
Overwrite pystun server list.
Browse files Browse the repository at this point in the history
* Non-responding servers in pystun's builtin list are causing node to
  crash upon starting up.
  • Loading branch information
Renelvon committed Nov 4, 2014
1 parent 5464b40 commit bca7566
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
8 changes: 3 additions & 5 deletions node/network_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
)


def init_additional_STUN_servers(servers=_ADDITIONAL_STUN_SERVERS):
"""Inject list of additional STUN servers."""
server_set = set(stun.stun_servers_list)
server_set.update(servers)
stun.stun_servers_list = tuple(server_set)
def set_stun_servers(servers=_ADDITIONAL_STUN_SERVERS):
"""Manually set the list of good STUN servers."""
stun.stun_servers_list = tuple(servers)


def get_NAT_status():
Expand Down
2 changes: 1 addition & 1 deletion node/openbazaar.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def ensure_database_setup(ob_ctx, defaults):

def start(arguments):
defaults = OpenBazaarContext.get_defaults()
network_util.init_additional_STUN_servers()
network_util.set_stun_servers()

# Turn off checks that don't make sense in development mode
if arguments.dev_mode:
Expand Down
19 changes: 3 additions & 16 deletions test/test_network_util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import collections
import unittest

import stun
Expand All @@ -8,25 +7,13 @@

class TestNodeNetworkUtil(unittest.TestCase):

def test_init_additional_stun_servers(self):
stun_servers_pre = stun.stun_servers_list
def test_set_stun_servers(self):
new_stun_servers = (
'stun.openbazaar1.com',
'stun.openbazaar2.com'
)
network_util.init_additional_STUN_servers(servers=new_stun_servers)

counter = collections.Counter(stun.stun_servers_list)

# Check all new STUN servers are in.
for server in new_stun_servers:
self.assertEqual(counter[server], 1)

network_util.init_additional_STUN_servers(servers=new_stun_servers)

# Check no STUN server was removed or added twice.
for server in stun_servers_pre:
self.assertEqual(counter[server], 1)
network_util.set_stun_servers(servers=new_stun_servers)
self.assertItemsEqual(new_stun_servers, stun.stun_servers_list)

def test_is_loopback_addr(self):
self.assertTrue(network_util.is_loopback_addr("127.0.0.1"))
Expand Down

0 comments on commit bca7566

Please sign in to comment.