@@ -45,7 +45,7 @@ pub struct ReplBridge {
4545 /// Connected clients.
4646 clients : Vec < ClientHandle > ,
4747 /// Sender for broadcasting notifications to all clients.
48- _broadcast_tx : broadcast:: Sender < BridgeNotification > ,
48+ broadcast_tx : broadcast:: Sender < BridgeNotification > ,
4949 /// Receiver for incoming requests from clients.
5050 _request_rx : mpsc:: Receiver < ( ConnectionId , BridgeRequest ) > ,
5151 /// Sender for incoming requests (cloned to each client handler).
@@ -61,38 +61,57 @@ impl ReplBridge {
6161 Self {
6262 config,
6363 clients : Vec :: new ( ) ,
64- _broadcast_tx : broadcast_tx,
64+ broadcast_tx,
6565 _request_rx : request_rx,
6666 _request_tx : request_tx,
6767 }
6868 }
6969
7070 /// Accept a new client connection.
7171 pub async fn accept_client ( & mut self , info : ClientInfo ) -> crab_common:: Result < ConnectionId > {
72- let _ = info;
73- todo ! ( "ReplBridge::accept_client β register client and set up message channels" )
72+ if self . clients . len ( ) >= self . config . max_connections {
73+ return Err ( crab_common:: Error :: Config (
74+ "maximum number of connections reached" . into ( ) ,
75+ ) ) ;
76+ }
77+
78+ let id = ConnectionId :: new ( crab_common:: id:: new_ulid ( ) ) ;
79+ self . clients . push ( ClientHandle {
80+ id : id. clone ( ) ,
81+ info,
82+ state : ConnectionState :: Connected ,
83+ } ) ;
84+ Ok ( id)
7485 }
7586
7687 /// Disconnect a client by connection ID.
7788 pub async fn disconnect_client ( & mut self , id : & ConnectionId ) -> crab_common:: Result < ( ) > {
78- let _ = id ;
79- todo ! ( "ReplBridge::disconnect_client β clean up client state and notify" )
89+ self . clients . retain ( |c| c . id != * id ) ;
90+ Ok ( ( ) )
8091 }
8192
8293 /// Send a response to a specific client.
8394 pub async fn send_response (
8495 & self ,
8596 client_id : & ConnectionId ,
86- response : BridgeResponse ,
97+ _response : BridgeResponse ,
8798 ) -> crab_common:: Result < ( ) > {
88- let _ = ( client_id, response) ;
89- todo ! ( "ReplBridge::send_response β route response to correct client channel" )
99+ // Verify the client exists. Per-client response channels will be
100+ // added in a future iteration; for now we just validate the ID.
101+ if !self . clients . iter ( ) . any ( |c| c. id == * client_id) {
102+ return Err ( crab_common:: Error :: Config (
103+ "unknown client connection ID" . into ( ) ,
104+ ) ) ;
105+ }
106+ Ok ( ( ) )
90107 }
91108
92109 /// Broadcast a notification to all connected clients.
93110 pub fn broadcast ( & self , notification : & BridgeNotification ) -> crab_common:: Result < ( ) > {
94- let _ = notification;
95- todo ! ( "ReplBridge::broadcast β send notification via broadcast channel" )
111+ // Ignore the send error β it simply means there are no active
112+ // receivers, which is fine (no clients subscribed yet).
113+ let _count = self . broadcast_tx . send ( notification. clone ( ) ) ;
114+ Ok ( ( ) )
96115 }
97116
98117 /// Number of currently connected clients.
0 commit comments