1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

mod client;
mod provider;

use fidl_fuchsia_net_dhcpv6::ClientProviderRequestStream;
use fuchsia_component::server::{ServiceFs, ServiceFsDir};
use futures::{future, StreamExt as _, TryStreamExt as _};

use anyhow::{Error, Result};
use tracing::info;

enum IncomingService {
    ClientProvider(ClientProviderRequestStream),
}

#[fuchsia::main()]
pub async fn main() -> Result<()> {
    info!("starting");

    let mut fs = ServiceFs::new_local();
    let _: &mut ServiceFsDir<'_, _> =
        fs.dir("svc").add_fidl_service(IncomingService::ClientProvider);
    let _: &mut ServiceFs<_> = fs.take_and_serve_directory_handle()?;

    fs.then(future::ok::<_, Error>)
        .try_for_each_concurrent(None, |request| async {
            match request {
                IncomingService::ClientProvider(client_provider_request_stream) => {
                    Ok(provider::run_client_provider(
                        client_provider_request_stream,
                        client::serve_client,
                    )
                    .await)
                }
            }
        })
        .await
}