Skip to content

Commit 161ff68

Browse files
committed
use strings for client id
1 parent fdc121b commit 161ff68

22 files changed

+111
-78
lines changed

Diff for: extraction/aggregation-dynamic/coq/ExtractTreeAggregation.v

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Require Import mathcomp.algebra.zmodp.
1717

1818
Require Import ExtrOcamlBasic.
1919
Require Import ExtrOcamlNatInt.
20+
Require Import ExtrOcamlString.
2021

2122
Require Import ExtrOcamlBasicExt.
2223
Require Import ExtrOcamlNatIntExt.

Diff for: extraction/aggregation-dynamic/ocaml/Serialization.ml

+8-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ open Printf
33
open Scanf
44
open TreeAggregation
55
open TreeAggregationNames
6+
open Util
67

78
let serializeName : Names.name -> string = string_of_int
89

@@ -16,24 +17,24 @@ let deserializeMsg : string -> coq_Msg = fun s ->
1617
let serializeMsg : coq_Msg -> string = fun msg ->
1718
Marshal.to_string msg []
1819

19-
let deserializeInput (s : string) (client_id : int) : coq_Input option =
20+
let deserializeInput (s : string) (c : string) : coq_Input option =
2021
match s with
2122
| "SendAggregate" -> Some SendAggregate
2223
| "Broadcast" -> Some Broadcast
23-
| "AggregateRequest" -> Some (AggregateRequest client_id)
24-
| "LevelRequest" -> Some (LevelRequest client_id)
24+
| "AggregateRequest" -> Some (AggregateRequest (char_list_of_string c))
25+
| "LevelRequest" -> Some (LevelRequest (char_list_of_string c))
2526
| _ ->
26-
try sscanf s "Local %d" (fun x -> Some (Local (Obj.magic x)))
27+
try Scanf.sscanf s "Local %d" (fun x -> Some (Local (Obj.magic x)))
2728
with _ -> None
2829

2930
let serializeLevelOption olv : string =
3031
match olv with
3132
| Some lv -> string_of_int lv
3233
| _ -> ""
3334

34-
let serializeOutput : coq_Output -> int * string = function
35-
| AggregateResponse (client_id, x) -> (client_id, sprintf "AggregateResponse %d" (Obj.magic x))
36-
| LevelResponse (client_id, olv) -> (client_id, sprintf "LevelResponse %s" (serializeLevelOption olv))
35+
let serializeOutput : coq_Output -> string * string = function
36+
| AggregateResponse (c, x) -> (string_of_char_list c, sprintf "AggregateResponse %d" (Obj.magic x))
37+
| LevelResponse (c, olv) -> (string_of_char_list c, sprintf "LevelResponse %s" (serializeLevelOption olv))
3738

3839
let debugSerializeInput : coq_Input -> string = function
3940
| SendAggregate -> "SendAggregate"

Diff for: extraction/aggregation-dynamic/ocaml/TreeAggregationArrangement.ml

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module TreeAggregationArrangement = struct
88
type output = coq_Output
99
type msg = coq_Msg
1010
type res = (output list * state) * ((name * msg) list)
11+
type client_id = string
1112

1213
let systemName : string = "Dynamic Tree Aggregation Protocol"
1314

@@ -28,13 +29,13 @@ module TreeAggregationArrangement = struct
2829

2930
let setTimeout : name -> state -> float = fun _ _ -> 1.0
3031

31-
let deserializeMsg : string -> msg = Serialization.deserializeMsg
32+
let deserializeMsg = Serialization.deserializeMsg
3233

33-
let serializeMsg : msg -> string = Serialization.serializeMsg
34+
let serializeMsg = Serialization.serializeMsg
3435

3536
let deserializeInput = Serialization.deserializeInput
3637

37-
let serializeOutput : output -> int * string = Serialization.serializeOutput
38+
let serializeOutput = Serialization.serializeOutput
3839

3940
let failMsg = Some Fail
4041

@@ -55,5 +56,6 @@ module TreeAggregationArrangement = struct
5556
print_newline ()
5657

5758
let debugTimeout : state -> unit = fun _ -> ()
58-
end
5959

