mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-11-10 10:05:09 +03:00
Modify proto
This commit is contained in:
parent
575f28cef0
commit
ef3c34c803
@ -15,22 +15,19 @@ extern "C" {
|
|||||||
struct Raft;
|
struct Raft;
|
||||||
struct Raft_Comd;
|
struct Raft_Comd;
|
||||||
struct Raft_Rent;
|
struct Raft_Rent;
|
||||||
struct Raft_Apen;
|
struct Raft_Rest;
|
||||||
struct Raft_Revo;
|
|
||||||
struct Raft_Rasp;
|
struct Raft_Rasp;
|
||||||
|
|
||||||
typedef struct {capn_ptr p;} Raft_ptr;
|
typedef struct {capn_ptr p;} Raft_ptr;
|
||||||
typedef struct {capn_ptr p;} Raft_Comd_ptr;
|
typedef struct {capn_ptr p;} Raft_Comd_ptr;
|
||||||
typedef struct {capn_ptr p;} Raft_Rent_ptr;
|
typedef struct {capn_ptr p;} Raft_Rent_ptr;
|
||||||
typedef struct {capn_ptr p;} Raft_Apen_ptr;
|
typedef struct {capn_ptr p;} Raft_Rest_ptr;
|
||||||
typedef struct {capn_ptr p;} Raft_Revo_ptr;
|
|
||||||
typedef struct {capn_ptr p;} Raft_Rasp_ptr;
|
typedef struct {capn_ptr p;} Raft_Rasp_ptr;
|
||||||
|
|
||||||
typedef struct {capn_ptr p;} Raft_list;
|
typedef struct {capn_ptr p;} Raft_list;
|
||||||
typedef struct {capn_ptr p;} Raft_Comd_list;
|
typedef struct {capn_ptr p;} Raft_Comd_list;
|
||||||
typedef struct {capn_ptr p;} Raft_Rent_list;
|
typedef struct {capn_ptr p;} Raft_Rent_list;
|
||||||
typedef struct {capn_ptr p;} Raft_Apen_list;
|
typedef struct {capn_ptr p;} Raft_Rest_list;
|
||||||
typedef struct {capn_ptr p;} Raft_Revo_list;
|
|
||||||
typedef struct {capn_ptr p;} Raft_Rasp_list;
|
typedef struct {capn_ptr p;} Raft_Rasp_list;
|
||||||
|
|
||||||
enum Raft_Comd_Type {
|
enum Raft_Comd_Type {
|
||||||
@ -47,24 +44,26 @@ struct Raft_Comd {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Raft_Rent {
|
struct Raft_Rent {
|
||||||
uint64_t tem;
|
uint32_t tem;
|
||||||
Raft_Comd_ptr cmd;
|
Raft_Comd_ptr cmd;
|
||||||
};
|
};
|
||||||
|
enum Raft_Rest_which {
|
||||||
struct Raft_Apen {
|
Raft_Rest_revo = 0,
|
||||||
uint64_t tem;
|
Raft_Rest_apen = 1
|
||||||
capn_text cid;
|
|
||||||
uint64_t lai;
|
|
||||||
uint64_t lat;
|
|
||||||
Raft_Rent_list ent;
|
|
||||||
uint64_t cit;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Raft_Revo {
|
struct Raft_Rest {
|
||||||
uint64_t tem;
|
uint32_t tem;
|
||||||
capn_text cid;
|
capn_text cid;
|
||||||
uint64_t lai;
|
uint64_t lai;
|
||||||
uint64_t lat;
|
uint32_t lat;
|
||||||
|
enum Raft_Rest_which which;
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
Raft_Rent_list ent;
|
||||||
|
uint64_t cit;
|
||||||
|
} apen;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Raft_Rasp {
|
struct Raft_Rasp {
|
||||||
@ -75,43 +74,37 @@ struct Raft_Rasp {
|
|||||||
Raft_ptr new_Raft(struct capn_segment*);
|
Raft_ptr new_Raft(struct capn_segment*);
|
||||||
Raft_Comd_ptr new_Raft_Comd(struct capn_segment*);
|
Raft_Comd_ptr new_Raft_Comd(struct capn_segment*);
|
||||||
Raft_Rent_ptr new_Raft_Rent(struct capn_segment*);
|
Raft_Rent_ptr new_Raft_Rent(struct capn_segment*);
|
||||||
Raft_Apen_ptr new_Raft_Apen(struct capn_segment*);
|
Raft_Rest_ptr new_Raft_Rest(struct capn_segment*);
|
||||||
Raft_Revo_ptr new_Raft_Revo(struct capn_segment*);
|
|
||||||
Raft_Rasp_ptr new_Raft_Rasp(struct capn_segment*);
|
Raft_Rasp_ptr new_Raft_Rasp(struct capn_segment*);
|
||||||
|
|
||||||
Raft_list new_Raft_list(struct capn_segment*, int len);
|
Raft_list new_Raft_list(struct capn_segment*, int len);
|
||||||
Raft_Comd_list new_Raft_Comd_list(struct capn_segment*, int len);
|
Raft_Comd_list new_Raft_Comd_list(struct capn_segment*, int len);
|
||||||
Raft_Rent_list new_Raft_Rent_list(struct capn_segment*, int len);
|
Raft_Rent_list new_Raft_Rent_list(struct capn_segment*, int len);
|
||||||
Raft_Apen_list new_Raft_Apen_list(struct capn_segment*, int len);
|
Raft_Rest_list new_Raft_Rest_list(struct capn_segment*, int len);
|
||||||
Raft_Revo_list new_Raft_Revo_list(struct capn_segment*, int len);
|
|
||||||
Raft_Rasp_list new_Raft_Rasp_list(struct capn_segment*, int len);
|
Raft_Rasp_list new_Raft_Rasp_list(struct capn_segment*, int len);
|
||||||
|
|
||||||
void read_Raft(struct Raft*, Raft_ptr);
|
void read_Raft(struct Raft*, Raft_ptr);
|
||||||
void read_Raft_Comd(struct Raft_Comd*, Raft_Comd_ptr);
|
void read_Raft_Comd(struct Raft_Comd*, Raft_Comd_ptr);
|
||||||
void read_Raft_Rent(struct Raft_Rent*, Raft_Rent_ptr);
|
void read_Raft_Rent(struct Raft_Rent*, Raft_Rent_ptr);
|
||||||
void read_Raft_Apen(struct Raft_Apen*, Raft_Apen_ptr);
|
void read_Raft_Rest(struct Raft_Rest*, Raft_Rest_ptr);
|
||||||
void read_Raft_Revo(struct Raft_Revo*, Raft_Revo_ptr);
|
|
||||||
void read_Raft_Rasp(struct Raft_Rasp*, Raft_Rasp_ptr);
|
void read_Raft_Rasp(struct Raft_Rasp*, Raft_Rasp_ptr);
|
||||||
|
|
||||||
void write_Raft(const struct Raft*, Raft_ptr);
|
void write_Raft(const struct Raft*, Raft_ptr);
|
||||||
void write_Raft_Comd(const struct Raft_Comd*, Raft_Comd_ptr);
|
void write_Raft_Comd(const struct Raft_Comd*, Raft_Comd_ptr);
|
||||||
void write_Raft_Rent(const struct Raft_Rent*, Raft_Rent_ptr);
|
void write_Raft_Rent(const struct Raft_Rent*, Raft_Rent_ptr);
|
||||||
void write_Raft_Apen(const struct Raft_Apen*, Raft_Apen_ptr);
|
void write_Raft_Rest(const struct Raft_Rest*, Raft_Rest_ptr);
|
||||||
void write_Raft_Revo(const struct Raft_Revo*, Raft_Revo_ptr);
|
|
||||||
void write_Raft_Rasp(const struct Raft_Rasp*, Raft_Rasp_ptr);
|
void write_Raft_Rasp(const struct Raft_Rasp*, Raft_Rasp_ptr);
|
||||||
|
|
||||||
void get_Raft(struct Raft*, Raft_list, int i);
|
void get_Raft(struct Raft*, Raft_list, int i);
|
||||||
void get_Raft_Comd(struct Raft_Comd*, Raft_Comd_list, int i);
|
void get_Raft_Comd(struct Raft_Comd*, Raft_Comd_list, int i);
|
||||||
void get_Raft_Rent(struct Raft_Rent*, Raft_Rent_list, int i);
|
void get_Raft_Rent(struct Raft_Rent*, Raft_Rent_list, int i);
|
||||||
void get_Raft_Apen(struct Raft_Apen*, Raft_Apen_list, int i);
|
void get_Raft_Rest(struct Raft_Rest*, Raft_Rest_list, int i);
|
||||||
void get_Raft_Revo(struct Raft_Revo*, Raft_Revo_list, int i);
|
|
||||||
void get_Raft_Rasp(struct Raft_Rasp*, Raft_Rasp_list, int i);
|
void get_Raft_Rasp(struct Raft_Rasp*, Raft_Rasp_list, int i);
|
||||||
|
|
||||||
void set_Raft(const struct Raft*, Raft_list, int i);
|
void set_Raft(const struct Raft*, Raft_list, int i);
|
||||||
void set_Raft_Comd(const struct Raft_Comd*, Raft_Comd_list, int i);
|
void set_Raft_Comd(const struct Raft_Comd*, Raft_Comd_list, int i);
|
||||||
void set_Raft_Rent(const struct Raft_Rent*, Raft_Rent_list, int i);
|
void set_Raft_Rent(const struct Raft_Rent*, Raft_Rent_list, int i);
|
||||||
void set_Raft_Apen(const struct Raft_Apen*, Raft_Apen_list, int i);
|
void set_Raft_Rest(const struct Raft_Rest*, Raft_Rest_list, int i);
|
||||||
void set_Raft_Revo(const struct Raft_Revo*, Raft_Revo_list, int i);
|
|
||||||
void set_Raft_Rasp(const struct Raft_Rasp*, Raft_Rasp_list, int i);
|
void set_Raft_Rasp(const struct Raft_Rasp*, Raft_Rasp_list, int i);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
30
p/raft.capnp
30
p/raft.capnp
@ -7,33 +7,31 @@ struct Raft {
|
|||||||
|
|
||||||
enum Type {
|
enum Type {
|
||||||
nop @0; # no-op
|
nop @0; # no-op
|
||||||
ova @1; # arvo events
|
ova @1; # arvo event
|
||||||
#xek @2; # checkpoint
|
#xek @2; # checkpoint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Rent { # log entry
|
struct Rent { # log entry
|
||||||
tem @0 :UInt64; # term
|
tem @0 :UInt32; # term
|
||||||
cmd @1 :Comd; # command
|
cmd @1 :Comd; # command
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Apen { # AppendEntries
|
struct Rest { # Raft RPC request
|
||||||
tem @0 :UInt64; # term
|
tem @0 :UInt32; # sender term
|
||||||
cid @1 :Text; # leader ID
|
cid @1 :Text; # sender name
|
||||||
lai @2 :UInt64; # previous log index
|
|
||||||
lat @3 :UInt64; # previous log term
|
|
||||||
ent @4 :List(Rent); # entries
|
|
||||||
cit @5 :UInt64; # leader commitIndex
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Revo { # RequestVote
|
|
||||||
tem @0 :UInt64; # term
|
|
||||||
cid @1 :Text; # candidate ID
|
|
||||||
lai @2 :UInt64; # last log index
|
lai @2 :UInt64; # last log index
|
||||||
lat @3 :UInt64; # last log term
|
lat @3 :UInt32; # last log term
|
||||||
|
union {
|
||||||
|
revo @4 :Void; # RequestVote
|
||||||
|
apen :group { # AppendEntries
|
||||||
|
ent @5 :List(Rent); # log entries
|
||||||
|
cit @6 :UInt64; # leader commitIndex
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Rasp { # Raft response
|
struct Rasp { # Raft RPC response
|
||||||
tem @0 :UInt64; # leader's term
|
tem @0 :UInt64; # leader's term
|
||||||
suc @1 :Bool; # success
|
suc @1 :Bool; # success
|
||||||
}
|
}
|
||||||
|
@ -72,12 +72,12 @@ Raft_Rent_list new_Raft_Rent_list(struct capn_segment *s, int len) {
|
|||||||
}
|
}
|
||||||
void read_Raft_Rent(struct Raft_Rent *s, Raft_Rent_ptr p) {
|
void read_Raft_Rent(struct Raft_Rent *s, Raft_Rent_ptr p) {
|
||||||
capn_resolve(&p.p);
|
capn_resolve(&p.p);
|
||||||
s->tem = capn_read64(p.p, 0);
|
s->tem = capn_read32(p.p, 0);
|
||||||
s->cmd.p = capn_getp(p.p, 0, 0);
|
s->cmd.p = capn_getp(p.p, 0, 0);
|
||||||
}
|
}
|
||||||
void write_Raft_Rent(const struct Raft_Rent *s, Raft_Rent_ptr p) {
|
void write_Raft_Rent(const struct Raft_Rent *s, Raft_Rent_ptr p) {
|
||||||
capn_resolve(&p.p);
|
capn_resolve(&p.p);
|
||||||
capn_write64(p.p, 0, s->tem);
|
capn_write32(p.p, 0, s->tem);
|
||||||
capn_setp(p.p, 0, s->cmd.p);
|
capn_setp(p.p, 0, s->cmd.p);
|
||||||
}
|
}
|
||||||
void get_Raft_Rent(struct Raft_Rent *s, Raft_Rent_list l, int i) {
|
void get_Raft_Rent(struct Raft_Rent *s, Raft_Rent_list l, int i) {
|
||||||
@ -91,78 +91,57 @@ void set_Raft_Rent(const struct Raft_Rent *s, Raft_Rent_list l, int i) {
|
|||||||
write_Raft_Rent(s, p);
|
write_Raft_Rent(s, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
Raft_Apen_ptr new_Raft_Apen(struct capn_segment *s) {
|
Raft_Rest_ptr new_Raft_Rest(struct capn_segment *s) {
|
||||||
Raft_Apen_ptr p;
|
Raft_Rest_ptr p;
|
||||||
p.p = capn_new_struct(s, 32, 2);
|
p.p = capn_new_struct(s, 32, 2);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
Raft_Apen_list new_Raft_Apen_list(struct capn_segment *s, int len) {
|
Raft_Rest_list new_Raft_Rest_list(struct capn_segment *s, int len) {
|
||||||
Raft_Apen_list p;
|
Raft_Rest_list p;
|
||||||
p.p = capn_new_list(s, len, 32, 2);
|
p.p = capn_new_list(s, len, 32, 2);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
void read_Raft_Apen(struct Raft_Apen *s, Raft_Apen_ptr p) {
|
void read_Raft_Rest(struct Raft_Rest *s, Raft_Rest_ptr p) {
|
||||||
capn_resolve(&p.p);
|
capn_resolve(&p.p);
|
||||||
s->tem = capn_read64(p.p, 0);
|
s->tem = capn_read32(p.p, 0);
|
||||||
s->cid = capn_get_text(p.p, 0, capn_val0);
|
s->cid = capn_get_text(p.p, 0, capn_val0);
|
||||||
s->lai = capn_read64(p.p, 8);
|
s->lai = capn_read64(p.p, 8);
|
||||||
s->lat = capn_read64(p.p, 16);
|
s->lat = capn_read32(p.p, 4);
|
||||||
s->ent.p = capn_getp(p.p, 1, 0);
|
s->which = (enum Raft_Rest_which) capn_read16(p.p, 16);
|
||||||
s->cit = capn_read64(p.p, 24);
|
switch (s->which) {
|
||||||
|
case Raft_Rest_apen:
|
||||||
|
s->apen.ent.p = capn_getp(p.p, 1, 0);
|
||||||
|
s->apen.cit = capn_read64(p.p, 24);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void write_Raft_Apen(const struct Raft_Apen *s, Raft_Apen_ptr p) {
|
void write_Raft_Rest(const struct Raft_Rest *s, Raft_Rest_ptr p) {
|
||||||
capn_resolve(&p.p);
|
capn_resolve(&p.p);
|
||||||
capn_write64(p.p, 0, s->tem);
|
capn_write32(p.p, 0, s->tem);
|
||||||
capn_set_text(p.p, 0, s->cid);
|
capn_set_text(p.p, 0, s->cid);
|
||||||
capn_write64(p.p, 8, s->lai);
|
capn_write64(p.p, 8, s->lai);
|
||||||
capn_write64(p.p, 16, s->lat);
|
capn_write32(p.p, 4, s->lat);
|
||||||
capn_setp(p.p, 1, s->ent.p);
|
capn_write16(p.p, 16, s->which);
|
||||||
capn_write64(p.p, 24, s->cit);
|
switch (s->which) {
|
||||||
|
case Raft_Rest_apen:
|
||||||
|
capn_setp(p.p, 1, s->apen.ent.p);
|
||||||
|
capn_write64(p.p, 24, s->apen.cit);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void get_Raft_Apen(struct Raft_Apen *s, Raft_Apen_list l, int i) {
|
void get_Raft_Rest(struct Raft_Rest *s, Raft_Rest_list l, int i) {
|
||||||
Raft_Apen_ptr p;
|
Raft_Rest_ptr p;
|
||||||
p.p = capn_getp(l.p, i, 0);
|
p.p = capn_getp(l.p, i, 0);
|
||||||
read_Raft_Apen(s, p);
|
read_Raft_Rest(s, p);
|
||||||
}
|
}
|
||||||
void set_Raft_Apen(const struct Raft_Apen *s, Raft_Apen_list l, int i) {
|
void set_Raft_Rest(const struct Raft_Rest *s, Raft_Rest_list l, int i) {
|
||||||
Raft_Apen_ptr p;
|
Raft_Rest_ptr p;
|
||||||
p.p = capn_getp(l.p, i, 0);
|
p.p = capn_getp(l.p, i, 0);
|
||||||
write_Raft_Apen(s, p);
|
write_Raft_Rest(s, p);
|
||||||
}
|
|
||||||
|
|
||||||
Raft_Revo_ptr new_Raft_Revo(struct capn_segment *s) {
|
|
||||||
Raft_Revo_ptr p;
|
|
||||||
p.p = capn_new_struct(s, 24, 1);
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
Raft_Revo_list new_Raft_Revo_list(struct capn_segment *s, int len) {
|
|
||||||
Raft_Revo_list p;
|
|
||||||
p.p = capn_new_list(s, len, 24, 1);
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
void read_Raft_Revo(struct Raft_Revo *s, Raft_Revo_ptr p) {
|
|
||||||
capn_resolve(&p.p);
|
|
||||||
s->tem = capn_read64(p.p, 0);
|
|
||||||
s->cid = capn_get_text(p.p, 0, capn_val0);
|
|
||||||
s->lai = capn_read64(p.p, 8);
|
|
||||||
s->lat = capn_read64(p.p, 16);
|
|
||||||
}
|
|
||||||
void write_Raft_Revo(const struct Raft_Revo *s, Raft_Revo_ptr p) {
|
|
||||||
capn_resolve(&p.p);
|
|
||||||
capn_write64(p.p, 0, s->tem);
|
|
||||||
capn_set_text(p.p, 0, s->cid);
|
|
||||||
capn_write64(p.p, 8, s->lai);
|
|
||||||
capn_write64(p.p, 16, s->lat);
|
|
||||||
}
|
|
||||||
void get_Raft_Revo(struct Raft_Revo *s, Raft_Revo_list l, int i) {
|
|
||||||
Raft_Revo_ptr p;
|
|
||||||
p.p = capn_getp(l.p, i, 0);
|
|
||||||
read_Raft_Revo(s, p);
|
|
||||||
}
|
|
||||||
void set_Raft_Revo(const struct Raft_Revo *s, Raft_Revo_list l, int i) {
|
|
||||||
Raft_Revo_ptr p;
|
|
||||||
p.p = capn_getp(l.p, i, 0);
|
|
||||||
write_Raft_Revo(s, p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Raft_Rasp_ptr new_Raft_Rasp(struct capn_segment *s) {
|
Raft_Rasp_ptr new_Raft_Rasp(struct capn_segment *s) {
|
||||||
|
Loading…
Reference in New Issue
Block a user