-
Notifications
You must be signed in to change notification settings - Fork 5
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
Fix CI issues #5
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 |
---|---|---|
|
@@ -15,15 +15,11 @@ pub mod rpc; | |
pub mod utransport; | ||
|
||
use protobuf::{Enum, Message}; | ||
use std::io::Write; | ||
use std::{ | ||
collections::HashMap, | ||
sync::{atomic::AtomicU64, Arc, Mutex}, | ||
}; | ||
use up_rust::{ | ||
uprotocol::{UAttributes, UCode, UMessage, UPayloadFormat, UPriority, UStatus, UUri}, | ||
uri::serializer::{MicroUriSerializer, UriSerializer}, | ||
}; | ||
use up_rust::uprotocol::{UAttributes, UCode, UMessage, UPayloadFormat, UPriority, UStatus, UUri}; | ||
use zenoh::{ | ||
config::Config, | ||
prelude::r#async::*, | ||
|
@@ -70,39 +66,31 @@ impl UPClientZenoh { | |
}) | ||
} | ||
|
||
// TODO: Workaround function. Should be added in up-rust | ||
fn get_uauth_from_uuri(uri: &UUri) -> Result<String, UStatus> { | ||
let mut buf = vec![]; | ||
if let Some(authority) = uri.authority.as_ref() { | ||
if authority.has_id() { | ||
let id = authority.id().to_vec(); | ||
let len = u8::try_from(id.len()).map_err(|_| { | ||
UStatus::fail_with_code(UCode::INVALID_ARGUMENT, "Wrong authority") | ||
})?; | ||
buf.write(&[len]).map_err(|_| { | ||
UStatus::fail_with_code(UCode::INVALID_ARGUMENT, "Wrong authority") | ||
})?; | ||
buf.write_all(&id).map_err(|_| { | ||
UStatus::fail_with_code(UCode::INVALID_ARGUMENT, "Wrong authority") | ||
})?; | ||
} else if authority.has_ip() { | ||
let ip = authority.ip().to_vec(); | ||
buf.write_all(&ip).map_err(|_| { | ||
UStatus::fail_with_code(UCode::INVALID_ARGUMENT, "Wrong authority") | ||
})?; | ||
} | ||
let buf: Vec<u8> = authority.try_into().map_err(|_| { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
UStatus::fail_with_code( | ||
UCode::INVALID_ARGUMENT, | ||
"Unable to transform UAuthority into micro form", | ||
) | ||
})?; | ||
Ok(buf | ||
.iter() | ||
.fold(String::new(), |s, c| s + &format!("{c:02x}"))) | ||
} else { | ||
Err(UStatus::fail_with_code( | ||
UCode::INVALID_ARGUMENT, | ||
"Empty UAuthority", | ||
)) | ||
} | ||
Ok(buf | ||
.iter() | ||
.fold(String::new(), |s, c| s + &format!("{c:02x}"))) | ||
} | ||
|
||
// The UURI format should be "upr/<UAuthority id or ip>/<the rest of remote UUri>" or "upl/<local UUri>" | ||
fn to_zenoh_key_string(uri: &UUri) -> Result<String, UStatus> { | ||
if uri.authority.is_some() && uri.entity.is_none() && uri.resource.is_none() { | ||
Ok(String::from("upr/") + &UPClientZenoh::get_uauth_from_uuri(uri)? + "/**") | ||
} else { | ||
let micro_uuri = MicroUriSerializer::serialize(uri).map_err(|_| { | ||
let micro_uuri: Vec<u8> = uri.try_into().map_err(|_| { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
UStatus::fail_with_code( | ||
UCode::INVALID_ARGUMENT, | ||
"Unable to serialize into micro format", | ||
|
@@ -223,7 +211,7 @@ mod tests { | |
let uuri = UUri { | ||
authority: Some(UAuthority { | ||
name: Some("UAuthName".to_string()), | ||
number: Some(Number::Id(vec![01, 02, 03, 10, 11, 12])), | ||
number: Some(Number::Id(vec![1, 2, 3, 10, 11, 12])), | ||
..Default::default() | ||
}) | ||
.into(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,8 @@ use async_trait::async_trait; | |
use std::{string::ToString, time::Duration}; | ||
use up_rust::{ | ||
rpc::{CallOptions, RpcClient, RpcClientResult, RpcMapperError, RpcServer}, | ||
transport::{builder::UAttributesBuilder, datamodel::UTransport}, | ||
uprotocol::{Data, UMessage, UPayload, UPriority, UStatus, UUri}, | ||
transport::{builder::UMessageBuilder, datamodel::UTransport}, | ||
uprotocol::{Data, UMessage, UPayload, UStatus, UUri}, | ||
uri::{builder::resourcebuilder::UResourceBuilder, validator::UriValidator}, | ||
uuid::builder::UUIDBuilder, | ||
}; | ||
|
@@ -52,16 +52,30 @@ impl RpcClient for UPClientZenoh { | |
}; | ||
|
||
// Generate UAttributes | ||
// TODO: Check the ttl | ||
let mut uattributes = | ||
UAttributesBuilder::request(UPriority::UPRIORITY_CS4, topic.clone(), 255).build(); | ||
// TODO: How to create the source address for Response | ||
let uuid_builder = UUIDBuilder::new(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this RPC flow still needs some thought though. We should not be creating a new UUIDBuilder here and getting the reqid from it. I believe this is where the UUIDBuilder that's been constructed already for the uE sending the request should be used. As is stated over here in the UUID spec, the I suppose that may mean that on construction, you'd need to construct a UUIDBuilder and then use it within WDYT? |
||
let reqid = UUIDBuilder::new().build(); | ||
// Create response address | ||
let mut source = topic.clone(); | ||
source.resource = Some(UResourceBuilder::for_rpc_response()).into(); | ||
uattributes.source = Some(source).into(); | ||
uattributes.reqid = Some(UUIDBuilder::new().build()).into(); | ||
// TODO: how to map CallOptions timeout into uAttributes | ||
uattributes.token = options.token().map(ToString::to_string); | ||
// TODO: Check the ttl | ||
let umessage = if let Some(token) = options.token() { | ||
UMessageBuilder::request(&topic, &source, &reqid, 255) | ||
.with_token(&token.to_string()) | ||
.build(&uuid_builder) | ||
} else { | ||
UMessageBuilder::request(&topic, &source, &reqid, 255).build(&uuid_builder) | ||
}; | ||
// Extract uAttributes | ||
let Ok(UMessage { | ||
attributes: uattributes, | ||
.. | ||
}) = umessage | ||
else { | ||
return Err(RpcMapperError::UnexpectedError(String::from( | ||
"Unable to create uAttributes", | ||
))); | ||
}; | ||
// Put into attachment | ||
let Ok(attachment) = UPClientZenoh::uattributes_to_attachment(&uattributes) else { | ||
return Err(RpcMapperError::UnexpectedError(String::from( | ||
"Invalid uAttributes", | ||
|
@@ -103,7 +117,7 @@ impl RpcClient for UPClientZenoh { | |
}; | ||
// TODO: Need to check attributes is correct or not | ||
Ok(UMessage { | ||
attributes: Some(uattributes).into(), | ||
attributes: uattributes, | ||
payload: Some(UPayload { | ||
length: Some(0), | ||
format: encoding.into(), | ||
|
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.
Ah okay, and then if there's a tag, we can use that instead. I'm always super impressed by Rust tooling. Using a git tag has been supported since 2014 🙂