Skip to content

Commit

Permalink
only expect hash for worker messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyandrews committed May 15, 2023
1 parent 9037b8f commit d8c68f4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 34 deletions.
59 changes: 30 additions & 29 deletions src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1621,38 +1621,39 @@ impl ControllerState {
if let Ok(command_string) = self.get_command_string(buf).await {
// Extract the command and value in a generic way.
if let Ok(request_message) = self.get_match(command_string.trim()).await {
let hash = if let Some(ControllerValue::Text(hash)) =
request_message.value.as_ref()
{
// Clone the value.
hash.to_string()
} else {
unreachable!("Hash must exist, enforced by regex");
};
// Workers using Telnet socket to connect to the Manager.
if request_message.command == ControllerCommand::WorkerConnect {
info!("Worker instance connecting ...");
if request_message.command == ControllerCommand::WorkerConnect {
// A Worker is trying to connect, send the connection to the Parent.
if self
.channel_tx
.try_send(ControllerRequest {
response_channel: None,
client_id: self.thread_id,
request: ControllerRequestMessage {
command: ControllerCommand::WorkerConnect,
value: Some(ControllerValue::Socket(
WorkerConnection { hash, socket },
)),
},
})
.is_err()
{
warn!("failed to send Worker socket to parent");
};
break;
// ELSE?
}
// Workers must include hash when connecting.
let hash = if let Some(ControllerValue::Text(hash)) =
request_message.value.as_ref()
{
// Clone the value.
hash.to_string()
} else {
// @TODO: Don't panic, instead cancel the connection ...
panic!("Hash must exist, enforced by regex");
};

// A Worker is trying to connect, send the connection to the Parent.
if self
.channel_tx
.try_send(ControllerRequest {
response_channel: None,
client_id: self.thread_id,
request: ControllerRequestMessage {
command: ControllerCommand::WorkerConnect,
value: Some(ControllerValue::Socket(
WorkerConnection { hash, socket },
)),
},
})
.is_err()
{
warn!("failed to send Worker socket to parent");
};
break;
// ELSE?
}

// Act on the commmand received.
Expand Down
2 changes: 1 addition & 1 deletion src/gaggle/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl GooseConfiguration {
message: "manager_host",
},
])
.unwrap_or_else(|| "".to_string());
.unwrap_or_default();

// Set `manager_port` on Worker.
self.manager_port = self
Expand Down
8 changes: 4 additions & 4 deletions tests/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ async fn run_standalone_test(test_type: TestType) {
if let Some(stream) = test_state.telnet_stream.as_mut() {
let _ = match stream.read(&mut test_state.buf).await {
Ok(data) => data,
Err(_) => {
panic!("ERROR: server disconnected!");
Err(e) => {
panic!("ERROR: server disconnected: {}", e);
}
};
response = str::from_utf8(&test_state.buf).unwrap();
Expand All @@ -233,7 +233,7 @@ async fn run_standalone_test(test_type: TestType) {
unreachable!();
}

//println!("{:?}: {}", test_state.command, response);
println!("{:?}: {}", test_state.command, response);
match test_state.command {
ControllerCommand::Exit => {
match test_state.step {
Expand Down Expand Up @@ -751,7 +751,7 @@ async fn update_state(test_state: Option<TestState>, test_type: &TestType) -> Te
} else {
// Connect to telnet controller.
let telnet_stream = match test_type {
TestType::Telnet => Some(TcpStream::connect("127.0.0.1:5116").await.unwrap()),
TestType::Telnet => Some(TcpStream::connect("127.0.0.1:5115").await.unwrap()),
_ => None,
};

Expand Down

0 comments on commit d8c68f4

Please sign in to comment.