NativeStorageServer: create with server_id, not key_s

They're the same thing, but knowing that is the responsibility of the
caller, not NativeStorageServer. Try to normalize on "server_id" as the
spelling. Remove support for missing key_s, now that we require V2
introductions.
This commit is contained in:
Brian Warner 2016-08-26 17:29:39 -07:00
parent 37f89b1346
commit f23660e178
3 changed files with 17 additions and 20 deletions

View File

@ -103,9 +103,9 @@ class StorageFarmBroker(service.MultiService):
s._is_connected = True
self.servers[serverid] = s
def test_add_server(self, serverid, s):
def test_add_server(self, server_id, s):
s.on_status_changed(lambda _: self._got_connection())
self.servers[serverid] = s
self.servers[server_id] = s
def use_introducer(self, introducer_client):
self.introducer_client = ic = introducer_client
@ -265,9 +265,9 @@ class NativeStorageServer(service.MultiService):
"application-version": "unknown: no get_version()",
}
def __init__(self, key_s, ann, tub_options={}, tub_handlers={}):
def __init__(self, server_id, ann, tub_options={}, tub_handlers={}):
service.MultiService.__init__(self)
self.key_s = key_s
self._server_id = server_id
self.announcement = ann
self._tub_options = tub_options
self._tub_handlers = tub_handlers
@ -282,16 +282,13 @@ class NativeStorageServer(service.MultiService):
ps = base32.a2b(str(ann["permutation-seed-base32"]))
self._permutation_seed = ps
if key_s:
self._long_description = key_s
if key_s.startswith("v0-"):
# remove v0- prefix from abbreviated name
self._short_description = key_s[3:3+8]
else:
self._short_description = key_s[:8]
assert server_id
self._long_description = server_id
if server_id.startswith("v0-"):
# remove v0- prefix from abbreviated name
self._short_description = server_id[3:3+8]
else:
self._long_description = tubid_s
self._short_description = tubid_s[:6]
self._short_description = server_id[:8]
self.last_connect_time = None
self.last_loss_time = None
@ -321,7 +318,7 @@ class NativeStorageServer(service.MultiService):
def __repr__(self):
return "<NativeStorageServer for %s>" % self.get_name()
def get_serverid(self):
return self.key_s
return self._server_id
def get_permutation_seed(self):
return self._permutation_seed
def get_version(self):

View File

@ -25,12 +25,12 @@ class WebResultsRendering(unittest.TestCase, WebRenderingMixin):
sb = StorageFarmBroker(True)
# s.get_name() (the "short description") will be "v0-00000000".
# s.get_longname() will include the -long suffix.
# s.get_peerid() (i.e. tubid) will be "aaa.." or "777.." or "ceir.."
servers = [("v0-00000000-long", "\x00"*20, "peer-0"),
("v0-ffffffff-long", "\xff"*20, "peer-f"),
("v0-11111111-long", "\x11"*20, "peer-11")]
for (key_s, peerid, nickname) in servers:
tubid_b32 = base32.b2a(peerid)
for (key_s, binary_tubid, nickname) in servers:
server_id = key_s
tubid_b32 = base32.b2a(binary_tubid)
furl = "pb://%s@nowhere/fake" % tubid_b32
ann = { "version": 0,
"service-name": "storage",
@ -41,8 +41,8 @@ class WebResultsRendering(unittest.TestCase, WebRenderingMixin):
"my-version": "ver",
"oldest-supported": "oldest",
}
s = NativeStorageServer(key_s, ann)
sb.test_add_server(peerid, s) # XXX: maybe use key_s?
s = NativeStorageServer(server_id, ann)
sb.test_add_server(server_id, s)
c = FakeClient()
c.storage_broker = sb
return c

View File

@ -50,7 +50,7 @@ class TestStorageFarmBroker(unittest.TestCase):
broker.got_static_announcement(key_s, ann, None)
self.failUnlessEqual(len(broker.static_servers), 1)
self.failUnlessEqual(broker.servers[key_s].announcement, ann)
self.failUnlessEqual(broker.servers[key_s].key_s, key_s)
self.failUnlessEqual(broker.servers[key_s].get_serverid(), key_s)
@inlineCallbacks
def test_threshold_reached(self):