forked from linkerd/linkerd2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The `control::destination` exposes an important trait, `Bind`, that abstracts the logic of instantiating a new service for an individual endpoint (i.e., in a load balancer). This interface is not specific to our service discovery implementation, and can easily be used to model other types of client factory. In the spirit of consolidating our HTTP-specific logic, and making the core APIs of the proxy more visible, this change renames the `Bind` trait to `NewClient`, simplifies the trait to have fewer type parameters, and documents this new generalized API.
- Loading branch information
Showing
8 changed files
with
88 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//! Infrastructure for proxying request-response message streams | ||
//! | ||
//! This module contains utilities for proxying request-response streams. This | ||
//! module borrows (and re-exports) from `tower`. | ||
//! | ||
//! ## Clients | ||
//! | ||
//! A client is a `Service` through which the proxy may dispatch requests. | ||
//! | ||
//! In the proxy, there are currently two types of clients: | ||
//! | ||
//! - As the proxy routes requests to an outbound `Destination`, a client | ||
//! service is resolves the destination to and load balances requests | ||
//! over its endpoints. | ||
//! | ||
//! - As an outbound load balancer dispatches a request to an endpoint, or as | ||
//! the inbound proxy fowards an inbound request, a client service models an | ||
//! individual `SocketAddr`. | ||
//! | ||
//! ## TODO | ||
//! | ||
//! * Move HTTP-specific service infrastructure into `svc::http`. | ||
|
||
pub use tower_service::Service; | ||
|
||
pub trait NewClient { | ||
|
||
/// Describes a resource to which the client will be attached. | ||
/// | ||
/// Depending on the implementation, the target may describe a logical name | ||
/// to be resolved (i.e. via DNS) and load balanced, or it may describe a | ||
/// specific network address to which one or more connections will be | ||
/// established, or it may describe an entirely arbitrary "virtual" service | ||
/// (i.e. that exists locally in memory). | ||
type Target; | ||
|
||
/// Indicates why the provided `Target` cannot be used to instantiate a client. | ||
type Error; | ||
|
||
/// Serves requests on behalf of a target. | ||
/// | ||
/// `Client`s are expected to acquire resources lazily as | ||
/// `Service::poll_ready` is called. `Service::poll_ready` must not return | ||
/// `Async::Ready` until the service is ready to service requests. | ||
/// `Service::call` must not be called until `Service::poll_ready` returns | ||
/// `Async::Ready`. When `Service::poll_ready` returns an error, the | ||
/// client must be discarded. | ||
type Client: Service; | ||
|
||
/// Creates a client | ||
/// | ||
/// If the provided `Target` is valid, immediately return a `Client` that may | ||
/// become ready lazily, i.e. as the target is resolved and connections are | ||
/// established. | ||
fn new_client(&mut self, t: &Self::Target) -> Result<Self::Client, Self::Error>; | ||
} |