-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add send_device_info #181
Add send_device_info #181
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -20,6 +20,8 @@ use crate::config::ServerConfig; | |||||||
use crate::network::Network; | ||||||||
use dotenv::dotenv; | ||||||||
use handlers::Command; | ||||||||
use mac_address::get_mac_address; | ||||||||
use std::env; | ||||||||
|
||||||||
mod config; | ||||||||
mod controllers; | ||||||||
|
@@ -180,6 +182,7 @@ async fn main() -> std::io::Result<()> { | |||||||
|
||||||||
// NOTE: hub initilize | ||||||||
hub_initilize(did.did_document.id.clone()).await; | ||||||||
send_device_info(did.did_document.id.clone()).await; | ||||||||
|
||||||||
let sock_path = runtime_dir.clone().join("nodex.sock"); | ||||||||
|
||||||||
|
@@ -323,6 +326,28 @@ async fn hub_initilize(did: String) { | |||||||
}; | ||||||||
} | ||||||||
|
||||||||
async fn send_device_info(did: String) { | ||||||||
const VERSION: &str = env!("CARGO_PKG_VERSION"); | ||||||||
const OS: &str = env::consts::OS; | ||||||||
let mac_address: String = match get_mac_address() { | ||||||||
Ok(Some(ma)) => ma.to_string(), | ||||||||
Ok(None) => String::from("No MAC address found."), | ||||||||
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. IMO 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 the mac address is additional information since it is used for the log display screen. It is not a required field, so it is better to be able to communicate even if it cannot be obtained. 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 so too. But, I think that the device that has no MAC address can't connect to the Hub over IP. 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 there would be no communication with devices that do not have a MAC address. 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 so too. |
||||||||
Err(_) => String::from("No MAC address found."), | ||||||||
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. nits
Suggested change
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. 👍 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. Fixed, Thanks! |
||||||||
}; | ||||||||
|
||||||||
let hub = Hub::new(); | ||||||||
match hub | ||||||||
.send_device_info(did, mac_address, VERSION.to_string(), OS.to_string()) | ||||||||
.await | ||||||||
{ | ||||||||
Ok(()) => (), | ||||||||
Err(e) => { | ||||||||
log::error!("{:?}", e); | ||||||||
panic!() | ||||||||
} | ||||||||
}; | ||||||||
} | ||||||||
|
||||||||
use env_logger::fmt::Color; | ||||||||
use log::Level; | ||||||||
|
||||||||
|
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.
MUST
Following this code,
get_mac_address()
returns the first MAC address.https://github.com/repnop/mac_address/blob/master/src/lib.rs#L107C5-L107C5
So if the machine has multiple NICs, it may return a different address that doesn't connect to the Hub.
Is this the desired behavior?
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.
Certainly getting the first one with the OS command when there are multiple NICs is a problem, but is there any other better way?
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.
I have no simple solution, but, there may be some solutions like the following page.
https://qiita.com/saiton03/items/e23b308cc2b8e4ebd66d
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.
What happens if I have one domain and multiple IP addresses?
Maybe this time, the purpose is not to know which network interface was used to make the connection, but to get the mac address to identify the terminal, so I think it is OK as long as it is unique.
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.
DNS will return one IP address randomly. This occurs, for example, with DNS round robin.
If the device has multiple NICs, and the server uses DNS round-robin, the MAC address may switched randomly.
OK, I understood.