From: Brian Warner Date: Thu, 26 Apr 2007 19:01:25 +0000 (-0700) Subject: add RIClient.get_versions, in the hopes of enabling backwards-compatibility code... X-Git-Tag: allmydata-tahoe_v0.1.1-1-UNSTABLE~18 X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/flags/rgr-080307.php?a=commitdiff_plain;h=5ceeaaea6a63d1e4e60c5a37a72a30df80207331;p=tahoe-lafs%2Ftahoe-lafs.git add RIClient.get_versions, in the hopes of enabling backwards-compatibility code in the future --- diff --git a/src/allmydata/client.py b/src/allmydata/client.py index 6e0f9b60..b22d033e 100644 --- a/src/allmydata/client.py +++ b/src/allmydata/client.py @@ -7,6 +7,7 @@ from allmydata import node from twisted.internet import defer +import allmydata from allmydata.Crypto.Util.number import bytes_to_long from allmydata.storageserver import StorageServer from allmydata.upload import Uploader @@ -26,6 +27,9 @@ class Client(node.Node, Referenceable): INTRODUCER_FURL_FILE = "introducer.furl" GLOBAL_VDRIVE_FURL_FILE = "vdrive.furl" + # we're pretty narrow-minded right now + OLDEST_SUPPORTED_VERSION = allmydata.__version__ + def __init__(self, basedir="."): node.Node.__init__(self, basedir) self.my_pburl = None @@ -87,6 +91,9 @@ class Client(node.Node, Referenceable): self.connected_to_vdrive = False vdrive_root.notifyOnDisconnect(_disconnected) + def remote_get_versions(self): + return str(allmydata.__version__), str(self.OLDEST_SUPPORTED_VERSION) + def remote_get_service(self, name): # TODO: 'vdrive' should not be public in the medium term return self.getServiceNamed(name) diff --git a/src/allmydata/interfaces.py b/src/allmydata/interfaces.py index abb4ab5c..855e85c9 100644 --- a/src/allmydata/interfaces.py +++ b/src/allmydata/interfaces.py @@ -25,6 +25,19 @@ class RIIntroducer(RemoteInterface): return None class RIClient(RemoteInterface): + def get_versions(): + """Return a tuple of (my_version, oldest_supported) strings. + + Each string can be parsed by an allmydata.util.version.Version + instance, and then compared. The first goal is to make sure that + nodes are not confused by speaking to an incompatible peer. The + second goal is to enable the development of backwards-compatibility + code. + + This method is likely to change in incompatible ways until we get the + whole compatibility scheme nailed down. + """ + return TupleOf(str, str) def get_service(name=str): return Referenceable def get_nodeid(): diff --git a/src/allmydata/test/test_client.py b/src/allmydata/test/test_client.py index b9bbba24..3366dea6 100644 --- a/src/allmydata/test/test_client.py +++ b/src/allmydata/test/test_client.py @@ -2,7 +2,9 @@ import os from twisted.trial import unittest +import allmydata from allmydata import client, introducer +from allmydata.util import version class MyIntroducerClient(introducer.IntroducerClient): def __init__(self): @@ -39,3 +41,12 @@ class Basic(unittest.TestCase): c2.introducer_client.connections[k] = None self.failUnlessEqual(permute(c2, "one"), ['3','1','0','4','2']) + def test_versions(self): + basedir = "test_client.Basic.test_versions" + os.mkdir(basedir) + open(os.path.join(basedir, "introducer.furl"), "w").write("") + open(os.path.join(basedir, "vdrive.furl"), "w").write("") + c = client.Client(basedir) + mine, oldest = c.remote_get_versions() + self.failUnlessEqual(version.Version(mine), allmydata.__version__) +