announce server hostname in MANIFEST, display in client
Server reads its hostname via gethostname(2) and includes it as a length-prefixed UTF-8 string at the start of the MANIFEST payload. Client displays 'Server: <hostname> — <MAC>' in a label above the upstream list. Both sides updated for the new MANIFEST format: [hostname_len:1][hostname:N][entries...] Protocol version unchanged (still 1); MANIFEST payload layout change is backward-incompatible but both sides ship together.
This commit is contained in:
+9
-3
@@ -52,6 +52,8 @@ async fn main() -> ExitCode {
|
||||
}
|
||||
};
|
||||
|
||||
let hostname = Arc::new(upstream::get_hostname());
|
||||
|
||||
let link = match Link::open(&args.iface) {
|
||||
Ok(l) => Arc::new(l),
|
||||
Err(e) => {
|
||||
@@ -112,7 +114,7 @@ async fn main() -> ExitCode {
|
||||
continue;
|
||||
}
|
||||
};
|
||||
handle_frame(frame, src, &tx, &store, &next_id, &table).await;
|
||||
handle_frame(frame, src, &tx, &store, &next_id, &table, &hostname).await;
|
||||
}
|
||||
Ok(None) => {
|
||||
// Ignorable frame (outgoing/short/mismatch) or transient; do not
|
||||
@@ -135,10 +137,14 @@ async fn handle_frame(
|
||||
store: &SessionStore,
|
||||
next_id: &Arc<AtomicU32>,
|
||||
table: &Arc<crate::upstream::UpstreamTable>,
|
||||
hostname: &Arc<String>,
|
||||
) {
|
||||
match frame {
|
||||
Frame::Discover => {
|
||||
let manifest = Frame::Manifest(table.entries());
|
||||
let manifest = Frame::Manifest {
|
||||
hostname: (**hostname).clone(),
|
||||
entries: table.entries(),
|
||||
};
|
||||
let _ = tx.send((src, manifest.encode())).await;
|
||||
}
|
||||
Frame::Open { upstream_id } => {
|
||||
@@ -202,6 +208,6 @@ async fn handle_frame(
|
||||
store.lock().expect("store poisoned").remove(&session_id);
|
||||
}
|
||||
// Not expected from a client; ignore.
|
||||
Frame::Manifest(_) | Frame::OpenAck { .. } | Frame::OpenNak { .. } => {}
|
||||
Frame::Manifest { .. } | Frame::OpenAck { .. } | Frame::OpenNak { .. } => {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user