Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3487216
D6284.id21551.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D6284.id21551.diff
View Options
diff --git a/shared/tunnelbroker-client/src/lib.rs b/shared/tunnelbroker-client/src/lib.rs
--- a/shared/tunnelbroker-client/src/lib.rs
+++ b/shared/tunnelbroker-client/src/lib.rs
@@ -1,6 +1,9 @@
+use anyhow::Result;
+use futures_util::stream;
use lazy_static::lazy_static;
use std::sync::Arc;
use tokio::runtime::{Builder, Runtime};
+use tokio::sync::mpsc;
use tonic::transport::Channel;
use tunnelbroker::tunnelbroker_service_client::TunnelbrokerServiceClient;
@@ -26,3 +29,46 @@
.block_on(TunnelbrokerServiceClient::connect(addr))
.expect("Failed to create Tokio runtime for the Tunnelbroker client")
}
+
+pub async fn publish_<T>(
+ client: &mut TunnelbrokerServiceClient<Channel>,
+ to_device_id: String,
+ payload: String,
+) -> anyhow::Result<()> {
+ let messages = vec![tunnelbroker::MessageToTunnelbroker {
+ data: Some(tunnelbroker::message_to_tunnelbroker::Data::MessagesToSend(
+ tunnelbroker::MessagesToSend {
+ messages: vec![tunnelbroker::MessageToTunnelbrokerStruct {
+ to_device_id,
+ payload,
+ blob_hashes: vec![],
+ }],
+ },
+ )),
+ }];
+ client
+ .messages_stream(stream::iter(messages))
+ .await
+ .expect("Failed to send messages to the Tunnelbroker stream");
+ Ok(())
+}
+
+pub async fn publish_message(
+ tx: &mpsc::Sender<tunnelbroker::MessageToTunnelbroker>,
+ to_device_id: String,
+ payload: String,
+) -> Result<()> {
+ let messages = tunnelbroker::MessageToTunnelbroker {
+ data: Some(tunnelbroker::message_to_tunnelbroker::Data::MessagesToSend(
+ tunnelbroker::MessagesToSend {
+ messages: vec![tunnelbroker::MessageToTunnelbrokerStruct {
+ to_device_id,
+ payload,
+ blob_hashes: vec![],
+ }],
+ },
+ )),
+ };
+ tx.send(messages).await?;
+ Ok(())
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 19, 7:21 AM (21 h, 39 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2675858
Default Alt Text
D6284.id21551.diff (1 KB)
Attached To
Mode
D6284: [tunnelbroker-client] Adding `publish_message` client function
Attached
Detach File
Event Timeline
Log In to Comment