@@ -94,60 +94,69 @@ impl Default for Http {
94
94
#[ derive( Deserialize , Debug ) ]
95
95
pub struct Distributed {
96
96
pub peer_address : SocketAddr ,
97
- pub sync : Sync ,
97
+ pub replicas : Replicas ,
98
98
pub peers : Peers ,
99
99
}
100
100
101
- /// Type of synchronisation of the blobs between nodes .
101
+ /// The amount of replicas of the blob stored .
102
102
#[ derive( Copy , Clone , Debug ) ]
103
- pub enum Sync {
104
- /// Full synchronisation: all nodes store all blobs (default).
105
- Full ,
103
+ pub enum Replicas {
104
+ /// All nodes store all blobs (default).
105
+ All ,
106
+ /// A single node stores a blob.
107
+ One ,
108
+ /// `(N/2)+1` nodes store a blob, where `N` is the total number of nodes in
109
+ /// the system.
110
+ Majority ,
106
111
}
107
112
108
- impl Default for Sync {
109
- fn default ( ) -> Sync {
110
- Sync :: Full
113
+ impl Default for Replicas {
114
+ fn default ( ) -> Replicas {
115
+ Replicas :: All
111
116
}
112
117
}
113
118
114
- impl fmt:: Display for Sync {
119
+ impl fmt:: Display for Replicas {
115
120
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
116
121
match self {
117
- Sync :: Full => f. write_str ( "full" ) ,
122
+ Replicas :: All => f. write_str ( "all" ) ,
123
+ Replicas :: One => f. write_str ( "one" ) ,
124
+ Replicas :: Majority => f. write_str ( "majority" ) ,
118
125
}
119
126
}
120
127
}
121
128
122
- /// Error returned by `FromStr` implementation for [`Sync `].
123
- pub struct ParseSyncErr ( ( ) ) ;
129
+ /// Error returned by `FromStr` implementation for [`Replicas `].
130
+ pub struct ParseReplicasErr ( ( ) ) ;
124
131
125
- impl fmt:: Display for ParseSyncErr {
132
+ impl fmt:: Display for ParseReplicasErr {
126
133
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
127
- f. write_str ( "invalid synchronisation method " )
134
+ f. write_str ( "invalid replicas " )
128
135
}
129
136
}
130
137
131
- impl FromStr for Sync {
132
- type Err = ParseSyncErr ;
138
+ impl FromStr for Replicas {
139
+ type Err = ParseReplicasErr ;
133
140
134
141
fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
135
142
match s {
136
- "full" => Ok ( Sync :: Full ) ,
137
- _ => Err ( ParseSyncErr ( ( ) ) ) ,
143
+ "all" => Ok ( Replicas :: All ) ,
144
+ "one" => Ok ( Replicas :: One ) ,
145
+ "majority" => Ok ( Replicas :: Majority ) ,
146
+ _ => Err ( ParseReplicasErr ( ( ) ) ) ,
138
147
}
139
148
}
140
149
}
141
150
142
- impl < ' de > Deserialize < ' de > for Sync {
151
+ impl < ' de > Deserialize < ' de > for Replicas {
143
152
fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
144
153
where
145
154
D : Deserializer < ' de > ,
146
155
{
147
- struct SyncVisitor ;
156
+ struct ReplicasVisitor ;
148
157
149
- impl < ' de > Visitor < ' de > for SyncVisitor {
150
- type Value = Sync ;
158
+ impl < ' de > Visitor < ' de > for ReplicasVisitor {
159
+ type Value = Replicas ;
151
160
152
161
fn expecting ( & self , formatter : & mut fmt:: Formatter ) -> fmt:: Result {
153
162
formatter. write_str ( "a string" )
@@ -157,11 +166,11 @@ impl<'de> Deserialize<'de> for Sync {
157
166
where
158
167
E : Error ,
159
168
{
160
- Sync :: from_str ( s) . map_err ( Error :: custom)
169
+ Replicas :: from_str ( s) . map_err ( Error :: custom)
161
170
}
162
171
}
163
172
164
- deserializer. deserialize_str ( SyncVisitor )
173
+ deserializer. deserialize_str ( ReplicasVisitor )
165
174
}
166
175
}
167
176
0 commit comments