MCPcopy Create free account
hub / github.com/GRVYDEV/Project-Lightspeed / handle_command

Function handle_command

ingest/src/connection.rs:214–341  ·  view source on GitHub ↗
(
    command: FtlCommand,
    sender: &mpsc::Sender<FrameCommand>,
    conn: &mut ConnectionState,
)

Source from the content-addressed store, hash-verified

212}
213
214async fn handle_command(
215 command: FtlCommand,
216 sender: &mpsc::Sender<FrameCommand>,
217 conn: &mut ConnectionState,
218) {
219 match command {
220 FtlCommand::HMAC => {
221 conn.hmac_payload = Some(generate_hmac());
222 let resp = vec!["200 ".to_string(), conn.get_payload(), "\n".to_string()];
223 match sender.send(FrameCommand::Send { data: resp }).await {
224 Ok(_) => {}
225 Err(e) => {
226 error!("Error sending to frame task (From: Handle HMAC) {:?}", e);
227 }
228 }
229 }
230 FtlCommand::Connect { data } => {
231 //make sure we receive a valid channel id and stream key
232 match (data.get("stream_key"), data.get("channel_id")) {
233 (Some(key), Some(_channel_id)) => {
234 //decode the client hash
235 let client_hash = hex::decode(key).expect("error with hash decode");
236 let key = hmac::Key::new(hmac::HMAC_SHA512, &read_stream_key(false, Some("")));
237 //compare the two hashes to ensure they match
238 match hmac::verify(
239 &key,
240 decode(conn.get_payload().into_bytes())
241 .expect("error with payload decode")
242 .as_slice(),
243 client_hash.as_slice(),
244 ) {
245 Ok(_) => {
246 info!("Hashes match!");
247 let resp = vec!["200\n".to_string()];
248 match sender.send(FrameCommand::Send { data: resp }).await {
249 Ok(_) => {}
250 Err(e) => error!(
251 "Error sending to frame task (From: Handle Connection) {:?}",
252 e
253 ),
254 }
255 }
256 _ => {
257 error!("Hashes do not equal");
258 }
259 };
260 }
261
262 (None, _) => {
263 error!("No stream key attached to connect command");
264 }
265 (_, None) => {
266 error!("No channel id attached to connect command");
267 }
268 }
269 }
270 FtlCommand::Attribute { data } => {
271 match (data.get("key"), data.get("value")) {

Callers 1

initMethod · 0.85

Calls 3

generate_hmacFunction · 0.85
read_stream_keyFunction · 0.85
get_payloadMethod · 0.80

Tested by

no test coverage detected