X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/5a5c578e2e358a121cdb9234a6cb11c4ecfbf323..ebd5aef6dc92accb509b1cc67eaf72159f35cdfa:/paxos_protocol.h?ds=inline diff --git a/paxos_protocol.h b/paxos_protocol.h index c24f155..30a3d2c 100644 --- a/paxos_protocol.h +++ b/paxos_protocol.h @@ -7,37 +7,34 @@ struct prop_t { unsigned n; string m; -}; -class paxos_protocol { - public: - enum status : status_t { OK, ERR }; - enum rpc_numbers : proc_t { - preparereq = 0x11001, - acceptreq, - decidereq, - heartbeat, - }; - - struct prepareres { - bool oldinstance; - bool accept; - prop_t n_a; - string v_a; - }; + MEMBERS(n, m) + LEXICOGRAPHIC_COMPARISON(prop_t) }; -inline unmarshall & operator>>(unmarshall &u, prop_t &a) { return u >> a.n >> a.m; } -inline marshall & operator<<(marshall &m, prop_t a) { return m << a.n << a.m; } -inline bool operator>(const prop_t &a, const prop_t &b) { return tie(a.n, a.m) > tie(b.n, b.m); } -inline bool operator>=(const prop_t &a, const prop_t &b) { return tie(a.n, a.m) >= tie(b.n, b.m); } - -inline unmarshall & operator>>(unmarshall &u, paxos_protocol::prepareres &r) { - return u >> r.oldinstance >> r.accept >> r.n_a >> r.v_a; +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::prepareres r) { - return m << r.oldinstance << r.accept << r.n_a << r.v_a; -} +MARSHALLABLE_STRUCT(paxos_protocol::prepareres) #endif