@@ -17,7 +17,7 @@ pub fn main() !void {
1717 if (arg_iter .next ()) | arg_str | {
1818 std .debug .print ("arg_str {s}\n " , .{arg_str });
1919 if (std .mem .eql (u8 , "dot" , arg_str )) {
20- const graph : ps.Graph = try ps .Graph .initWithFsm (gpa , Random2pc );
20+ const graph : ps.Graph = try ps .Graph .initWithFsm (gpa , Start );
2121 const graph_fs = try std .fs .cwd ().createFile ("t.dot" , .{});
2222 var graph_fs_writer = graph_fs .writer (try gpa .alloc (u8 , 1 << 20 ));
2323 try graph .generateDot (& graph_fs_writer .interface );
@@ -108,7 +108,7 @@ const CharlieContext = struct {
108108};
109109
110110const SelectorContext = struct {
111- times_2pc : u32 = 0 ,
111+ times : u32 = 0 ,
112112 xoshiro256 : std.Random.Xoshiro256 = undefined ,
113113};
114114
@@ -119,7 +119,7 @@ const Context = struct {
119119 selector : type = SelectorContext ,
120120};
121121
122- pub const EnterFsmState = Random2pc ;
122+ pub const EnterFsmState = Start ;
123123
124124pub const Runner = ps .Runner (EnterFsmState );
125125pub const curr_id = Runner .idFromState (EnterFsmState );
@@ -147,31 +147,32 @@ fn BAC(Next: type) type {
147147}
148148
149149//Randomly select a 2pc protocol
150- pub const Random2pc = union (enum ) {
150+ pub const Start = union (enum ) {
151151 charlie_as_coordinator : Data (void , PingPong (.alice , .bob , PingPong (.bob , .charlie , PingPong (
152152 .charlie ,
153153 .alice ,
154- CAB (@This ()).Start ,
155- ).Start ). Start ). Start ),
156- alice_as_coordinator : Data (void , PingPong (.charlie , .bob , ABC (@This ()).Start ). Start ),
157- bob_as_coordinator : Data (void , PingPong (.alice , .charlie , BAC (@This ()).Start ). Start ),
154+ CAB (@This ()).Begin ,
155+ ).Ping ). Ping ). Ping ),
156+ alice_as_coordinator : Data (void , PingPong (.charlie , .bob , ABC (@This ()).Begin ). Ping ),
157+ bob_as_coordinator : Data (void , PingPong (.alice , .charlie , BAC (@This ()).Begin ). Ping ),
158158 exit : Data (void , ps .Exit ),
159159
160160 pub const info : ps .ProtocolInfo (
161- "random_2pc " ,
161+ "random_pingpong_and_2pc " ,
162162 AllRole ,
163163 Context {},
164164 &.{ .selector , .charlie , .alice , .bob },
165165 &.{},
166166 ) = .{
167+ .name = "Start" ,
167168 .sender = .selector ,
168169 .receiver = &.{ .charlie , .alice , .bob },
169170 };
170171
171172 pub fn process (ctx : * SelectorContext ) ! @This () {
172- ctx .times_2pc += 1 ;
173- std .debug .print ("times_2pc : {d}\n " , .{ctx .times_2pc });
174- if (ctx .times_2pc > 300 ) {
173+ ctx .times += 1 ;
174+ std .debug .print ("times : {d}\n " , .{ctx .times });
175+ if (ctx .times > 300 ) {
175176 return .{ .exit = .{ .data = {} } };
176177 }
177178
@@ -196,20 +197,24 @@ pub fn mk2pc(
196197 Failed : type ,
197198) type {
198199 return struct {
199- fn two_pc (sender : Role , receiver : []const Role ) ps.ProtocolInfo (
200+ fn two_pc (
201+ StateName : []const u8 ,
202+ sender : Role ,
203+ receiver : []const Role ,
204+ ) ps.ProtocolInfo (
200205 "2pc_generic" ,
201206 Role ,
202207 context ,
203208 &.{ coordinator , alice , bob },
204209 &.{ Successed , Failed },
205210 ) {
206- return .{ .sender = sender , .receiver = receiver };
211+ return .{ .name = StateName , . sender = sender , .receiver = receiver };
207212 }
208213
209- pub const Start = union (enum ) {
214+ pub const Begin = union (enum ) {
210215 begin : Data (void , AliceResp ),
211216
212- pub const info = two_pc (coordinator , &.{ alice , bob });
217+ pub const info = two_pc ("Begin" , coordinator , &.{ alice , bob });
213218
214219 pub fn process (ctx : * info .Ctx (coordinator )) ! @This () {
215220 ctx .counter = 0 ;
@@ -220,7 +225,7 @@ pub fn mk2pc(
220225 pub const AliceResp = union (enum ) {
221226 resp : Data (bool , BobResp ),
222227
223- pub const info = two_pc (alice , &.{coordinator });
228+ pub const info = two_pc ("AliceResp" , alice , &.{coordinator });
224229
225230 pub fn process (ctx : * info .Ctx (alice )) ! @This () {
226231 const random : std.Random = ctx .xoshiro256 .random ();
@@ -241,7 +246,7 @@ pub fn mk2pc(
241246 union (enum ) {
242247 resp : Data (bool , Check ),
243248
244- pub const info = two_pc (bob , &.{coordinator });
249+ pub const info = two_pc ("BobResp" , bob , &.{coordinator });
245250
246251 pub fn process (ctx : * info .Ctx (bob )) ! @This () {
247252 const random : std.Random = ctx .xoshiro256 .random ();
@@ -261,9 +266,9 @@ pub fn mk2pc(
261266 pub const Check = union (enum ) {
262267 succcessed : Data (void , Successed ),
263268 failed : Data (void , Failed ),
264- failed_retry : Data (void , Start ),
269+ failed_retry : Data (void , Begin ),
265270
266- pub const info = two_pc (coordinator , &.{ alice , bob });
271+ pub const info = two_pc ("Check" , coordinator , &.{ alice , bob });
267272
268273 pub fn process (ctx : * info .Ctx (coordinator )) ! @This () {
269274 if (ctx .counter == 2 ) {
0 commit comments