Skip to content

Commit

Permalink
Box all warp filters
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Dec 23, 2021
1 parent d0696d5 commit 1fdc41e
Show file tree
Hide file tree
Showing 25 changed files with 98 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use bee_tangle::Tangle;
use futures::channel::oneshot;
use serde_json::Value as JsonValue;
use tokio::time::timeout;
use warp::{reject, Filter, Rejection, Reply};
use warp::{filters::BoxedFilter, reject, Filter, Rejection, Reply};

use std::{
any::TypeId,
Expand All @@ -47,7 +47,7 @@ pub(crate) fn filter<B: StorageBackend>(
message_requester: MessageRequesterWorker,
requested_messages: ResourceHandle<RequestedMessages>,
rest_api_config: RestApiConfig,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
) -> BoxedFilter<(impl Reply,)> {
self::path()
.and(warp::post())
.and(has_permission(ROUTE_WHITE_FLAG, public_routes, allowed_ips))
Expand All @@ -59,6 +59,7 @@ pub(crate) fn filter<B: StorageBackend>(
.and(with_requested_messages(requested_messages))
.and(with_rest_api_config(rest_api_config))
.and_then(white_flag)
.boxed()
}

pub(crate) async fn white_flag<B: StorageBackend>(
Expand Down
5 changes: 3 additions & 2 deletions bee-api/bee-rest-api/src/endpoints/routes/api/v1/add_peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use bee_protocol::workers::PeerManager;
use bee_runtime::resource::ResourceHandle;

use serde_json::Value as JsonValue;
use warp::{http::StatusCode, reject, Filter, Rejection, Reply};
use warp::{filters::BoxedFilter, http::StatusCode, reject, Filter, Rejection, Reply};

use std::net::IpAddr;

Expand All @@ -33,14 +33,15 @@ pub(crate) fn filter(
allowed_ips: Box<[IpAddr]>,
peer_manager: ResourceHandle<PeerManager>,
network_command_sender: ResourceHandle<NetworkCommandSender>,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
) -> BoxedFilter<(impl Reply,)> {
self::path()
.and(warp::post())
.and(has_permission(ROUTE_ADD_PEER, public_routes, allowed_ips))
.and(warp::body::json())
.and(with_peer_manager(peer_manager))
.and(with_network_command_sender(network_command_sender))
.and_then(add_peer)
.boxed()
}

pub(crate) async fn add_peer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use bee_ledger::workers::consensus::ConsensusWorkerCommand;
use bee_message::address::Address;

use tokio::sync::mpsc;
use warp::{Filter, Rejection, Reply};
use warp::{filters::BoxedFilter, Filter, Rejection, Reply};

use std::net::IpAddr;

Expand All @@ -25,12 +25,13 @@ pub(crate) fn filter(
public_routes: Box<[String]>,
allowed_ips: Box<[IpAddr]>,
consensus_worker: mpsc::UnboundedSender<ConsensusWorkerCommand>,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
) -> BoxedFilter<(impl Reply,)> {
self::path()
.and(warp::get())
.and(has_permission(ROUTE_BALANCE_BECH32, public_routes, allowed_ips))
.and(with_consensus_worker(consensus_worker))
.and_then(|addr, consensus_worker| async move { balance_bech32(addr, consensus_worker).await })
.boxed()
}

pub(crate) async fn balance_bech32(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use bee_message::address::{Address, Ed25519Address};
use futures::channel::oneshot;
use log::error;
use tokio::sync::mpsc;
use warp::{reject, Filter, Rejection, Reply};
use warp::{filters::BoxedFilter, reject, Filter, Rejection, Reply};

use std::net::IpAddr;

Expand All @@ -34,12 +34,13 @@ pub(crate) fn filter(
public_routes: Box<[String]>,
allowed_ips: Box<[IpAddr]>,
consensus_worker: mpsc::UnboundedSender<ConsensusWorkerCommand>,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
) -> BoxedFilter<(impl Reply,)> {
self::path()
.and(warp::get())
.and(has_permission(ROUTE_BALANCE_ED25519, public_routes, allowed_ips))
.and(with_consensus_worker(consensus_worker))
.and_then(|addr, consensus_worker| async move { balance_ed25519(addr, consensus_worker).await })
.boxed()
}

pub(crate) async fn balance_ed25519(
Expand Down
5 changes: 3 additions & 2 deletions bee-api/bee-rest-api/src/endpoints/routes/api/v1/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use bee_protocol::workers::{config::ProtocolConfig, PeerManager};
use bee_runtime::{node::NodeInfo, resource::ResourceHandle};
use bee_tangle::Tangle;

use warp::{Filter, Rejection, Reply};
use warp::{filters::BoxedFilter, Filter, Reply};

use std::{convert::Infallible, net::IpAddr};

Expand All @@ -39,7 +39,7 @@ pub(crate) fn filter<B: StorageBackend>(
protocol_config: ProtocolConfig,
node_info: ResourceHandle<NodeInfo>,
peer_manager: ResourceHandle<PeerManager>,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
) -> BoxedFilter<(impl Reply,)> {
self::path()
.and(warp::get())
.and(has_permission(ROUTE_INFO, public_routes, allowed_ips))
Expand All @@ -51,6 +51,7 @@ pub(crate) fn filter<B: StorageBackend>(
.and(with_node_info(node_info))
.and(with_peer_manager(peer_manager))
.and_then(info)
.boxed()
}

pub(crate) async fn info<B: StorageBackend>(
Expand Down
5 changes: 3 additions & 2 deletions bee-api/bee-rest-api/src/endpoints/routes/api/v1/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use bee_message::MessageId;
use bee_runtime::resource::ResourceHandle;
use bee_tangle::Tangle;

use warp::{reject, Filter, Rejection, Reply};
use warp::{filters::BoxedFilter, reject, Filter, Rejection, Reply};

use std::net::IpAddr;

Expand All @@ -28,12 +28,13 @@ pub(crate) fn filter<B: StorageBackend>(
public_routes: Box<[String]>,
allowed_ips: Box<[IpAddr]>,
tangle: ResourceHandle<Tangle<B>>,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
) -> BoxedFilter<(impl Reply,)> {
self::path()
.and(warp::get())
.and(has_permission(ROUTE_MESSAGE, public_routes, allowed_ips))
.and(with_tangle(tangle))
.and_then(message)
.boxed()
}

pub(crate) async fn message<B: StorageBackend>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use bee_message::MessageId;
use bee_runtime::resource::ResourceHandle;
use bee_tangle::Tangle;

use warp::{Filter, Rejection, Reply};
use warp::{filters::BoxedFilter, Filter, Rejection, Reply};

use std::net::IpAddr;

Expand All @@ -29,12 +29,13 @@ pub(crate) fn filter<B: StorageBackend>(
public_routes: Box<[String]>,
allowed_ips: Box<[IpAddr]>,
tangle: ResourceHandle<Tangle<B>>,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
) -> BoxedFilter<(impl Reply,)> {
self::path()
.and(warp::get())
.and(has_permission(ROUTE_MESSAGE_CHILDREN, public_routes, allowed_ips))
.and(with_tangle(tangle))
.and_then(message_children)
.boxed()
}

pub async fn message_children<B: StorageBackend>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use bee_message::{payload::Payload, MessageId};
use bee_runtime::resource::ResourceHandle;
use bee_tangle::{ConflictReason, Tangle};

use warp::{reject, Filter, Rejection, Reply};
use warp::{filters::BoxedFilter, reject, Filter, Rejection, Reply};

use std::net::IpAddr;

Expand All @@ -29,12 +29,13 @@ pub(crate) fn filter<B: StorageBackend>(
public_routes: Box<[String]>,
allowed_ips: Box<[IpAddr]>,
tangle: ResourceHandle<Tangle<B>>,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
) -> BoxedFilter<(impl Reply,)> {
self::path()
.and(warp::get())
.and(has_permission(ROUTE_MESSAGE_METADATA, public_routes, allowed_ips))
.and(with_tangle(tangle))
.and_then(message_metadata)
.boxed()
}

pub(crate) async fn message_metadata<B: StorageBackend>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use bee_message::MessageId;
use bee_runtime::resource::ResourceHandle;
use bee_tangle::Tangle;

use warp::{http::Response, reject, Filter, Rejection, Reply};
use warp::{filters::BoxedFilter, http::Response, reject, Filter, Rejection, Reply};

use std::net::IpAddr;

Expand All @@ -27,12 +27,13 @@ pub(crate) fn filter<B: StorageBackend>(
public_routes: Box<[String]>,
allowed_ips: Box<[IpAddr]>,
tangle: ResourceHandle<Tangle<B>>,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
) -> BoxedFilter<(impl Reply,)> {
self::path()
.and(warp::get())
.and(has_permission(ROUTE_MESSAGE_RAW, public_routes, allowed_ips))
.and(with_tangle(tangle))
.and_then(message_raw)
.boxed()
}

pub async fn message_raw<B: StorageBackend>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use bee_message::{
use bee_runtime::resource::ResourceHandle;
use bee_storage::access::Fetch;

use warp::{reject, Filter, Rejection, Reply};
use warp::{filters::BoxedFilter, reject, Filter, Rejection, Reply};

use std::{collections::HashMap, net::IpAddr};

Expand All @@ -28,7 +28,7 @@ pub(crate) fn filter<B: StorageBackend>(
public_routes: Box<[String]>,
allowed_ips: Box<[IpAddr]>,
storage: ResourceHandle<B>,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
) -> BoxedFilter<(impl Reply,)> {
self::path()
.and(warp::get())
.and(has_permission(ROUTE_MESSAGES_FIND, public_routes, allowed_ips))
Expand All @@ -42,6 +42,7 @@ pub(crate) fn filter<B: StorageBackend>(
}))
.and(with_storage(storage))
.and_then(|index, storage| async move { messages_find(index, storage) })
.boxed()
}

pub(crate) fn messages_find<B: StorageBackend>(
Expand Down
5 changes: 3 additions & 2 deletions bee-api/bee-rest-api/src/endpoints/routes/api/v1/milestone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use bee_message::milestone::MilestoneIndex;
use bee_runtime::resource::ResourceHandle;
use bee_tangle::Tangle;

use warp::{reject, Filter, Rejection, Reply};
use warp::{filters::BoxedFilter, reject, Filter, Rejection, Reply};

use std::net::IpAddr;

Expand All @@ -28,12 +28,13 @@ pub(crate) fn filter<B: StorageBackend>(
public_routes: Box<[String]>,
allowed_ips: Box<[IpAddr]>,
tangle: ResourceHandle<Tangle<B>>,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
) -> BoxedFilter<(impl Reply,)> {
self::path()
.and(warp::get())
.and(has_permission(ROUTE_MILESTONE, public_routes, allowed_ips))
.and(with_tangle(tangle))
.and_then(milestone)
.boxed()
}

pub(crate) async fn milestone<B: StorageBackend>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use bee_message::milestone::MilestoneIndex;
use bee_runtime::resource::ResourceHandle;
use bee_storage::access::Fetch;

use warp::{reject, Filter, Rejection, Reply};
use warp::{filters::BoxedFilter, reject, Filter, Rejection, Reply};

use std::net::IpAddr;

Expand All @@ -30,12 +30,13 @@ pub(crate) fn filter<B: StorageBackend>(
public_routes: Box<[String]>,
allowed_ips: Box<[IpAddr]>,
storage: ResourceHandle<B>,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
) -> BoxedFilter<(impl Reply,)> {
self::path()
.and(warp::get())
.and(has_permission(ROUTE_MILESTONE_UTXO_CHANGES, public_routes, allowed_ips))
.and(with_storage(storage))
.and_then(|index, storage| async move { milestone_utxo_changes(index, storage) })
.boxed()
}

pub(crate) fn milestone_utxo_changes<B: StorageBackend>(
Expand Down
5 changes: 3 additions & 2 deletions bee-api/bee-rest-api/src/endpoints/routes/api/v1/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use bee_storage::access::Fetch;
use futures::channel::oneshot;
use log::error;
use tokio::sync::mpsc;
use warp::{reject, Filter, Rejection, Reply};
use warp::{filters::BoxedFilter, reject, Filter, Rejection, Reply};

use std::net::IpAddr;

Expand All @@ -40,7 +40,7 @@ pub(crate) fn filter<B: StorageBackend>(
allowed_ips: Box<[IpAddr]>,
storage: ResourceHandle<B>,
consensus_worker: mpsc::UnboundedSender<ConsensusWorkerCommand>,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
) -> BoxedFilter<(impl Reply,)> {
self::path()
.and(warp::get())
.and(has_permission(ROUTE_OUTPUT, public_routes, allowed_ips))
Expand All @@ -49,6 +49,7 @@ pub(crate) fn filter<B: StorageBackend>(
.and_then(
|output_id, storage, consensus_worker| async move { output(output_id, storage, consensus_worker).await },
)
.boxed()
}

pub(crate) async fn output<B: StorageBackend>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use bee_ledger::workers::consensus::ConsensusWorkerCommand;
use bee_message::address::Address;

use tokio::sync::mpsc;
use warp::{Filter, Rejection, Reply};
use warp::{filters::BoxedFilter, Filter, Rejection, Reply};

use std::net::IpAddr;

Expand All @@ -26,12 +26,13 @@ pub(crate) fn filter(
public_routes: Box<[String]>,
allowed_ips: Box<[IpAddr]>,
consensus_worker: mpsc::UnboundedSender<ConsensusWorkerCommand>,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
) -> BoxedFilter<(impl Reply,)> {
self::path()
.and(warp::get())
.and(has_permission(ROUTE_OUTPUTS_BECH32, public_routes, allowed_ips))
.and(with_consensus_worker(consensus_worker))
.and_then(|addr, consensus_worker| async move { outputs_bech32(addr, consensus_worker).await })
.boxed()
}

pub(crate) async fn outputs_bech32(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use bee_message::{address::Ed25519Address, output::OutputId, prelude::Address};
use futures::channel::oneshot;
use log::error;
use tokio::sync::mpsc;
use warp::{reject, Filter, Rejection, Reply};
use warp::{filters::BoxedFilter, reject, Filter, Rejection, Reply};

use std::net::IpAddr;

Expand All @@ -35,12 +35,13 @@ pub(crate) fn filter(
public_routes: Box<[String]>,
allowed_ips: Box<[IpAddr]>,
consensus_worker: mpsc::UnboundedSender<ConsensusWorkerCommand>,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
) -> BoxedFilter<(impl Reply,)> {
self::path()
.and(warp::get())
.and(has_permission(ROUTE_OUTPUTS_ED25519, public_routes, allowed_ips))
.and(with_consensus_worker(consensus_worker))
.and_then(|addr, consensus_worker| async move { outputs_ed25519(addr, consensus_worker).await })
.boxed()
}

pub(crate) async fn outputs_ed25519(
Expand Down
5 changes: 3 additions & 2 deletions bee-api/bee-rest-api/src/endpoints/routes/api/v1/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use bee_network::PeerId;
use bee_protocol::workers::PeerManager;
use bee_runtime::resource::ResourceHandle;

use warp::{reject, Filter, Rejection, Reply};
use warp::{filters::BoxedFilter, reject, Filter, Rejection, Reply};

use std::net::IpAddr;

Expand All @@ -28,12 +28,13 @@ pub(crate) fn filter(
public_routes: Box<[String]>,
allowed_ips: Box<[IpAddr]>,
peer_manager: ResourceHandle<PeerManager>,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
) -> BoxedFilter<(impl Reply,)> {
self::path()
.and(warp::get())
.and(has_permission(ROUTE_PEER, public_routes, allowed_ips))
.and(with_peer_manager(peer_manager))
.and_then(peer)
.boxed()
}

pub(crate) async fn peer(peer_id: PeerId, peer_manager: ResourceHandle<PeerManager>) -> Result<impl Reply, Rejection> {
Expand Down
Loading

0 comments on commit 1fdc41e

Please sign in to comment.