pub fn new(options: RouterOptions) -> Result<Rc<Self>, Error> {
        let node_id = options.node_id.unwrap_or_else(generate_node_id);
        let server_cert_file = options
            .quic_server_cert_file
            .ok_or_else(|| anyhow::format_err!("No server cert file"))?;
        if !server_cert_file.as_ref().as_ref().exists() {
            anyhow::bail!(
                "Server cert file does not exist: {}",
                server_cert_file.as_ref().as_ref().display()
            );
        }
        let server_key_file = options
            .quic_server_key_file
            .ok_or_else(|| anyhow::format_err!("No server key file"))?;
        if !server_key_file.as_ref().as_ref().exists() {
            anyhow::bail!(
                "Server key file does not exist: {}",
                server_key_file.as_ref().as_ref().display()
            );
        }
        let (routing_update_sender, routing_update_receiver) = routing_update_channel();
        let service_map = ServiceMap::new(node_id);
        let list_peers_observer = Mutex::new(Some(service_map.new_list_peers_observer()));
        let (link_state_publisher, link_state_receiver) = futures::channel::mpsc::channel(1);
        let router = Rc::new(Router {
            node_id,
            next_node_link_id: 1.into(),
            server_cert_file,
            server_key_file,
            routing_update_sender,
            link_state_publisher,
            link_state_observable: Rc::new(Observable::new(Vec::new())),
            service_map,
            links: Mutex::new(HashMap::new()),
            peers: Mutex::new(BTreeMap::new()),
            list_peers_observer,
        });

        spawn_route_planner(
            router.clone(),
            routing_update_receiver,
            router.link_state_observable.new_observer(),
        );
        spawn_link_status_updater(router.link_state_observable.clone(), link_state_receiver);
        // Spawn a future to service diagnostic requests
        if let Some(implementation) = options.diagnostics {
            spawn_diagostic_service_request_handler(router.clone(), implementation);
        }
        Ok(router)
    }
/// New with some set of options
New with some set of options
New with some set of options
pub fn new(options: RouterOptions) -> Result<Rc<Self>, Error> {
        let node_id = options.node_id.unwrap_or_else(generate_node_id);
        let server_cert_file = options
            .quic_server_cert_file
            .ok_or_else(|| anyhow::format_err!("No server cert file"))?;
        if !server_cert_file.as_ref().as_ref().exists() {
            anyhow::bail!(
                "Server cert file does not exist: {}",
                server_cert_file.as_ref().as_ref().display()
            );
        }
        let server_key_file = options
            .quic_server_key_file
            .ok_or_else(|| anyhow::format_err!("No server key file"))?;
        if !server_key_file.as_ref().as_ref().exists() {
            anyhow::bail!(
                "Server key file does not exist: {}",
                server_key_file.as_ref().as_ref().display()
            );
        }
        let (routing_update_sender, routing_update_receiver) = routing_update_channel();
        let service_map = ServiceMap::new(node_id);
        let list_peers_observer = Mutex::new(Some(service_map.new_list_peers_observer()));
        let (link_state_publisher, link_state_receiver) = futures::channel::mpsc::channel(1);
        let router = Rc::new(Router {
            node_id,
            next_node_link_id: 1.into(),
            server_cert_file,
            server_key_file,
            routing_update_sender,
            link_state_publisher,
            link_state_observable: Rc::new(Observable::new(Vec::new())),
            service_map,
            links: Mutex::new(HashMap::new()),
            peers: Mutex::new(BTreeMap::new()),
            list_peers_observer,
        });
        spawn_route_planner(
            router.clone(),
            routing_update_receiver,
            router.link_state_observable.new_observer(),
        );
        spawn_link_status_updater(router.link_state_observable.clone(), link_state_receiver);
        // Spawn a future to service diagnostic requests
        if let Some(implementation) = options.diagnostics {
            spawn_diagostic_service_request_handler(router.clone(), implementation);
        }
        Ok(router)
    }
pub fn new ( options : RouterOptions ) -> Result < Rc < Self > , Error > { let node_id = options . node_id . unwrap_or_else ( generate_node_id ) ; let server_cert_file = options . quic_server_cert_file . ok_or_else ( | | anyhow :: format_err ! ( " " ) ) ? ; if ! server_cert_file . as_ref ( ) . as_ref ( ) . exists ( ) { anyhow :: bail ! ( " " server_cert_file as_ref ( ) as_ref ( ) display ( ) ) ; } let server_key_file = options . quic_server_key_file . ok_or_else ( | | anyhow :: format_err ! ( " " ) ) ? ; if ! server_key_file . as_ref ( ) . as_ref ( ) . exists ( ) { anyhow :: bail ! ( " " server_key_file as_ref ( ) as_ref ( ) display ( ) ) ; } let ( routing_update_sender , routing_update_receiver ) = routing_update_channel ( ) ; let service_map = ServiceMap :: new ( node_id ) ; let list_peers_observer = Mutex :: new ( Some ( service_map . new_list_peers_observer ( ) ) ) ; let ( link_state_publisher , link_state_receiver ) = futures :: channel :: mpsc :: channel ( 1 ) ; let router = Rc :: new ( Router { node_id , next_node_link_id : 1 . into ( ) , server_cert_file , server_key_file , routing_update_sender , link_state_publisher , link_state_observable : Rc :: new ( Observable :: new ( Vec :: new ( ) ) ) , service_map , links : Mutex :: new ( HashMap :: new ( ) ) , peers : Mutex :: new ( BTreeMap :: new ( ) ) , list_peers_observer , } ) ; spawn_route_planner ( router . clone ( ) , routing_update_receiver , router . link_state_observable . new_observer ( ) , ) ; spawn_link_status_updater ( router . link_state_observable . clone ( ) , link_state_receiver ) ; // Spawn a future to service diagnostic requests if let Some ( implementation ) = options . diagnostics { spawn_diagostic_service_request_handler ( router . clone ( ) , implementation ) ; } Ok ( router ) }
New with some set of options
New with some set of options
options
RouterOptions
options
RouterOptions