@@ -190,40 +190,30 @@ fn limit_max_connections(max_connections: usize) -> EventSender {
190190 // based on the current connection count if we want to accept or reject.
191191 // We also want detailed logging of events for the get request, so we can
192192 // detect when the request is finished one way or another.
193- get : RequestMode :: RequestLog ,
193+ connected : ConnectMode :: Request ,
194194 ..EventMask :: DEFAULT
195195 } ;
196196 let ( tx, mut rx) = EventSender :: channel ( 32 , mask) ;
197197 n0_future:: task:: spawn ( async move {
198198 let requests = ConnectionCounter :: new ( max_connections) ;
199199 while let Some ( msg) = rx. recv ( ) . await {
200- if let ProviderMessage :: GetRequestReceived ( mut msg) = msg {
201- let connection_id = msg. connection_id ;
202- let request_id = msg. request_id ;
203- let res = requests. inc ( ) ;
204- match res {
205- Ok ( n) => {
206- println ! ( "Accepting request {n}, id ({connection_id},{request_id})" ) ;
207- msg. tx . send ( Ok ( ( ) ) ) . await . ok ( ) ;
208- }
209- Err ( _) => {
210- println ! (
211- "Connection limit of {max_connections} exceeded, rejecting request"
212- ) ;
213- msg. tx . send ( Err ( AbortReason :: RateLimited ) ) . await . ok ( ) ;
214- continue ;
215- }
200+ match msg {
201+ ProviderMessage :: ClientConnected ( msg) => {
202+ let connection_id = msg. connection_id ;
203+ let node_id = msg. node_id ;
204+ let res = if let Ok ( n) = requests. inc ( ) {
205+ println ! ( "Accepting connection {n}, node_id {node_id}, connection_id {connection_id}" ) ;
206+ Ok ( ( ) )
207+ } else {
208+ Err ( AbortReason :: RateLimited )
209+ } ;
210+ msg. tx . send ( res) . await . ok ( ) ;
216211 }
217- let requests = requests. clone ( ) ;
218- n0_future:: task:: spawn ( async move {
219- // just drain the per request events
220- //
221- // Note that we have requested updates for the request, now we also need to process them
222- // otherwise the request will be aborted!
223- while let Ok ( Some ( _) ) = msg. rx . recv ( ) . await { }
224- println ! ( "Stopping request, id ({connection_id},{request_id})" ) ;
212+ ProviderMessage :: ConnectionClosed ( msg) => {
225213 requests. dec ( ) ;
226- } ) ;
214+ println ! ( "Connection closed, connection_id {}" , msg. connection_id, ) ;
215+ }
216+ _ => { }
227217 }
228218 }
229219 } ) ;
0 commit comments