fn on_call<F, X>(&self, call: Call, meta: Metadata, next: F) -> Either<Self::CallFuture, X>
    where
        F: Fn(Call, Metadata) -> X + Send + Sync,
        X: Future<Item = Option<Output>, Error = ()> + Send + 'static,
    {
        let method = match &call {
            Call::MethodCall(m) => Some((m.method.clone(), m.jsonrpc, m.id.clone())),
            Call::Notification(n) => Some((n.method.clone(), n.jsonrpc, Id::Null)),
            Call::Invalid { .. } => None,
        };
        if let Some((m, json_version, id)) = method {
            match self.limiters.check(&m, meta.user.as_ref()) {
                Ok(_) => Either::B(next(call, meta)),
                Err(e) => {
                    let output = Output::Failure(Failure {
                        jsonrpc: json_version,
                        error: Error {
                            code: ErrorCode::ServerError(-10000),
                            message: e.to_string(),
                            data: None,
                        },
                        id,
                    });
                    Either::A(jsonrpc_core::futures::finished(Some(output)))
                }
            }
        } else {
            Either::B(next(call, meta))
        }
    }
/// Only override on_call, because we do rate limit on api level, not request level.
Only override on_call, because we do rate limit on api level, not request level.
Only override on_call because we do rate limit on api level not request level .
fn on_call<F, X>(&self, call: Call, meta: Metadata, next: F) -> Either<Self::CallFuture, X>
    where
        F: Fn(Call, Metadata) -> X + Send + Sync,
        X: Future<Item = Option<Output>, Error = ()> + Send + 'static,
    {
        let method = match &call {
            Call::MethodCall(m) => Some((m.method.clone(), m.jsonrpc, m.id.clone())),
            Call::Notification(n) => Some((n.method.clone(), n.jsonrpc, Id::Null)),
            Call::Invalid { .. } => None,
        };
        if let Some((m, json_version, id)) = method {
            match self.limiters.check(&m, meta.user.as_ref()) {
                Ok(_) => Either::B(next(call, meta)),
                Err(e) => {
                    let output = Output::Failure(Failure {
                        jsonrpc: json_version,
                        error: Error {
                            code: ErrorCode::ServerError(-10000),
                            message: e.to_string(),
                            data: None,
                        },
                        id,
                    });
                    Either::A(jsonrpc_core::futures::finished(Some(output)))
                }
            }
        } else {
            Either::B(next(call, meta))
        }
    }
fn on_call < F , X > ( & self , call : Call , meta : Metadata , next : F ) -> Either < Self :: CallFuture , X > where F : Fn ( Call , Metadata ) -> X + Send + Sync , X : Future < Item = Option < Output > , Error = ( ) > + Send + ' static , { let method = match & call { Call :: MethodCall ( m ) => Some ( ( m . method . clone ( ) , m . jsonrpc , m . id . clone ( ) ) ) , Call :: Notification ( n ) => Some ( ( n . method . clone ( ) , n . jsonrpc , Id :: Null ) ) , Call :: Invalid { .. } => None , } ; if let Some ( ( m , json_version , id ) ) = method { match self . limiters . check ( & m , meta . user . as_ref ( ) ) { Ok ( _ ) => Either :: B ( next ( call , meta ) ) , Err ( e ) => { let output = Output :: Failure ( Failure { jsonrpc : json_version , error : Error { code : ErrorCode :: ServerError ( - 10000 ) , message : e . to_string ( ) , data : None , } , id , } ) ; Either :: A ( jsonrpc_core :: futures :: finished ( Some ( output ) ) ) } } } else { Either :: B ( next ( call , meta ) ) } }
Only override on_call, because we do rate limit on api level, not request level.
Only override on_call because we do rate limit on api level not request level .
&self
call
Call
meta
Metadata
next
F
&self
call
Call
meta
Metadata
next
F