]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
split IDisplayableServer from IServer, add sb.get_stub_server()
authorBrian Warner <warner@lothar.com>
Tue, 22 May 2012 04:17:27 +0000 (21:17 -0700)
committerBrian Warner <warner@lothar.com>
Tue, 22 May 2012 04:17:27 +0000 (21:17 -0700)
IDisplayableServer includes just enough functionality to call
.get_name() and friends, which is all that the UploadResults really
need. IServer is a superset that includes actual share-manipulation
methods. StubServer instances provide only IDisplayableServer, while
actual NativeStorageServer instances provide the full IServer interface.

When the Helper sends a serverid (so we know what to call the server but
nothing else about it, and have no corresponding NativeStorageServer
object to reference), but we want to store an IDisplayableServer in the
UploadResults, we create a synthetic StubServer "server" and store that
instead.

src/allmydata/interfaces.py
src/allmydata/storage_client.py

index 93063d3c503d80ebec1ad6a5e58e2c6cb7b8fed0..8fb0aba79b4fba0088893a5bef112ddb06336193 100644 (file)
@@ -420,12 +420,18 @@ class IStorageBroker(Interface):
         repeatable way, to distribute load over many peers.
         """
 
-class IServer(Interface):
+class IDisplayableServer(Interface):
+    def get_nickname():
+        pass
+    def get_name():
+        pass
+    def get_longname():
+        pass
+
+class IServer(IDisplayableServer):
     """I live in the client, and represent a single server."""
     def start_connecting(tub, trigger_cb):
         pass
-    def get_nickname():
-        pass
     def get_rref():
         pass
 
index 6d2a72dd9c252a46e94edf119776feab8cad7a10..d4397d693e8c5789d53af976c78155846af30a97 100644 (file)
@@ -32,7 +32,7 @@ the foolscap-based server implemented in src/allmydata/storage/*.py .
 import re, time
 from zope.interface import implements
 from foolscap.api import eventually
-from allmydata.interfaces import IStorageBroker, IServer
+from allmydata.interfaces import IStorageBroker, IDisplayableServer, IServer
 from allmydata.util import log, base32
 from allmydata.util.assertutil import precondition
 from allmydata.util.rrefutil import add_version_to_remote_reference
@@ -139,6 +139,24 @@ class StorageFarmBroker:
             return self.servers[serverid].get_nickname()
         return None
 
+    def get_stub_server(self, serverid):
+        if serverid in self.servers:
+            return self.servers[serverid]
+        return StubServer(serverid)
+
+class StubServer:
+    implements(IDisplayableServer)
+    def __init__(self, serverid):
+        self.serverid = serverid # binary tubid
+    def get_serverid(self):
+        return self.serverid
+    def get_name(self):
+        return base32.b2a(self.serverid)[:8]
+    def get_longname(self):
+        return base32.b2a(self.serverid)
+    def get_nickname(self):
+        return "?"
+
 class NativeStorageServer:
     """I hold information about a storage server that we want to connect to.
     If we are connected, I hold the RemoteReference, their host address, and