60+
let createClientId () = Uuidm.to_string (Uuidm.create `V4)
61+
end

Diff for: extraction/aggregation/coq/ExtractTreeAggregation.v

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Require Import mathcomp.algebra.zmodp.
1818

1919
Require Import ExtrOcamlBasic.
2020
Require Import ExtrOcamlNatInt.
21+
Require Import ExtrOcamlString.
2122

2223
Require Import ExtrOcamlBasicExt.
2324
Require Import ExtrOcamlNatIntExt.

Diff for: extraction/aggregation/ocaml/Serialization.ml

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ open Printf
33
open Scanf
44
open TreeAggregation
55
open TreeAggregationNames
6+
open Util
67

78
let serializeName : Names.name -> string = string_of_int
89

@@ -16,12 +17,12 @@ let deserializeMsg : string -> coq_Msg = fun s ->
1617
let serializeMsg : coq_Msg -> string = fun msg ->
1718
Marshal.to_string msg []
1819

19-
let deserializeInput (s : string) (client_id : int) : coq_Input option =
20+
let deserializeInput (s : string) (c : string) : coq_Input option =
2021
match s with
2122
| "SendAggregate" -> Some SendAggregate
2223
| "Broadcast" -> Some Broadcast
23-
| "AggregateRequest" -> Some (AggregateRequest client_id)
24-
| "LevelRequest" -> Some (LevelRequest client_id)
24+
| "AggregateRequest" -> Some (AggregateRequest (char_list_of_string c))
25+
| "LevelRequest" -> Some (LevelRequest (char_list_of_string c))
2526
| _ ->
2627
try Scanf.sscanf s "Local %d" (fun x -> Some (Local (Obj.magic x)))
2728
with _ -> None
@@ -31,9 +32,9 @@ let serializeLevelOption olv : string =
3132
| Some lv -> string_of_int lv
3233
| _ -> "-"
3334

34-
let serializeOutput : coq_Output -> int * string = function
35-
| AggregateResponse (client_id, x) -> (client_id, sprintf "AggregateResponse %d" (Obj.magic x))
36-
| LevelResponse (client_id, olv) -> (client_id, sprintf "LevelResponse %s" (serializeLevelOption olv))
35+
let serializeOutput : coq_Output -> string * string = function
36+
| AggregateResponse (c, x) -> (string_of_char_list c, sprintf "AggregateResponse %d" (Obj.magic x))
37+
| LevelResponse (c, olv) -> (string_of_char_list c, sprintf "LevelResponse %s" (serializeLevelOption olv))
3738

3839
let debugSerializeInput : coq_Input -> string = function
3940
| SendAggregate -> "SendAggregate"

Diff for: extraction/aggregation/ocaml/TreeAggregationArrangement.ml

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module TreeAggregationArrangement = struct
88
type output = coq_Output
99
type msg = coq_Msg
1010
type res = (output list * state) * ((name * msg) list)
11+
type client_id = string
1112

1213
let systemName : string = "Static Tree Aggregation Protocol"
1314

@@ -32,9 +33,9 @@ module TreeAggregationArrangement = struct
3233

3334
let serializeMsg : msg -> string = Serialization.serializeMsg
3435

35-
let deserializeInput : string -> int -> input option = Serialization.deserializeInput
36+
let deserializeInput : string -> client_id -> input option = Serialization.deserializeInput
3637

37-
let serializeOutput : output -> int * string = Serialization.serializeOutput
38+
let serializeOutput : output -> client_id * string = Serialization.serializeOutput
3839

3940
let failMsg : msg option = Some Fail
4041

@@ -55,4 +56,6 @@ module TreeAggregationArrangement = struct
5556
print_newline ()
5657

5758
let debugTimeout : state -> unit = fun _ -> ()
59+
60+
let createClientId () = Uuidm.to_string (Uuidm.create `V4)
5861
end

Diff for: extraction/tree-dynamic/coq/ExtractTree.v

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Require Import StructTact.Fin.
88

99
Require Import ExtrOcamlBasic.
1010
Require Import ExtrOcamlNatInt.
11+
Require Import ExtrOcamlString.
1112

1213
Require Import ExtrOcamlBasicExt.
1314
Require Import ExtrOcamlNatIntExt.

Diff for: extraction/tree-dynamic/ocaml/Serialization.ml

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ open Printf
33
open Scanf
44
open Tree
55
open TreeNames
6+
open Util
67

78
let serializeName : Names.name -> string = string_of_int
89

@@ -16,19 +17,19 @@ let deserializeMsg : string -> coq_Msg = fun s ->
1617
let serializeMsg : coq_Msg -> string = fun msg ->
1718
Marshal.to_string msg []
1819

