@@ -31,6 +31,8 @@ pub struct ClientConfiguration {
3131 pub peer_count_per_ip_max : usize ,
3232 #[ wasm_bindgen( skip) ]
3333 pub peer_count_per_subnet_max : usize ,
34+ #[ wasm_bindgen( skip) ]
35+ pub sync_mode : String ,
3436}
3537
3638#[ cfg( any( feature = "client" , feature = "primitives" ) ) ]
@@ -58,6 +60,8 @@ pub struct PlainClientConfiguration {
5860 pub peer_count_per_ip_max : Option < usize > ,
5961 #[ cfg_attr( feature = "client" , serde( skip_serializing_if = "Option::is_none" ) ) ]
6062 pub peer_count_per_subnet_max : Option < usize > ,
63+ #[ cfg_attr( feature = "client" , serde( skip_serializing_if = "Option::is_none" ) ) ]
64+ pub sync_mode : Option < String > ,
6165}
6266
6367impl Default for ClientConfiguration {
@@ -86,6 +90,7 @@ impl Default for ClientConfiguration {
8690 peer_count_max : 50 ,
8791 peer_count_per_ip_max : 10 ,
8892 peer_count_per_subnet_max : 10 ,
93+ sync_mode : "light" . to_string ( ) ,
8994 }
9095 }
9196}
@@ -166,6 +171,14 @@ impl ClientConfiguration {
166171 self . peer_count_per_subnet_max = peer_count_per_subnet_max;
167172 }
168173
174+ /// Sets the sync mode that shoud be used.
175+ /// Only "light" and "pico" are supported for web clients
176+ /// Default is "light"
177+ #[ wasm_bindgen( js_name = syncMode) ]
178+ pub fn sync_mode ( & mut self , sync_mode : String ) {
179+ self . sync_mode = sync_mode. to_lowercase ( ) ;
180+ }
181+
169182 // TODO: Find a way to make this method work, maybe by using the synthetic Client from the main thread as an import?
170183 // /// Instantiates a client from this configuration builder.
171184 // #[wasm_bindgen(js_name = instantiateClient)]
@@ -187,6 +200,7 @@ impl ClientConfiguration {
187200 peer_count_max : Some ( self . peer_count_max ) ,
188201 peer_count_per_ip_max : Some ( self . peer_count_per_ip_max ) ,
189202 peer_count_per_subnet_max : Some ( self . peer_count_per_subnet_max ) ,
203+ sync_mode : Some ( self . sync_mode . clone ( ) ) ,
190204 } )
191205 . unwrap ( )
192206 . into ( )
@@ -233,6 +247,15 @@ impl TryFrom<PlainClientConfiguration> for ClientConfiguration {
233247 client_config. peer_count_per_subnet_max = peer_count_per_subnet_max;
234248 }
235249
250+ if let Some ( sync_mode) = config. sync_mode {
251+ // Only "pico" and "light" sync modes are supported for web clients
252+ if !( sync_mode == "pico" || sync_mode == "light" ) {
253+ return Err ( JsError :: new ( & format ! ( "Invalid sync mode: {}" , sync_mode) ) ) ;
254+ }
255+
256+ client_config. sync_mode = sync_mode;
257+ }
258+
236259 Ok ( client_config)
237260 }
238261}
0 commit comments