Commit 896bc9de authored by Julien Muchembled's avatar Julien Muchembled

registry: new RPC to get versions of all running nodes

parent e9243962
...@@ -161,7 +161,7 @@ class RegistryServer(object): ...@@ -161,7 +161,7 @@ class RegistryServer(object):
def handle_request(self, request, method, kw): def handle_request(self, request, method, kw):
m = getattr(self, method) m = getattr(self, method)
if method in ('topology',) and \ if method in ('versions', 'topology',) and \
request.client_address[0] not in ('127.0.0.1', '::1'): request.client_address[0] not in ('127.0.0.1', '::1'):
return request.send_error(httplib.FORBIDDEN) return request.send_error(httplib.FORBIDDEN)
key = m.getcallargs(**kw).get('cn') key = m.getcallargs(**kw).get('cn')
...@@ -369,6 +369,44 @@ class RegistryServer(object): ...@@ -369,6 +369,44 @@ class RegistryServer(object):
logging.info("Sending bootstrap peer: %s", msg) logging.info("Sending bootstrap peer: %s", msg)
return utils.encrypt(cert, msg) return utils.encrypt(cert, msg)
@rpc
def versions(self):
with self.peers_lock:
self.request_dump()
peers = set(prefix
for neigh_routes in self.ctl.neighbours.itervalues()
for prefix in neigh_routes[1]
if prefix)
peers.add(self.prefix)
peer_dict = {}
s = self.sock,
with self.lock:
while True:
r, w, _ = select.select(s, s if peers else (), (), 3)
if r:
ver, address = self.sock.recvfrom(1<<16)
address = utils.binFromIp(address[0])
if (address.startswith(self.network) and
len(ver) > 1 and ver[0] in '\3\4' # BBB
):
try:
peer_dict[max(filter(address[len(self.network):]
.startswith, peer_dict),
key=len)] = ver[1:]
except ValueError:
pass
if w:
x = peers.pop()
peer_dict[x] = None
x = utils.ipFromBin(self.network + x)
try:
self.sock.sendto('\3', (x, tunnel.PORT))
except socket.error:
pass
elif not r:
break
return repr(peer_dict)
@rpc @rpc
def topology(self): def topology(self):
with self.lock: with self.lock:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment