1mod client;
12mod inspect;
13mod packetsocket;
14mod provider;
15mod udpsocket;
16
17use fidl_fuchsia_net_dhcp::{ClientProviderMarker, ClientProviderRequestStream};
18use fidl_fuchsia_posix_socket_packet as fpacket;
19use fuchsia_component::server::{ServiceFs, ServiceFsDir};
20use futures::{future, StreamExt as _, TryStreamExt as _};
21
22use anyhow::Error;
23
24enum IncomingService {
25 ClientProvider(ClientProviderRequestStream),
26}
27
28#[fuchsia::main()]
29pub async fn main() {
30 log::info!("starting");
31
32 let inspector = fuchsia_inspect::component::inspector();
33 let _inspect_server_task =
34 inspect_runtime::publish(inspector, inspect_runtime::PublishOptions::default())
35 .expect("publish Inspect task");
36 let clients_inspect_root = inspector.root().create_child("Clients");
37 let clients_inspect_root = &clients_inspect_root;
38
39 let mut fs = ServiceFs::new_local();
40 let _: &mut ServiceFsDir<'_, _> =
41 fs.dir("svc").add_fidl_service(IncomingService::ClientProvider);
42 let _: &mut ServiceFs<_> =
43 fs.take_and_serve_directory_handle().expect("failed to serve directory handle");
44
45 fs.then(future::ok::<_, Error>)
46 .try_for_each_concurrent(None, |request| async {
47 match request {
48 IncomingService::ClientProvider(client_provider_request_stream) => {
49 provider::serve_client_provider(
50 client_provider_request_stream,
51 fuchsia_component::client::connect_to_protocol::<fpacket::ProviderMarker>()
52 .unwrap_or_else(|e| {
53 panic!("error {e:?} while connecting to {}",
54 <fpacket::ProviderMarker as fidl::endpoints::ProtocolMarker>
55 ::DEBUG_NAME)
56 }),
57 clients_inspect_root,
58 )
59 .await
60 .unwrap_or_else(|e| {
61 log::error!(
62 "error while serving {}: {e:?}",
63 <ClientProviderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME
64 );
65 });
66 Ok(())
67 }
68 }
69 })
70 .await
71 .unwrap_or_else(|e| panic!("error while serving outgoing directory: {e:?}"))
72}