[−][src]Struct vented::server::VentedServer
The vented server that provides parallel handling of connections Usage:
use vented::server::VentedServer; use vented::server::data::{Node, ServerTimeouts}; use vented::stream::SecretKey; use rand::thread_rng; use vented::event::Event; let global_secret_b = SecretKey::generate(&mut thread_rng()); let nodes = vec![ Node { id: "B".to_string(), addresses: vec![], trusted: true, public_key: global_secret_b.public_key() // load it from somewhere }, ]; // in a real world example the secret key needs to be loaded from somewhere because connections // with unknown keys are not accepted. let global_secret = SecretKey::generate(&mut thread_rng()); let mut server = VentedServer::new("A".to_string(), global_secret, nodes.clone(), ServerTimeouts::default()); server.listen("localhost:20000".to_string()); server.on("pong", |_event| { Box::pin(async {println!("Pong!"); None }) }); assert!(async_std::task::block_on(server.emit("B", Event::new("ping".to_string()))).is_err()) // this won't work without a known node B
Implementations
impl VentedServer
[src]
pub fn new(
node_id: String,
secret_key: SecretKey,
nodes: Vec<Node>,
timeouts: ServerTimeouts
) -> Self
[src]
node_id: String,
secret_key: SecretKey,
nodes: Vec<Node>,
timeouts: ServerTimeouts
) -> Self
Creates a new vented server with a given node_id and secret key that are used to authenticate against other servers. The given nodes are used for authentication.
pub fn node_id(&self) -> String
[src]
Returns the nodeId of the server
pub fn nodes(&self) -> Vec<Node>
[src]
Returns the nodes known to the server
pub fn nodes_ref(&self) -> Arc<Mutex<HashMap<String, NodeData>>>
[src]
Returns the actual reference to the inner node list
pub async fn emit<S: ToString, '_>(
&'_ self,
node_id: S,
event: Event
) -> VentedResult<()>
[src]
&'_ self,
node_id: S,
event: Event
) -> VentedResult<()>
Emits an event to the specified Node
pub fn on<F: 'static>(&mut self, event_name: &str, handler: F) where
F: Fn(Event) -> Pin<Box<dyn Future<Output = Option<Event>>>> + Send + Sync,
[src]
F: Fn(Event) -> Pin<Box<dyn Future<Output = Option<Event>>>> + Send + Sync,
Adds a handler for the given event. The event returned by the handler is returned to the sender. Multiple handlers can be registered for an event.
pub fn listen(&self, address: String)
[src]
Starts listening on the specified address (with port!) This will cause a new thread to start up so that the method returns immediately With the returned wait group one can wait for the server to be ready. The method can be called multiple times to start listeners on multiple ports.
Trait Implementations
impl Clone for VentedServer
[src]
pub fn clone(&self) -> VentedServer
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
Auto Trait Implementations
impl !RefUnwindSafe for VentedServer
impl Send for VentedServer
impl Sync for VentedServer
impl Unpin for VentedServer
impl !UnwindSafe for VentedServer
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
[src]
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,