Skip to content

Commit 023754a

Browse files
authored
API Review cleanup (#619)
* fix(service): rename WrappedService params for consistency * docs(oer): add comment on `put_var_octet_string_length` * fix: rename RouteManagerStore to CcpRoutingStore
1 parent ecdc970 commit 023754a

File tree

11 files changed

+93
-92
lines changed

11 files changed

+93
-92
lines changed

crates/ilp-node/src/node.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use hex::FromHex;
2828
use interledger::{
2929
api::{NodeApi, NodeStore},
3030
btp::{btp_service_as_filter, connect_client, BtpOutgoingService, BtpStore},
31-
ccp::{CcpRouteManagerBuilder, CcpRoutingAccount, RouteManagerStore, RoutingRelation},
31+
ccp::{CcpRouteManagerBuilder, CcpRoutingAccount, CcpRoutingStore, RoutingRelation},
3232
errors::*,
3333
http::{HttpClientService, HttpServer as IlpOverHttpServer, HttpStore},
3434
ildcp::IldcpService,
@@ -284,7 +284,7 @@ impl InterledgerNode {
284284
+ BalanceStore
285285
+ SettlementStore<Account = Account>
286286
+ RouterStore<Account = Account>
287-
+ RouteManagerStore<Account = Account>
287+
+ CcpRoutingStore<Account = Account>
288288
+ RateLimitStore<Account = Account>
289289
+ LeftoversStore<AccountId = Uuid, AssetType = BigUint>
290290
+ IdempotentStore

crates/interledger-ccp/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//! we know about.
1111
1212
use async_trait::async_trait;
13-
use interledger_errors::RouteManagerStoreError;
13+
use interledger_errors::CcpRoutingStoreError;
1414
use interledger_service::Account;
1515
use std::collections::HashMap;
1616
use std::{fmt, str::FromStr};
@@ -101,30 +101,30 @@ type LocalAndConfiguredRoutes<T> = (Routes<T>, Routes<T>);
101101

102102
/// Store trait for managing the routes broadcast and set over Connector to Connector protocol
103103
#[async_trait]
104-
pub trait RouteManagerStore: Clone {
104+
pub trait CcpRoutingStore: Clone {
105105
type Account: CcpRoutingAccount;
106106

107107
// TODO should we have a way to only get the details for specific routes?
108108
/// Gets the local and manually configured routes
109109
async fn get_local_and_configured_routes(
110110
&self,
111-
) -> Result<LocalAndConfiguredRoutes<Self::Account>, RouteManagerStoreError>;
111+
) -> Result<LocalAndConfiguredRoutes<Self::Account>, CcpRoutingStoreError>;
112112

113113
/// Gets all accounts which the node should send routes to (Peer and Child accounts)
114114
/// The caller can also pass a vector of account ids to be ignored
115115
async fn get_accounts_to_send_routes_to(
116116
&self,
117117
ignore_accounts: Vec<Uuid>,
118-
) -> Result<Vec<Self::Account>, RouteManagerStoreError>;
118+
) -> Result<Vec<Self::Account>, CcpRoutingStoreError>;
119119

120120
/// Gets all accounts which the node should receive routes to (Peer and Parent accounts)
121121
async fn get_accounts_to_receive_routes_from(
122122
&self,
123-
) -> Result<Vec<Self::Account>, RouteManagerStoreError>;
123+
) -> Result<Vec<Self::Account>, CcpRoutingStoreError>;
124124

125125
/// Sets the new routes to the store (prefix -> account)
126126
async fn set_routes(
127127
&mut self,
128128
routes: impl IntoIterator<Item = (String, Self::Account)> + Send + 'async_trait,
129-
) -> Result<(), RouteManagerStoreError>;
129+
) -> Result<(), CcpRoutingStoreError>;
130130
}

