Skip to main content

Server

Trait Server 

Source
pub trait Server:
    DerefMut<Target = Self::AppCreatorT>
    + Sized
    + 'static {
    type AppT: App<Self>;
    type AppCreatorT: AppCreator<Self>;
    type ExtraConfig;
    type ExtraRunningState: Clone + Debug;
    type ExtraSharedState;
    type ObjectStoreT: Sync;

    const NAME: Name;

    // Required methods
    fn new(config: &Config) -> Result<Self>;
    fn config(&self) -> &Config;
    fn server_config_from(config: &Config) -> &ServerConfig<Self::ExtraConfig>;
    fn create_running_state(
        &self,
        constellation: &Constellation,
    ) -> Result<Self::ExtraRunningState>;
    fn create_extra_shared_state(
        config: &Config,
    ) -> Result<Self::ExtraSharedState>;
    async fn run_until_modifier(
        self: Rc<Self>,
        shutdown_receiver: Receiver<Infallible>,
        app: Rc<Self::AppT>,
    ) -> Result<Option<Box<dyn Modifier<Self>>>>;

    // Provided methods
    fn default_port() -> u16 { ... }
    fn server_config(&self) -> &ServerConfig<Self::ExtraConfig> { ... }
    fn cors() -> Cors { ... }
}
Expand description

Common API to the different PubHubs servers.

A single instance of the ServerImpl implementation of Server is created for each server that’s being run, and it’s mainly responsible for creating immutable App instances to be sent to the individual threads.

For efficiency’s sake, only the App instances are available to each thread, and are mostly immutable. To change the server’s state, generally all apps must be restarted.

An exception to this no-shared-mutable-state is the shared state in Handle, for example the crate::servers::run::DiscoveryLimiter and the object store

Required Associated Constants§

Required Associated Types§

Source

type AppT: App<Self>

Source

type AppCreatorT: AppCreator<Self>

Is moved accross threads to create the Apps.

Source

type ExtraConfig

Source

type ExtraRunningState: Clone + Debug

Additional state when the server is running

Source

type ExtraSharedState

Additional shared state

Source

type ObjectStoreT: Sync

Type of this server’s object store, usually an object_store::ObjectStore, or ().

Required Methods§

Source

fn new(config: &Config) -> Result<Self>

Source

fn config(&self) -> &Config

Source

fn server_config_from(config: &Config) -> &ServerConfig<Self::ExtraConfig>

Source

fn create_running_state( &self, constellation: &Constellation, ) -> Result<Self::ExtraRunningState>

Source

fn create_extra_shared_state(config: &Config) -> Result<Self::ExtraSharedState>

Source

async fn run_until_modifier( self: Rc<Self>, shutdown_receiver: Receiver<Infallible>, app: Rc<Self::AppT>, ) -> Result<Option<Box<dyn Modifier<Self>>>>

This function is called when the server is started to run discovery.

It is only passed a shared (and thus immutable) reference to itself to prevent any modifications going unnoticed by App instances.

It can be ordered to stop via the shutdown_receiver, in which case it should return Ok(None).

If can also return on its own to modify itself via the returned BoxModifier.

If it returns an error, the whole binary crashes.

Before this function’s future finishes, it should relinquish all references to self. Otherwise the modification following it will panic.

It is given its own App instance.

TODO: remove returning BoxModifier since that can be achieved via App instance?

Provided Methods§

Source

fn default_port() -> u16

Returns the default TCP port this server binds to.

Source

fn server_config(&self) -> &ServerConfig<Self::ExtraConfig>

Source

fn cors() -> Cors

Creates cross-origin resource sharing middleware for this server.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§