szaszm commented on a change in pull request #674: Minificpp 1007 - ECU C2 
integration.
URL: https://github.com/apache/nifi-minifi-cpp/pull/674#discussion_r371763092
 
 

 ##########
 File path: nanofi/ecu/c2_server.c
 ##########
 @@ -0,0 +1,293 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+    *
+    *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+/**
+ * The flow of C2 operations looks as follows
+ * |***********|                |**************| c2 operations  
|****************|
+ * |           | c2 operations  |              |--------------->|              
  |
+ * | c2 client |--------------->| c2 server    |<---------------| c2 agent / 
ecu |
+ * |           |                |              |  c2 heartbeat  |              
  |
+ * *************                ****************                
******************
+ *
+ *
+ * This is meant to be used as a c2 server to listen
+ * for heartbeats from c2 agents.
+ * It keeps track of c2 agents by the agent's uuid
+ * and when c2 command is received from a c2 client,
+ * forwards that command to the corresponding c2 agent
+ * in response to the heartbeat
+ *
+ * This is in no way meant to be used in production.
+ * This is just a skeleton/dummy c2 server used to
+ * test c2 agents functionality.
+ */
+
+#include <nanofi/coap_server.h>
+#include <coap/c2protocol.h>
+#include <coap/c2structs.h>
+#include <coap/c2payload.h>
+#include <coap/c2agent.h>
+#include <c2_api/c2api.h>
+#include "api/ecu.h"
+#include "utlist.h"
+
+#include <signal.h>
+
+
+volatile sig_atomic_t stop_c2 = 0;
+
+void c2_signal_handler(int signum) {
+    if (signum == SIGINT || signum == SIGTERM) {
+        stop_c2 = 1;
+    }
+}
+
+void setup_c2_signal_action() {
+#ifdef _WIN32
+    signal(SIGINT, c2_signal_handler);
+    signal(SIGTERM, c2_signal_handler);
+#else
+    struct sigaction action;
+    memset(&action, 0, sizeof(sigaction));
+    action.sa_handler = c2_signal_handler;
+    sigaction(SIGTERM, &action, NULL);
+    sigaction(SIGINT, &action, NULL);
+#endif
+}
+
+typedef struct c2_server_responses {
+    char uuid[37]; //key
+    c2_server_response_t * response;
+    UT_hash_handle hh;
+} c2_server_responses_t;
+
+typedef struct agents {
+    char uuid[37];
+    struct agents * next;
+} agents_t;
+
+int little_endian = 0;
+c2_server_responses_t * responses = NULL;
+agents_t * ags = NULL;
+
+int find_agent(char * uuid_str) {
+    agents_t * el;
+    LL_FOREACH(ags, el) {
+        if (memcmp(el->uuid, uuid_str, strlen(uuid_str)) == 0) {
 
 Review comment:
   `memcmp` + `strlen` = `strcmp`
   Why are we not using `strcmp` for string comparison?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to