introducer: allow nodes to refrain from publishing themselves, by passing furl=None. This would be useful for clients who do not run storage servers.

This commit is contained in:
Brian Warner 2008-02-01 19:48:38 -07:00
parent 6363ab5727
commit a01f9ce9cc
3 changed files with 21 additions and 8 deletions

View File

@ -44,7 +44,7 @@ class RIIntroducerClient(RemoteInterface):
return None return None
class RIIntroducer(RemoteInterface): class RIIntroducer(RemoteInterface):
def hello(node=RIIntroducerClient, furl=FURL): def hello(node=RIIntroducerClient, furl=ChoiceOf(FURL, None)):
return None return None
class RIClient(RemoteInterface): class RIClient(RemoteInterface):

View File

@ -44,15 +44,17 @@ class IntroducerService(service.MultiService, Referenceable):
def _remove(): def _remove():
log.msg(" introducer: removing %s %s" % (node, furl)) log.msg(" introducer: removing %s %s" % (node, furl))
self.nodes.remove(node) self.nodes.remove(node)
if furl is not None:
self.furls.remove(furl) self.furls.remove(furl)
node.notifyOnDisconnect(_remove) node.notifyOnDisconnect(_remove)
if furl is not None:
self.furls.add(furl) self.furls.add(furl)
for othernode in self.nodes:
othernode.callRemote("new_peers", set([furl]))
node.callRemote("new_peers", self.furls) node.callRemote("new_peers", self.furls)
if self._encoding_parameters is not None: if self._encoding_parameters is not None:
node.callRemote("set_encoding_parameters", node.callRemote("set_encoding_parameters",
self._encoding_parameters) self._encoding_parameters)
for othernode in self.nodes:
othernode.callRemote("new_peers", set([furl]))
self.nodes.add(node) self.nodes.add(node)
class IntroducerClient(service.Service, Referenceable): class IntroducerClient(service.Service, Referenceable):
@ -176,7 +178,11 @@ class IntroducerClient(service.Service, Referenceable):
self.reconnectors[furl] = self.tub.connectTo(furl, _got_peer) self.reconnectors[furl] = self.tub.connectTo(furl, _got_peer)
def _got_introducer(self, introducer): def _got_introducer(self, introducer):
self.log("introducing ourselves: %s, %s" % (self, self.my_furl[6:13])) if self.my_furl:
my_furl_s = self.my_furl[6:13]
else:
my_furl_s = "<none>"
self.log("introducing ourselves: %s, %s" % (self, my_furl_s))
self._connected = True self._connected = True
d = introducer.callRemote("hello", d = introducer.callRemote("hello",
node=self, node=self,

View File

@ -89,10 +89,13 @@ class TestIntroducer(unittest.TestCase, testutil.PollMixin):
i.setServiceParent(self.parent) i.setServiceParent(self.parent)
iurl = tub.registerReference(i) iurl = tub.registerReference(i)
NUMCLIENTS = 5 NUMCLIENTS = 5
# we have 5 clients who publish themselves, and an extra one which
# does not. When the connections are fully established, all six nodes
# should have 5 connections each.
clients = [] clients = []
tubs = {} tubs = {}
for i in range(NUMCLIENTS): for i in range(NUMCLIENTS+1):
tub = Tub() tub = Tub()
#tub.setOption("logLocalFailures", True) #tub.setOption("logLocalFailures", True)
#tub.setOption("logRemoteFailures", True) #tub.setOption("logRemoteFailures", True)
@ -102,7 +105,11 @@ class TestIntroducer(unittest.TestCase, testutil.PollMixin):
tub.setLocation("localhost:%d" % portnum) tub.setLocation("localhost:%d" % portnum)
n = FakeNode() n = FakeNode()
log.msg("creating client %d: %s" % (i, tub.getShortTubID()))
if i < NUMCLIENTS:
node_furl = tub.registerReference(n) node_furl = tub.registerReference(n)
else:
node_furl = None
c = IntroducerClient(tub, iurl, node_furl) c = IntroducerClient(tub, iurl, node_furl)
c.setServiceParent(self.parent) c.setServiceParent(self.parent)