[components][sandbox] Replace Connector protocol with a token
Right now, there are there types associated with [Connector]:
- ConnectorCapability: the token
- Connector: the client end, obtained from [ConnectorCapability], served
by component_manager
- Receiver: the server end, served by the provider component.
To obtain a channel from a Connector, you have to do the following:
- Factory/OpenConnector(ConnectorCapability) -> Connector
- Connector/Open -> zx.CHANNEL
We can reduce this to one step and eliminate the Connector protocol:
- Factory/OpenConnector(ConnectorCapability) -> zx.CHANNEL
Finally, since there is no more Connector protocol, we can rename
ConnectorCapability -> Connector.
Fixed: 339513422
Change-Id: I27fa86c67e876eb621bc97738f43b71b882c0725
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1046552
Reviewed-by: David Gilhooley <dgilhooley@google.com>
API-Review: Gary Bressler <geb@google.com>
Commit-Queue: Gary Bressler <geb@google.com>
diff --git a/sdk/fidl/fuchsia.component.sandbox/fuchsia.component.sandbox.api b/sdk/fidl/fuchsia.component.sandbox/fuchsia.component.sandbox.api
index 2d3291e..091886d 100644
--- a/sdk/fidl/fuchsia.component.sandbox/fuchsia.component.sandbox.api
+++ b/sdk/fidl/fuchsia.component.sandbox/fuchsia.component.sandbox.api
@@ -1,3 +1,3 @@
{
- "fidl/fuchsia.component.sandbox": "0398b3286281979570acaccaf9383337"
+ "fidl/fuchsia.component.sandbox": "73a93eac5284f5cab06d5da3f7bdaeaf"
}
\ No newline at end of file
diff --git a/sdk/fidl/fuchsia.component.sandbox/sandbox.fidl b/sdk/fidl/fuchsia.component.sandbox/sandbox.fidl
index 1a8735b..63a3f87 100644
--- a/sdk/fidl/fuchsia.component.sandbox/sandbox.fidl
+++ b/sdk/fidl/fuchsia.component.sandbox/sandbox.fidl
@@ -37,7 +37,7 @@
};
@available(added=HEAD)
-type ConnectorCapability = resource struct {
+type Connector = resource struct {
token zx.Handle:EVENTPAIR;
};
@@ -47,7 +47,7 @@
2: handle HandleCapability;
3: data DataCapability;
4: dictionary client_end:Dictionary;
- 5: connector ConnectorCapability;
+ 5: connector Connector;
6: directory client_end:fuchsia.io.Directory;
7: router client_end:Router;
};
@@ -173,15 +173,6 @@
});
};
-/// A connector allows a client to send a channel to the framework
-/// so that it can be connected.
-@discoverable
-@available(added=HEAD)
-open protocol Connector {
- /// Sends a channel over this connector.
- flexible Open(ProtocolPayload);
-};
-
/// This represents a component within the framework.
/// There are currently no methods here as this is used as a token.
@available(added=HEAD)
@@ -239,15 +230,10 @@
@discoverable
@available(added=HEAD)
open protocol Factory {
- /// Operate on the provided connector capability.
- ///
- /// Consumes a token referencing a bedrock object and serves the
- /// corresponding FIDL representation on `server_end`. The peer of the
- /// `server_end` is another reference to the bedrock object. Dropping the
- /// control channel decreases one reference on the object.
+ /// Open a connection from the provided [Connector] capability.
flexible OpenConnector(resource struct {
- capability ConnectorCapability;
- server_end server_end:Connector;
+ capability Connector;
+ server_end zx.Handle:CHANNEL;
});
/// Operate on the provided handle capability.
@@ -265,7 +251,7 @@
flexible CreateConnector(resource struct {
receiver client_end:Receiver;
}) -> (resource struct {
- capability ConnectorCapability;
+ capability Connector;
});
/// Creates a `Handle` from the provided `handle`.
diff --git a/src/sys/component_manager/lib/sandbox/src/connector.rs b/src/sys/component_manager/lib/sandbox/src/connector.rs
index df39382..3dd9860 100644
--- a/src/sys/component_manager/lib/sandbox/src/connector.rs
+++ b/src/sys/component_manager/lib/sandbox/src/connector.rs
@@ -78,9 +78,9 @@
}
}
-impl From<Connector> for fsandbox::ConnectorCapability {
+impl From<Connector> for fsandbox::Connector {
fn from(value: Connector) -> Self {
- fsandbox::ConnectorCapability { token: registry::insert_token(value.into()) }
+ fsandbox::Connector { token: registry::insert_token(value.into()) }
}
}
@@ -114,10 +114,10 @@
sender.send_channel(ch1).unwrap();
// Convert the Sender to a FIDL token.
- let connector: fsandbox::ConnectorCapability = sender.into();
+ let connector: fsandbox::Connector = sender.into();
// Clone the Sender by cloning the token.
- let token_clone = fsandbox::ConnectorCapability {
+ let token_clone = fsandbox::Connector {
token: connector.token.duplicate_handle(zx::Rights::SAME_RIGHTS).unwrap(),
};
let connector_clone = match crate::Capability::try_from(fsandbox::Capability::Connector(
diff --git a/src/sys/component_manager/src/framework/factory.rs b/src/sys/component_manager/src/framework/factory.rs
index 842b6cc..0fe23f2 100644
--- a/src/sys/component_manager/src/framework/factory.rs
+++ b/src/sys/component_manager/src/framework/factory.rs
@@ -11,7 +11,10 @@
async_trait::async_trait,
cm_types::Name,
cm_util::TaskGroup,
- fidl::endpoints::{self, ClientEnd, DiscoverableProtocolMarker, ServerEnd},
+ fidl::{
+ endpoints::{self, ClientEnd, DiscoverableProtocolMarker, ServerEnd},
+ epitaph::ChannelEpitaphExt,
+ },
fidl_fuchsia_component_sandbox as fsandbox,
fuchsia_zircon::{self as zx, AsHandleRef},
futures::prelude::*,
@@ -103,9 +106,7 @@
} => match sandbox::Capability::try_from(fsandbox::Capability::Connector(capability)) {
Ok(capability) => match capability {
sandbox::Capability::Connector(connector) => {
- let server_end: ServerEnd<fsandbox::ConnectorMarker> = server_end.into();
- self.tasks
- .spawn(serve_connector(connector, server_end.into_stream().unwrap()));
+ let _ = connector.send(sandbox::Message { channel: server_end });
}
_ => unreachable!(),
},
@@ -140,12 +141,12 @@
fn create_connector(
&self,
receiver_client: ClientEnd<fsandbox::ReceiverMarker>,
- ) -> fsandbox::ConnectorCapability {
+ ) -> fsandbox::Connector {
let (receiver, sender) = Receiver::new();
self.tasks.spawn(async move {
receiver.handle_receiver(receiver_client.into_proxy().unwrap()).await;
});
- fsandbox::ConnectorCapability::from(sender)
+ fsandbox::Connector::from(sender)
}
fn create_dictionary(&self) -> ClientEnd<fsandbox::DictionaryMarker> {
@@ -172,21 +173,6 @@
}
}
-async fn serve_connector(sender: sandbox::Connector, mut stream: fsandbox::ConnectorRequestStream) {
- while let Ok(Some(request)) = stream.try_next().await {
- match request {
- fsandbox::ConnectorRequest::Open { channel, control_handle: _ } => {
- if let Err(_err) = sender.send(sandbox::Message { channel }) {
- return;
- }
- }
- fsandbox::ConnectorRequest::_UnknownMethod { ordinal, .. } => {
- warn!("Received unknown Sender request with ordinal {ordinal}");
- }
- }
- }
-}
-
pub struct FactoryFrameworkCapability {
host: Arc<FactoryCapabilityHost>,
}
@@ -315,14 +301,9 @@
let (receiver_client_end, mut receiver_stream) =
endpoints::create_request_stream::<fsandbox::ReceiverMarker>().unwrap();
let connector = factory_proxy.create_connector(receiver_client_end).await.unwrap();
- let (connector_client, connector_server) =
- fidl::endpoints::create_endpoints::<fsandbox::ConnectorMarker>();
- factory_proxy.open_connector(connector, connector_server.into()).unwrap();
- let connector = connector_client.into_proxy().unwrap();
-
let (ch1, _ch2) = zx::Channel::create();
let expected_koid = ch1.get_koid().unwrap();
- connector.open(ch1).unwrap();
+ factory_proxy.open_connector(connector, ch1).unwrap();
let request = receiver_stream.try_next().await.unwrap().unwrap();
if let fsandbox::ReceiverRequest::Receive { channel, .. } = request {
diff --git a/src/sys/component_manager/tests/controller/src/lib.rs b/src/sys/component_manager/tests/controller/src/lib.rs
index b8af4b5..61ee45a 100644
--- a/src/sys/component_manager/tests/controller/src/lib.rs
+++ b/src/sys/component_manager/tests/controller/src/lib.rs
@@ -535,12 +535,8 @@
};
let factory =
instance.root.connect_to_protocol_at_exposed_dir::<fsandbox::FactoryMarker>().unwrap();
- let (echo_connector_client, echo_connector_server) =
- fidl::endpoints::create_endpoints::<fsandbox::ConnectorMarker>();
- factory.open_connector(echo_connector_capability, echo_connector_server.into()).unwrap();
- let echo_connector = echo_connector_client.into_proxy().unwrap();
let (echo_proxy, server_end) = create_proxy::<fecho::EchoMarker>().unwrap();
- echo_connector.open(server_end.into_channel().into()).unwrap();
+ factory.open_connector(echo_connector_capability, server_end.into_channel()).unwrap();
let response = echo_proxy.echo_string(Some("hello")).await.unwrap().unwrap();
assert_eq!(response, "hello");
}