-
Notifications
You must be signed in to change notification settings - Fork 3
Replace query request-response with libp2p-stream #196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -215,7 +215,17 @@ impl P2PTransportBuilder { | |
| pub async fn build_worker( | ||
| self, | ||
| config: WorkerConfig, | ||
| ) -> Result<(impl Stream<Item = WorkerEvent>, WorkerTransportHandle), Error> { | ||
| ) -> Result< | ||
| ( | ||
| impl Stream<Item = WorkerEvent>, | ||
| WorkerTransportHandle, | ||
| libp2p_stream::IncomingStreams, | ||
| libp2p_stream::IncomingStreams, | ||
| ), | ||
|
Comment on lines
+218
to
+224
|
||
| Error, | ||
| > { | ||
| use crate::protocol::{QUERY_PROTOCOL, SQL_QUERY_PROTOCOL}; | ||
|
|
||
| let local_peer_id = self.local_peer_id(); | ||
| // Wait for the worker to be registered on chain | ||
| loop { | ||
|
|
@@ -233,8 +243,22 @@ impl P2PTransportBuilder { | |
| } | ||
| break; | ||
| } | ||
| let swarm = self.build_swarm(|base| WorkerBehaviour::new(base, &config))?; | ||
| Ok(worker::start_transport(swarm, &config)) | ||
|
|
||
| // Create stream behaviour for query protocols. | ||
| // IncomingStreams are returned to the caller for direct handling. | ||
| let query_stream_behaviour = libp2p_stream::Behaviour::new(); | ||
| let mut control = query_stream_behaviour.new_control(); | ||
| let query_streams = control | ||
| .accept(StreamProtocol::new(QUERY_PROTOCOL)) | ||
| .expect("Query protocol should not already be registered"); | ||
| let sql_query_streams = control | ||
| .accept(StreamProtocol::new(SQL_QUERY_PROTOCOL)) | ||
| .expect("SQL query protocol should not already be registered"); | ||
|
Comment on lines
+247
to
+256
|
||
|
|
||
| let swarm = | ||
| self.build_swarm(|base| WorkerBehaviour::new(base, &config, query_stream_behaviour))?; | ||
| let (events, handle) = worker::start_transport(swarm, &config); | ||
| Ok((events, handle, query_streams, sql_query_streams)) | ||
| } | ||
|
|
||
| #[cfg(feature = "sql-client")] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InnerBehaviour’squery_streamsfield is alibp2p_stream::Behaviourthat is used to accept both query and SQL query substreams. The field name implies it only handles queries, which can be confusing now that SQL is registered here too. Consider renaming the field (and corresponding constructor parameter) to reflect that it covers multiple protocols.