|
3 | 3 | //---------------------------------------------------------------------------------------------------- Use
|
4 | 4 | use std::task::Poll;
|
5 | 5 |
|
| 6 | +use cuprate_rpc_types::{ |
| 7 | + bin::{BinRequest, BinResponse}, |
| 8 | + json::{JsonRpcRequest, JsonRpcResponse}, |
| 9 | + other::{OtherRequest, OtherResponse}, |
| 10 | +}; |
6 | 11 | use futures::channel::oneshot::channel;
|
7 | 12 | use serde::{Deserialize, Serialize};
|
8 | 13 | use tower::Service;
|
@@ -36,32 +41,57 @@ impl RpcHandler for CupratedRpcHandler {
|
36 | 41 | }
|
37 | 42 | }
|
38 | 43 |
|
39 |
| -impl Service<RpcRequest> for CupratedRpcHandler { |
40 |
| - type Response = RpcResponse; |
| 44 | +// INVARIANT: |
| 45 | +// |
| 46 | +// We don't need to check for `self.is_restricted()` |
| 47 | +// here because `cuprate-rpc-interface` handles that. |
| 48 | +// |
| 49 | +// We can assume the request coming has the required permissions. |
| 50 | + |
| 51 | +impl Service<JsonRpcRequest> for CupratedRpcHandler { |
| 52 | + type Response = JsonRpcResponse; |
41 | 53 | type Error = RpcError;
|
42 |
| - type Future = InfallibleOneshotReceiver<Result<RpcResponse, RpcError>>; |
| 54 | + type Future = InfallibleOneshotReceiver<Result<JsonRpcResponse, RpcError>>; |
43 | 55 |
|
44 | 56 | fn poll_ready(&mut self, _: &mut std::task::Context<'_>) -> Poll<Result<(), Self::Error>> {
|
45 | 57 | Poll::Ready(Ok(()))
|
46 | 58 | }
|
47 | 59 |
|
48 |
| - /// INVARIANT: |
49 |
| - /// |
50 |
| - /// We don't need to check for `self.is_restricted()` |
51 |
| - /// here because `cuprate-rpc-interface` handles that. |
52 |
| - /// |
53 |
| - /// We can assume the request coming has the required permissions. |
54 |
| - fn call(&mut self, req: RpcRequest) -> Self::Future { |
| 60 | + fn call(&mut self, request: JsonRpcRequest) -> Self::Future { |
55 | 61 | let state = Self::clone(self);
|
| 62 | + let response = json::map_request(state, request).expect("TODO"); |
| 63 | + todo!() |
| 64 | + } |
| 65 | +} |
56 | 66 |
|
57 |
| - let resp = match req { |
58 |
| - RpcRequest::JsonRpc(r) => { |
59 |
| - RpcResponse::JsonRpc(json::map_request(state, r).expect("TODO")) |
60 |
| - } // JSON-RPC 2.0 requests. |
61 |
| - RpcRequest::Binary(r) => RpcResponse::Binary(bin::map_request(state, r).expect("TODO")), // Binary requests. |
62 |
| - RpcRequest::Other(r) => RpcResponse::Other(other::map_request(state, r).expect("TODO")), // JSON (but not JSON-RPC) requests. |
63 |
| - }; |
| 67 | +impl Service<BinRequest> for CupratedRpcHandler { |
| 68 | + type Response = BinResponse; |
| 69 | + type Error = RpcError; |
| 70 | + type Future = InfallibleOneshotReceiver<Result<BinResponse, RpcError>>; |
64 | 71 |
|
| 72 | + fn poll_ready(&mut self, _: &mut std::task::Context<'_>) -> Poll<Result<(), Self::Error>> { |
| 73 | + Poll::Ready(Ok(())) |
| 74 | + } |
| 75 | + |
| 76 | + fn call(&mut self, request: BinRequest) -> Self::Future { |
| 77 | + let state = Self::clone(self); |
| 78 | + let response = bin::map_request(state, request).expect("TODO"); |
| 79 | + todo!() |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +impl Service<OtherRequest> for CupratedRpcHandler { |
| 84 | + type Response = OtherResponse; |
| 85 | + type Error = RpcError; |
| 86 | + type Future = InfallibleOneshotReceiver<Result<OtherResponse, RpcError>>; |
| 87 | + |
| 88 | + fn poll_ready(&mut self, _: &mut std::task::Context<'_>) -> Poll<Result<(), Self::Error>> { |
| 89 | + Poll::Ready(Ok(())) |
| 90 | + } |
| 91 | + |
| 92 | + fn call(&mut self, request: OtherRequest) -> Self::Future { |
| 93 | + let state = Self::clone(self); |
| 94 | + let response = other::map_request(state, request).expect("TODO"); |
65 | 95 | todo!()
|
66 | 96 | }
|
67 | 97 | }
|
0 commit comments