19-
let deserializeInput (s : string) (client_id : int) : coq_Input option =
20+
let deserializeInput (s : string) (c : string) : coq_Input option =
2021
match s with
2122
| "Broadcast" -> Some Broadcast
22-
| "LevelRequest" -> Some (LevelRequest client_id)
23+
| "LevelRequest" -> Some (LevelRequest (char_list_of_string c))
2324
| _ -> None
2425

2526
let serializeLevelOption olv : string =
2627
match olv with
2728
| Some lv -> string_of_int lv
2829
| _ -> "-"
2930

30-
let serializeOutput : coq_Output -> int * string = function
31-
| LevelResponse (client_id, olv) -> (client_id, sprintf "LevelResponse %s" (serializeLevelOption olv))
31+
let serializeOutput : coq_Output -> string * string = function
32+
| LevelResponse (c, olv) -> (string_of_char_list c, sprintf "LevelResponse %s" (serializeLevelOption olv))
3233

3334
let debugSerializeInput : coq_Input -> string = function
3435
| Broadcast -> "Broadcast"

Diff for: extraction/tree-dynamic/ocaml/TreeArrangement.ml

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module TreeArrangement = struct
88
type output = coq_Output
99
type msg = coq_Msg
1010
type res = (output list * state) * ((name * msg) list)
11+
type client_id = string
1112

1213
let systemName : string = "Dynamic Tree Building Protocol"
1314

@@ -55,4 +56,6 @@ module TreeArrangement = struct
5556
print_newline ()
5657

5758
let debugTimeout : state -> unit = fun _ -> ()
59+
60+
let createClientId () = Uuidm.to_string (Uuidm.create `V4)
5861
end

Diff for: extraction/tree/coq/ExtractTree.v

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Require Import StructTact.Fin.
88

99
Require Import ExtrOcamlBasic.
1010
Require Import ExtrOcamlNatInt.
11+
Require Import ExtrOcamlString.
1112

1213
Require Import ExtrOcamlBasicExt.
1314
Require Import ExtrOcamlNatIntExt.

Diff for: extraction/tree/ocaml/Serialization.ml

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ open Printf
33
open Scanf
44
open Tree
55
open TreeNames
6+
open Util
67

78
let serializeName : Names.name -> string = string_of_int
89

@@ -16,19 +17,19 @@ let deserializeMsg : string -> coq_Msg = fun s ->
1617
let serializeMsg : coq_Msg -> string = fun msg ->
1718
Marshal.to_string msg []
1819

19-
let deserializeInput (s : string) (client_id : int) : coq_Input option =
20+
let deserializeInput (s : string) (c : string) : coq_Input option =
2021
match s with
2122
| "Broadcast" -> Some Broadcast
22-
| "LevelRequest" -> Some (LevelRequest client_id)
23+
| "LevelRequest" -> Some (LevelRequest (char_list_of_string c))
2324
| _ -> None
2425

2526
let serializeLevelOption olv : string =
2627
match olv with
2728
| Some lv -> string_of_int lv
2829
| _ -> "-"
2930

30-
let serializeOutput : coq_Output -> int * string = function
31-
| LevelResponse (client_id, olv) -> (client_id, sprintf "LevelResponse %s" (serializeLevelOption olv))
31+
let serializeOutput : coq_Output -> string * string = function
32+
| LevelResponse (c, olv) -> (string_of_char_list c, sprintf "LevelResponse %s" (serializeLevelOption olv))
3233

3334
let debugSerializeInput : coq_Input -> string = function
3435
| Broadcast -> "Broadcast"

Diff for: extraction/tree/ocaml/TreeArrangement.ml

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module TreeArrangement = struct
88
type output = coq_Output
99
type msg = coq_Msg
1010
type res = (output list * state) * ((name * msg) list)
11+
type client_id = string
1112

1213
let systemName : string = "Static Tree Building Protocol"
1314

@@ -55,4 +56,6 @@ module TreeArrangement = struct
5556
print_newline ()
5657

5758
let debugTimeout : state -> unit = fun _ -> ()
59+
60+
let createClientId () = Uuidm.to_string (Uuidm.create `V4)
5861
end

Diff for: systems/AggregationDynamic.v

+11-9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Require Import mathcomp.ssreflect.fintype.
1414
Require Import mathcomp.ssreflect.finset.
1515
Require Import mathcomp.fingroup.fingroup.
1616

