@@ -3,7 +3,7 @@ use duva::{
33 clients:: authentications:: { AuthRequest , AuthResponse } ,
44 domains:: query_parsers:: query_io:: { QueryIO , deserialize} ,
55 prelude:: {
6- BytesMut ,
6+ BytesMut , PeerIdentifier ,
77 tokio:: {
88 self ,
99 io:: { AsyncReadExt , AsyncWriteExt } ,
@@ -19,27 +19,31 @@ pub struct ClientController<T> {
1919 client_id : Uuid ,
2020 request_id : u64 ,
2121 latest_known_index : u64 ,
22+ cluster_nodes : Vec < PeerIdentifier > ,
2223 pub target : T ,
2324}
2425
2526impl < T > ClientController < T > {
2627 pub async fn new ( editor : T , server_addr : & str ) -> Self {
27- let ( stream, client_id, request_id) =
28- ClientController :: < T > :: authenticate ( server_addr) . await ;
29- Self { stream, client_id, target : editor, latest_known_index : 0 , request_id }
28+ let ( stream, mut auth_response) = ClientController :: < T > :: authenticate ( server_addr) . await ;
29+ auth_response. cluster_nodes . push ( server_addr. to_string ( ) . into ( ) ) ;
30+ Self {
31+ stream,
32+ client_id : Uuid :: parse_str ( & auth_response. client_id ) . unwrap ( ) ,
33+ target : editor,
34+ latest_known_index : 0 ,
35+ request_id : auth_response. request_id ,
36+ cluster_nodes : auth_response. cluster_nodes ,
37+ }
3038 }
3139
32- async fn authenticate ( server_addr : & str ) -> ( TcpStream , Uuid , u64 ) {
40+ async fn authenticate ( server_addr : & str ) -> ( TcpStream , AuthResponse ) {
3341 let mut stream = TcpStream :: connect ( server_addr) . await . unwrap ( ) ;
3442 stream. serialized_write ( AuthRequest :: default ( ) ) . await . unwrap ( ) ; // client_id not exist
3543
36- let AuthResponse { client_id, request_id } = stream. deserialized_read ( ) . await . unwrap ( ) ;
37-
38- let client_id = Uuid :: parse_str ( & client_id) . unwrap ( ) ;
39- println ! ( "Client ID: {}" , client_id) ;
40- println ! ( "Connected to Redis at {}" , server_addr) ;
44+ let auth_response: AuthResponse = stream. deserialized_read ( ) . await . unwrap ( ) ;
4145
42- ( stream, client_id , request_id )
46+ ( stream, auth_response )
4347 }
4448
4549 pub async fn send_command (
0 commit comments