crates/interledger-ccp/src/server.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use crate::{
44
CCP_RESPONSE, CCP_UPDATE_DESTINATION,
55
},
66
routing_table::RoutingTable,
7-
CcpRoutingAccount, RouteManagerStore, RoutingRelation,
7+
CcpRoutingAccount, CcpRoutingStore, RoutingRelation,
88
};
99
use async_trait::async_trait;
1010
use futures::future::join_all;
11-
use interledger_errors::RouteManagerStoreError;
11+
use interledger_errors::CcpRoutingStoreError;
1212
use interledger_packet::{Address, ErrorCode, RejectBuilder};
1313
use interledger_service::{
1414
Account, AddressStore, IlpResult, IncomingRequest, IncomingService, OutgoingRequest,
@@ -54,6 +54,8 @@ fn hash(preimage: &[u8; 32]) -> [u8; 32] {
5454

5555
type NewAndWithdrawnRoutes = (Vec<Route>, Vec<String>);
5656

57+
/// Builder for [CcpRouteManager](./CcpRouteManager.html)
58+
/// See documentation on fields for more details.
5759
pub struct CcpRouteManagerBuilder<I, O, S> {
5860
/// The next request handler that will be used both to pass on requests that are not CCP messages.
5961
next_incoming: I,
@@ -72,7 +74,7 @@ impl<I, O, S, A> CcpRouteManagerBuilder<I, O, S>
7274
where
7375
I: IncomingService<A> + Clone + Send + Sync + 'static,
7476
O: OutgoingService<A> + Clone + Send + Sync + 'static,
75-
S: AddressStore + RouteManagerStore<Account = A> + Clone + Send + Sync + 'static,
77+
S: AddressStore + CcpRoutingStore<Account = A> + Clone + Send + Sync + 'static,
7678
A: CcpRoutingAccount + Send + Sync + 'static,
7779
{
7880
pub fn new(ilp_address: Address, store: S, outgoing: O, next_incoming: I) -> Self {
@@ -179,7 +181,7 @@ impl<I, O, S, A> CcpRouteManager<I, O, S, A>
179181
where
180182
I: IncomingService<A> + Clone + Send + Sync + 'static,
181183
O: OutgoingService<A> + Clone + Send + Sync + 'static,
182-
S: AddressStore + RouteManagerStore<Account = A> + Clone + Send + Sync + 'static,
184+
S: AddressStore + CcpRoutingStore<Account = A> + Clone + Send + Sync + 'static,
183185
A: CcpRoutingAccount + Send + Sync + 'static,
184186
{
185187
/// Returns a future that will trigger this service to update its routes and broadcast
@@ -210,7 +212,7 @@ where
210212
}
211213
}
212214

213-
pub async fn broadcast_routes(&self) -> Result<(), RouteManagerStoreError> {
215+
pub async fn broadcast_routes(&self) -> Result<(), CcpRoutingStoreError> {
214216
self.update_best_routes(None).await?;
215217
self.send_route_updates().await
216218
}
@@ -518,7 +520,7 @@ where
518520
async fn update_best_routes(
519521
&self,
520522
prefixes: Option<Vec<String>>,
521-
) -> Result<(), RouteManagerStoreError> {
523+
) -> Result<(), CcpRoutingStoreError> {
522524
let local_table = self.local_table.clone();
523525
let forwarding_table = self.forwarding_table.clone();
524526
let forwarding_table_updates = self.forwarding_table_updates.clone();
@@ -657,7 +659,7 @@ where
657659
}
658660

659661
/// Send RouteUpdateRequests to all peers that we send routing messages to
660-
async fn send_route_updates(&self) -> Result<(), RouteManagerStoreError> {
662+
async fn send_route_updates(&self) -> Result<(), CcpRoutingStoreError> {
661663
let self_clone = self.clone();
662664
let unavailable_accounts = self.unavailable_accounts.clone();
663665
// Check which accounts we should skip this iteration
@@ -969,7 +971,7 @@ impl<I, O, S, A> IncomingService<A> for CcpRouteManager<I, O, S, A>
969971
where
970972
I: IncomingService<A> + Clone + Send + Sync + 'static,
971973
O: OutgoingService<A> + Clone + Send + Sync + 'static,
972-
S: AddressStore + RouteManagerStore<Account = A> + Clone + Send + Sync + 'static,
974+
S: AddressStore + CcpRoutingStore<Account = A> + Clone + Send + Sync + 'static,
973975
A: CcpRoutingAccount + Send + Sync + 'static,
974976
{
975977
/// Handle the IncomingRequest if it is a CCP protocol message or

crates/interledger-ccp/src/test_helpers.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use super::*;
33
use crate::{packet::CCP_RESPONSE, server::CcpRouteManager};
44
use async_trait::async_trait;
5-
use interledger_errors::{AddressStoreError, RouteManagerStoreError};
5+
use interledger_errors::{AddressStoreError, CcpRoutingStoreError};
66
use interledger_packet::{Address, ErrorCode, RejectBuilder};
77
use interledger_service::{
88
incoming_service_fn, outgoing_service_fn, AddressStore, IncomingService, OutgoingRequest,
@@ -126,20 +126,19 @@ impl AddressStore for TestStore {
126126
}
127127

128128
#[async_trait]
129-
impl RouteManagerStore for TestStore {
129+
impl CcpRoutingStore for TestStore {
130130
type Account = TestAccount;
131131

132132
async fn get_local_and_configured_routes(
133133
&self,
134-
) -> Result<(RoutingTable<TestAccount>, RoutingTable<TestAccount>), RouteManagerStoreError>
135-
{
134+
) -> Result<(RoutingTable<TestAccount>, RoutingTable<TestAccount>), CcpRoutingStoreError> {
136135
Ok((self.local.clone(), self.configured.clone()))
137136
}
138137

139138
async fn get_accounts_to_send_routes_to(
140139
&self,
141140
ignore_accounts: Vec<Uuid>,
142-
) -> Result<Vec<TestAccount>, RouteManagerStoreError> {
141+
) -> Result<Vec<TestAccount>, CcpRoutingStoreError> {
143142
let mut accounts: Vec<TestAccount> = self
144143
.local
145144
.values()
@@ -156,7 +155,7 @@ impl RouteManagerStore for TestStore {
156155

157156
async fn get_accounts_to_receive_routes_from(
158157
&self,
159-
) -> Result<Vec<TestAccount>, RouteManagerStoreError> {
158+
) -> Result<Vec<TestAccount>, CcpRoutingStoreError> {
160159
let mut accounts: Vec<TestAccount> = self
161160
.local
162161
.values()
@@ -172,7 +171,7 @@ impl RouteManagerStore for TestStore {
172171
async fn set_routes(
173172
&mut self,
174173
routes: impl IntoIterator<Item = (String, TestAccount)> + Send + 'async_trait,
175-
) -> Result<(), RouteManagerStoreError> {
174+
) -> Result<(), CcpRoutingStoreError> {
176175
*self.routes.lock() = HashMap::from_iter(routes.into_iter());
177176
Ok(())
178177
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use super::{AccountStoreError, NodeStoreError};
2+
use crate::error::ApiError;
3+
use std::error::Error as StdError;
4+
use thiserror::Error;
5+
6+
/// Errors for the CcpRoutingStore
7+
#[derive(Error, Debug)]
8+
#[non_exhaustive]
9+
pub enum CcpRoutingStoreError {
10+
#[error("{0}")]
11+
Other(#[from] Box<dyn StdError + Send + 'static>),
12+
}
13+
14+
impl From<AccountStoreError> for CcpRoutingStoreError {
15+
fn from(src: AccountStoreError) -> Self {
16+
CcpRoutingStoreError::Other(Box::new(src))
17+
}
18+
}
19+
20+
impl From<NodeStoreError> for CcpRoutingStoreError {
21+
fn from(src: NodeStoreError) -> Self {
22+
CcpRoutingStoreError::Other(Box::new(src))
23+
}
24+
}
25+
26+
impl From<CcpRoutingStoreError> for ApiError {
27+
fn from(src: CcpRoutingStoreError) -> Self {
28+
match src {
29+
_ => ApiError::method_not_allowed(),
30+
}
31+
}
32+
}
33+
34+
#[cfg(feature = "warp_errors")]
35+
impl From<CcpRoutingStoreError> for warp::Rejection {
36+
fn from(src: CcpRoutingStoreError) -> Self {
37+
ApiError::from(src).into()
38+
}
39+
}
40+
41+
#[cfg(feature = "redis_errors")]
42+
use redis::RedisError;
43+
44+
#[cfg(feature = "redis_errors")]
45+
impl From<RedisError> for CcpRoutingStoreError {
46+
fn from(src: RedisError) -> CcpRoutingStoreError {
47+
CcpRoutingStoreError::Other(Box::new(src))
48+
}
49+
}

crates/interledger-errors/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ pub use http_store_error::HttpStoreError;
1414
mod btp_store_error;
1515
pub use btp_store_error::BtpStoreError;
1616

17-
mod routemanager_store_error;
18-
pub use routemanager_store_error::RouteManagerStoreError;
17+
mod ccprouting_store_error;
18+
pub use ccprouting_store_error::CcpRoutingStoreError;
1919

2020
mod balance_store_error;
2121
pub use balance_store_error::BalanceStoreError;

crates/interledger-errors/src/routemanager_store_error.rs

Lines changed: 0 additions & 49 deletions
This file was deleted.

crates/interledger-packet/src/oer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ pub trait MutBufOerExt: BufMut + Sized {
144144
self.put(buf);
145145
}
146146

147-
#[doc(hidden)]
147+
/// Encodes the length of a datatype as variable-length octet encoded unsigned integer and puts it into `Buf`
148148
#[inline]
149149
fn put_var_octet_string_length(&mut self, length: usize) {
150150
if length < 128 {

crates/interledger-service/src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -258,18 +258,18 @@ pub struct WrappedService<F, I, A> {
258258
account_type: PhantomData<A>,
259259
}
260260

261-
impl<F, IO, A, R> WrappedService<F, IO, A>
261+
impl<F, I, A, R> WrappedService<F, I, A>
262262
where
263263
F: Send + Sync + Fn(IncomingRequest<A>, Box<dyn IncomingService<A> + Send>) -> R,
264264
R: Future<Output = IlpResult>,
265-
IO: IncomingService<A> + Clone,
265+
I: IncomingService<A> + Clone,
266266
A: Account,
267267
{
268268
/// Wrap the given service such that the provided function will
269269
/// be called to handle each request. That function can
270270
/// return immediately, modify the request before passing it on,
271271
/// and/or handle the result of calling the inner service.
272-
pub fn wrap_incoming(inner: IO, f: F) -> Self {
272+
pub fn wrap_incoming(inner: I, f: F) -> Self {
273273
WrappedService {
274274
f,
275275
inner: Arc::new(inner),
@@ -279,30 +279,30 @@ where
279279
}
280280

281281
#[async_trait]
282-
impl<F, IO, A, R> IncomingService<A> for WrappedService<F, IO, A>
282+
impl<F, I, A, R> IncomingService<A> for WrappedService<F, I, A>
283283
where
284284
F: Send + Sync + Fn(IncomingRequest<A>, Box<dyn IncomingService<A> + Send>) -> R,
285285
R: Future<Output = IlpResult> + Send + 'static,
286-
IO: IncomingService<A> + Send + Sync + Clone + 'static,
286+
I: IncomingService<A> + Send + Sync + Clone + 'static,
287287
A: Account + Sync,
288288
{
289289
async fn handle_request(&mut self, request: IncomingRequest<A>) -> IlpResult {
290290
(self.f)(request, Box::new((*self.inner).clone())).await
291291
}
292292
}
293293

294-
impl<F, IO, A, R> WrappedService<F, IO, A>
294+
impl<F, O, A, R> WrappedService<F, O, A>
295295
where
296296
F: Send + Sync + Fn(OutgoingRequest<A>, Box<dyn OutgoingService<A> + Send>) -> R,
297297
R: Future<Output = IlpResult>,
298-
IO: OutgoingService<A> + Clone,
298+
O: OutgoingService<A> + Clone,
299299
A: Account,
300300
{
301301
/// Wrap the given service such that the provided function will
302302
/// be called to handle each request. That function can
303303
/// return immediately, modify the request before passing it on,
304304
/// and/or handle the result of calling the inner service.
305-
pub fn wrap_outgoing(inner: IO, f: F) -> Self {
305+
pub fn wrap_outgoing(inner: O, f: F) -> Self {
306306
WrappedService {
307307
f,
308308
inner: Arc::new(inner),
@@ -312,11 +312,11 @@ where
312312
}
313313

314314
#[async_trait]
315-
impl<F, IO, A, R> OutgoingService<A> for WrappedService<F, IO, A>
315+
impl<F, O, A, R> OutgoingService<A> for WrappedService<F, O, A>
316316
where
317317
F: Send + Sync + Fn(OutgoingRequest<A>, Box<dyn OutgoingService<A> + Send>) -> R,
318318
R: Future<Output = IlpResult> + Send + 'static,
319-
IO: OutgoingService<A> + Send + Sync + Clone + 'static,
319+
O: OutgoingService<A> + Send + Sync + Clone + 'static,
320320
A: Account,
321321
{
322322
async fn send_request(&mut self, request: OutgoingRequest<A>) -> IlpResult {

0 commit comments

Comments
 (0)