17+
Require String.
18+
1719
Local Arguments update {_} {_} _ _ _ _ _ : simpl never.
1820

1921
Set Implicit Arguments.
@@ -42,24 +44,24 @@ Defined.
4244
Inductive Input : Type :=
4345
| Local : m -> Input
4446
| SendAggregate : name -> Input
45-
| AggregateRequest : nat -> Input.
47+
| AggregateRequest : String.string -> Input.
4648

4749
Definition Input_eq_dec : forall x y : Input, {x = y} + {x <> y}.
48-
decide equality; auto using Nat.eq_dec, m_eq_dec, name_eq_dec.
50+
decide equality; auto using String.string_dec, m_eq_dec, name_eq_dec.
4951
Defined.
5052

5153
Inductive Output : Type :=
52-
| AggregateResponse : nat -> m -> Output.
54+
| AggregateResponse : String.string -> m -> Output.
5355

5456
Definition Output_eq_dec : forall x y : Output, {x = y} + {x <> y}.
55-
decide equality; auto using Nat.eq_dec, m_eq_dec.
57+
decide equality; auto using String.string_dec, m_eq_dec.
5658
Defined.
5759

58-
Record Data := mkData {
59-
local : m ;
60-
aggregate : m ;
61-
adjacent : NS ;
62-
balance : NM
60+
Record Data := mkData {
61+
local : m ;
62+
aggregate : m ;
63+
adjacent : NS ;
64+
balance : NM
6365
}.
6466

6567
Definition InitData (n : name) :=

Diff for: systems/AggregationStatic.v

+6-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Require Import mathcomp.ssreflect.fintype.
1515
Require Import mathcomp.ssreflect.finset.
1616
Require Import mathcomp.fingroup.fingroup.
1717

18+
Require String.
19+
1820
Local Arguments update {_} {_} _ _ _ _ _ : simpl never.
1921

2022
Set Implicit Arguments.
@@ -43,17 +45,17 @@ Defined.
4345
Inductive Input : Type :=
4446
| Local : m -> Input
4547
| SendAggregate : name -> Input
46-
| AggregateRequest : nat -> Input.
48+
| AggregateRequest : String.string -> Input.
4749

4850
Definition Input_eq_dec : forall x y : Input, {x = y} + {x <> y}.
49-
decide equality; auto using Nat.eq_dec, m_eq_dec, name_eq_dec.
51+
decide equality; auto using String.string_dec, m_eq_dec, name_eq_dec.
5052
Defined.
5153

5254
Inductive Output : Type :=
53-
| AggregateResponse : nat -> m -> Output.
55+
| AggregateResponse : String.string -> m -> Output.
5456

5557
Definition Output_eq_dec : forall x y : Output, {x = y} + {x <> y}.
56-
decide equality; auto using Nat.eq_dec, m_eq_dec.
58+
decide equality; auto using String.string_dec, m_eq_dec.
5759
Defined.
5860

5961
Record Data := mkData {

Diff for: systems/AggregatorDynamic.v

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Require Import Orders.
1111
Require Import MSetFacts.
1212
Require Import MSetProperties.
1313
Require Import Sumbool.
14+
Require String.
1415

1516
Require Import mathcomp.ssreflect.ssreflect.
1617
Require Import mathcomp.ssreflect.ssrbool.
@@ -50,7 +51,7 @@ Inductive Input : Type :=
5051
| New : name -> Input
5152
| Local : m -> Input
5253
| SendAggregate : name -> Input
53-
| AggregateRequest : nat -> Input.
54+
| AggregateRequest : String.string -> Input.
5455

5556
Definition Input_eq_dec : forall x y : Input, {x = y} + {x <> y}.
5657
decide equality.
@@ -60,14 +61,14 @@ decide equality.
6061
- exact: name_eq_dec.
6162
- exact: m_eq_dec.
6263
- exact: name_eq_dec.
63-
- exact: Nat.eq_dec.
64+
- exact: String.string_dec.
6465
Defined.
6566

6667
Inductive Output : Type :=
67-
| AggregateResponse : nat -> m -> Output.
68+
| AggregateResponse : String.string -> m -> Output.
6869

6970
Definition Output_eq_dec : forall x y : Output, {x = y} + {x <> y}.
70-
decide equality; auto using Nat.eq_dec, m_eq_dec.
71+
decide equality; auto using String.string_dec, m_eq_dec.
7172
Defined.
7273

7374
Record Data := mkData {

0 commit comments

Comments
 (0)