Conversation
Signed-off-by: Akshaya Jagannadharao <[email protected]>
Signed-off-by: Akshaya Jagannadharao <[email protected]>
Signed-off-by: Akshaya Jagannadharao <[email protected]>
Signed-off-by: Akshaya Jagannadharao <[email protected]>
Signed-off-by: Akshaya Jagannadharao <[email protected]>
Signed-off-by: Akshaya Jagannadharao <[email protected]>
Signed-off-by: Akshaya Jagannadharao <[email protected]>
Signed-off-by: Akshaya Jagannadharao <[email protected]>
Signed-off-by: Akshaya Jagannadharao <[email protected]>
Signed-off-by: Akshaya Jagannadharao <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## openadr3_1 #367 +/- ##
==============================================
+ Coverage 80.07% 80.82% +0.75%
==============================================
Files 41 44 +3
Lines 4898 5013 +115
==============================================
+ Hits 3922 4052 +130
+ Misses 976 961 -15 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
pohlm01
left a comment
There was a problem hiding this comment.
Thanks a lot for your PR! As mentioned, it runs on my machine, which is great. I still found a couple of points that could use some improvement. Let me know if you could use any help.
| async fn main() { | ||
| info!("Searching for VTN servers..."); | ||
|
|
||
| let vtns = discover_local_vtns("_openadr-http._tcp.local.").await; |
There was a problem hiding this comment.
According to the spec, this should be _openadr3._tcp.local., shouldn't it? (Also see various other places in the code)
| let timeout = tokio::time::sleep(std::time::Duration::from_secs(20)); | ||
| tokio::pin!(timeout); |
There was a problem hiding this comment.
Maybe move the sleep in the loop. I think that would look cleaner to me, and you can skip the pin!. Additionally, it might be nice to add two more parameters to the function:
- The maximum time you want to search, i.e., the
timeout - An optional limit of VTNs to discover. I imagine most users want to discover only a single VTN and immediately return as soon as it's found instead of waiting for the full timeout.
| let mdns = ServiceDaemon::new().expect("Failed to create daemon"); | ||
|
|
||
| // Include metadata about the VTN service, such as version and API path | ||
| let properties = [("version", "3.1"), ("path", "/programs")]; |
There was a problem hiding this comment.
I think you should double-check that with the spec:
- The version has three parts, i.e,
3.1.0 - The
pathisn't a property that's specified base_pathis missinglocal_urlis missing- We might want to skip
proram_names,requires_auth, andopenapi_urlfor now. Especially theprogram_namesseem like a challenge to me, as it changes over the curse of the VTN lifetime.
|
|
||
| // Search for the ServiceResolved event, timeout after 5 seconds if not found | ||
| let mut found = false; | ||
| let timeout = tokio::time::sleep(Duration::from_secs(5)); |
There was a problem hiding this comment.
Moving the sleep right into the select! branch seems cleaner to me
| } | ||
| } | ||
|
|
||
| assert!(found, "The mDNS service was not discovered within the 5s timeout."); |
| std::env::set_var("PORT", "3999"); // Random port | ||
| std::env::set_var("MDNS_SERVICE_TYPE", "_openadr-test._tcp.local."); | ||
| std::env::set_var("MDNS_SERVER_NAME", "test-vtn-integration"); | ||
| std::env::set_var("MDNS_IP_ADDRESS", "127.0.0.1"); |
There was a problem hiding this comment.
Unfortunately, set_var is marked unsafe from the 2024 edition onwards (and was already unsafe before, but the marking was missing). We have an outstanding issue to migrate to the 2024 edition that's currently blocked by other tests that also use the set_var function.
Maybe you can find a way to either make sure the usage of unsafe is fine here and mark it as such (with an explanation), or avoid the set_var function. I haven't looked into this myself now, so I don't know what the best solution from the top of my head, but let me know if you could use any assistance.
| if let Some(host) = info.get_addresses().iter().next() { | ||
| let port = info.get_port(); | ||
| if let Ok(url) = url::Url::parse(&format!("http://{}:{}", host, port)) { | ||
| found_urls.push(url); | ||
| } |
There was a problem hiding this comment.
I don't think we gain a lot from formatting the url here. Instead, I think we should return a struct with all the information we can get from the announcement (version, base_path, local_url, etc.).
|
Also, please make sure to run |
Summary
Implements mDNS service discovery for VTN servers (resolves #276) with corresponding client-side discovery capabilities.
Implement mDNS in VTN for and an example implementation of VTN discovery for the client.
Details
VTN Changes
_openadr-http._tcp.local..env)Client Changes
openleadr-client/mdns.rsexamples/discover_vtns.rsTesting
Limitations