X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/5fd8cc8409d0efadc07dfe8d6774ad9ff477663d..f0dcb6b97d6d40f67698d1f71ac26970f1776f82:/paxos_protocol.h diff --git a/paxos_protocol.h b/paxos_protocol.h index 9c2703e..c61e2eb 100644 --- a/paxos_protocol.h +++ b/paxos_protocol.h @@ -1,133 +1,40 @@ #ifndef paxos_protocol_h #define paxos_protocol_h -#include "rpc.h" +#include "types.h" +#include "rpc/rpc.h" struct prop_t { - unsigned n; - std::string m; -}; - -class paxos_protocol { - public: - enum xxstatus { OK, ERR }; - typedef int status; - enum rpc_numbers { - preparereq = 0x11001, - acceptreq, - decidereq, - heartbeat, - }; - - struct preparearg { - unsigned instance; - prop_t n; - }; - - struct prepareres { - bool oldinstance; - bool accept; - prop_t n_a; - std::string v_a; - }; - - struct acceptarg { - unsigned instance; - prop_t n; - std::string v; - }; - - struct decidearg { - unsigned instance; - std::string v; - }; + unsigned n; + string m; + MEMBERS(n, m) + LEXICOGRAPHIC_COMPARISON(prop_t) }; -inline unmarshall & -operator>>(unmarshall &u, prop_t &a) -{ - u >> a.n; - u >> a.m; - return u; -} - -inline marshall & -operator<<(marshall &m, prop_t a) -{ - m << a.n; - m << a.m; - return m; -} - -inline unmarshall & -operator>>(unmarshall &u, paxos_protocol::preparearg &a) -{ - u >> a.instance; - u >> a.n; - return u; -} - -inline marshall & -operator<<(marshall &m, paxos_protocol::preparearg a) -{ - m << a.instance; - m << a.n; - return m; -} - -inline unmarshall & -operator>>(unmarshall &u, paxos_protocol::prepareres &r) -{ - u >> r.oldinstance; - u >> r.accept; - u >> r.n_a; - u >> r.v_a; - return u; -} - -inline marshall & -operator<<(marshall &m, paxos_protocol::prepareres r) -{ - m << r.oldinstance; - m << r.accept; - m << r.n_a; - m << r.v_a; - return m; -} - -inline unmarshall & -operator>>(unmarshall &u, paxos_protocol::acceptarg &a) -{ - u >> a.instance; - u >> a.n; - u >> a.v; - return u; -} - -inline marshall & -operator<<(marshall &m, paxos_protocol::acceptarg a) -{ - m << a.instance; - m << a.n; - m << a.v; - return m; -} - -inline unmarshall & -operator>>(unmarshall &u, paxos_protocol::decidearg &a) -{ - u >> a.instance; - u >> a.v; - return u; -} +MARSHALLABLE_STRUCT(prop_t) + +namespace paxos_protocol { + enum status : rpc_protocol::status { OK, ERR }; + struct prepareres { + bool oldinstance; + bool accept; + prop_t n_a; + string v_a; + + MEMBERS(oldinstance, accept, n_a, v_a) + }; + using node_t = string; + using nodes_t = vector; + using value_t = string; + + REMOTE_PROCEDURE_BASE(0x11000); + REMOTE_PROCEDURE(1, preparereq, (prepareres &, node_t, unsigned, prop_t)); + REMOTE_PROCEDURE(2, acceptreq, (bool &, node_t, unsigned, prop_t, value_t)); + REMOTE_PROCEDURE(3, decidereq, (int &, node_t, unsigned, value_t)); + REMOTE_PROCEDURE(4, heartbeat, (int &, string, unsigned)); +}; -inline marshall & -operator<<(marshall &m, paxos_protocol::decidearg a) -{ - m << a.instance; - m << a.v; - return m; -} +MARSHALLABLE_STRUCT(paxos_protocol::prepareres) #endif