From 44124646579f5d7f0579bc70395723d4c0bdbcb5 Mon Sep 17 00:00:00 2001 From: Lauren Perry Date: Fri, 13 Feb 2015 13:23:16 +0000 Subject: Add protocol versioning for distbuild systems --- distbuild/initiator.py | 5 +++-- distbuild/initiator_connection.py | 12 ++++++++++++ distbuild/protocol.py | 10 +++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/distbuild/initiator.py b/distbuild/initiator.py index ddea8cb3..7f82827c 100644 --- a/distbuild/initiator.py +++ b/distbuild/initiator.py @@ -83,11 +83,12 @@ class Initiator(distbuild.StateMachine): repo=self._repo_name, ref=self._ref, morphology=self._morphology, - original_ref=self._original_ref + original_ref=self._original_ref, + protocol_version=distbuild.protocol.VERSION ) self._jm.send(msg) logging.debug('Initiator: sent to controller: %s', repr(msg)) - + def _handle_json_message(self, event_source, event): distbuild.crash_point() diff --git a/distbuild/initiator_connection.py b/distbuild/initiator_connection.py index c7f9dec7..86df28f1 100644 --- a/distbuild/initiator_connection.py +++ b/distbuild/initiator_connection.py @@ -102,6 +102,18 @@ class InitiatorConnection(distbuild.StateMachine): try: if event.msg['type'] == 'build-request': + if (event.msg.get('protocol_version') != + distbuild.protocol.VERSION): + msg = distbuild.message('build-failed', + id=event.msg['id'], + reason=('Protocol version mismatch between server & ' + 'initiator: distbuild network uses distbuild ' + 'protocol version %i, but client uses version' + ' %i.', distbuild.protocol.VERSION, + event.msg.get('protocol_version'))) + self.jm.send(msg) + self._log_send(msg) + return new_id = self._idgen.next() self.our_ids.add(new_id) self._route_map.add(event.msg['id'], new_id) diff --git a/distbuild/protocol.py b/distbuild/protocol.py index ffce1fe7..f2c74819 100644 --- a/distbuild/protocol.py +++ b/distbuild/protocol.py @@ -1,6 +1,6 @@ # distbuild/protocol.py -- abstractions for the JSON messages # -# Copyright (C) 2012, 2014 Codethink Limited +# Copyright (C) 2012, 2014 - 2015 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,12 +19,20 @@ '''Construct protocol message objects (dicts).''' +# Version refers to an integer that should be incremented by one each time a +# time a change is introduced that would break server/initiator compatibility + + +VERSION = 1 + + _required_fields = { 'build-request': [ 'id', 'repo', 'ref', 'morphology', + 'protocol_version', ], 'build-progress': [ 'id', -- cgit v1.2.1