@@ -6,8 +6,6 @@ Toxcore daemon may serialize its states to file with some interval.
66
77use futures:: future;
88
9- use tox_packet:: dht:: packed_node:: * ;
10-
119use crate :: dht:: server:: * ;
1210use crate :: state_format:: old:: * ;
1311use tox_binary_io:: * ;
@@ -54,11 +52,7 @@ pub const DHT_STATE_BUFFER_SIZE: usize =
5452impl DaemonState {
5553 /// Serialize DHT states, old means that the format of seriaization is old version
5654 pub async fn serialize_old ( server : & Server ) -> Vec < u8 > {
57- let close_nodes = server. close_nodes . read ( ) . await ;
58-
59- let nodes = close_nodes. iter ( )
60- . flat_map ( |node| node. to_packed_node ( ) )
61- . collect :: < Vec < PackedNode > > ( ) ;
55+ let nodes = server. get_all_nodes ( ) . await ;
6256
6357 let mut buf = [ 0u8 ; DHT_STATE_BUFFER_SIZE ] ;
6458 let ( _, buf_len) = DhtState ( nodes) . to_bytes ( ( & mut buf, 0 ) ) . expect ( "DhtState(nodes).to_bytes has failed" ) ;
@@ -93,6 +87,7 @@ mod tests {
9387 use rand:: thread_rng;
9488 use tox_crypto:: * ;
9589 use tox_packet:: dht:: * ;
90+ use tox_packet:: dht:: packed_node:: * ;
9691
9792 use futures:: channel:: mpsc;
9893 use futures:: StreamExt ;
@@ -115,10 +110,14 @@ mod tests {
115110 let ( tx, rx) = mpsc:: channel ( 1 ) ;
116111 let alice = Server :: new ( tx, pk. clone ( ) , sk) ;
117112
113+ // test with empty close list
114+ let serialized_vec = DaemonState :: serialize_old ( & alice) . await ;
115+ assert ! ( DaemonState :: deserialize_old( & alice, & serialized_vec) . await . is_ok( ) ) ;
116+
118117 let addr_org = "1.2.3.4:1234" . parse ( ) . unwrap ( ) ;
119118 let pk_org = SecretKey :: generate ( & mut rng) . public_key ( ) ;
120119 let pn = PackedNode { pk : pk_org. clone ( ) , saddr : addr_org } ;
121- alice. close_nodes . write ( ) . await . try_add ( pn ) ;
120+ alice. add_node ( pn ) . await ;
122121
123122 let serialized_vec = DaemonState :: serialize_old ( & alice) . await ;
124123 DaemonState :: deserialize_old ( & alice, & serialized_vec) . await . unwrap ( ) ;
@@ -148,10 +147,5 @@ mod tests {
148147 let error = res. err ( ) . unwrap ( ) ;
149148 assert_eq ! ( error, DeserializeError :: Deserialize { error: Err :: Error ( NomError :: new(
150149 vec![ 42 ; 10 ] , NomErrorKind :: Tag ) ) , data: serialized_vec. to_vec( ) } ) ;
151-
152- // test with empty close list
153- alice. close_nodes . write ( ) . await . remove ( & pk_org) ;
154- let serialized_vec = DaemonState :: serialize_old ( & alice) . await ;
155- assert ! ( DaemonState :: deserialize_old( & alice, & serialized_vec) . await . is_ok( ) ) ;
156150 }
157151}
0 commit comments