Browse Source

unique ID for nodes

kaikas 7 years ago
parent
commit
9e18a24d10
6 changed files with 39 additions and 20 deletions
  1. 2 5
      CMakeLists.txt
  2. 12 4
      src/myco-daemon.c
  3. 3 9
      src/myco-daemon.h
  4. 19 0
      src/myco-modules-default.c
  5. 2 1
      src/myco-modules.h
  6. 1 1
      test/mycodaemon.c

+ 2 - 5
CMakeLists.txt

@@ -5,9 +5,7 @@ project (Mycorrhiza C)
 set(CMAKE_EXE_LINKER_FLAGS "-lrt")
 
 find_package(PkgConfig)
-#find_package(kiro REQUIRED)
-pkg_check_modules(KIRO kiro>=1.0 REQUIRED)
-include_directories(${KIRO_INCLUDE_DIRS})
+
 
 add_executable(mycoagent test/mycoagent.c)
 add_executable(mycoagent2 test/mycoagent2.c)
@@ -15,5 +13,4 @@ add_executable(mycoagent3 test/mycoagent3.c)
 add_executable(mycodaemon test/mycodaemon.c)
 add_executable(mycoindexer test/mycoindexer.c)
 
-#target_link_libraries(Mycorrhiza ${KIRO_LIBRARIES})
-target_link_libraries(mycoagent ${KIRO_LIBRARIES})
+#target_link_libraries(mycoagent ${KIRO_LIBRARIES})

+ 12 - 4
src/myco-daemon.c

@@ -21,6 +21,7 @@
 
 myco_agent *first_agent = NULL;
 myco_resource *first_resource = NULL;
+in_addr_t myco_daemon_node_ip;
 
 myco_agent *myco_daemon_find_agent(const char *agent_name) {
     myco_agent *current_agent;
@@ -192,6 +193,7 @@ int myco_daemon_register_resource(message msg) {
         first_resource->transfer_locked = 1;
         first_resource->transactional = msg.resource_transactional;
         first_resource->version = 0;
+        first_resource->node_ip = myco_daemon_node_ip;
     } else {
         // Insert as last element
         current_resource = first_resource;
@@ -210,6 +212,7 @@ int myco_daemon_register_resource(message msg) {
         current_resource->next->read_locked = 0;
         current_resource->next->transactional = msg.resource_transactional;
         current_resource->next->version = 0;
+        current_resource->next->node_ip = myco_daemon_node_ip;
     }
 
     sprintf(msg.message, "SUCCESS: resource %s registered\n", msg.resource_name);
@@ -300,7 +303,11 @@ int myco_daemon_request_resource(message msg) {
         return -1;
     }
 
-    // TODO: Handle case where resource is on another node (another agent)
+    // Check if resource resides on same node
+    printf("\n The adress is: %d\n", current_resource->node_ip);
+
+    // TODO: Handle case where resource is on another node
+    
 
     // If on same node, send information
     msg.sender_pid = current_resource->pid; 
@@ -509,7 +516,7 @@ int myco_daemon_unlock_resource(message msg) {
     }
 }
 
-int myco_daemon_connect(char* ip, int port) {
+int myco_daemon_connect(const char* ip, int port) {
     struct sockaddr_in address;
     int mysocket = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
     address.sin_family = AF_INET;
@@ -520,13 +527,14 @@ int myco_daemon_connect(char* ip, int port) {
     return mysocket;
 }
 
-int myco_daemon_start(pid) {
+int myco_daemon_start(pid_t pid, const char *node_ip, const char *indexer_ip) {
+    in_addr_t myco_daemon_node_ip = inet_network(node_ip);
     char *buffer = malloc (1024);
     int daemon_message_queue_id;
     message msg = {0};
 
     // Connect to indexer
-    int socket = myco_daemon_connect("127.0.0.1", 15000);
+    int socket = myco_daemon_connect(indexer_ip, 15000);
 
     // Create message queue
     daemon_message_queue_id = myco_create_global_message_queue();

+ 3 - 9
src/myco-daemon.h

@@ -42,6 +42,7 @@ typedef struct myco_agent_ myco_agent;
 struct myco_agent_ {
     char name[AGENT_NAME_LENGTH];
     int message_queue_id;
+    in_addr_t node_ip;
     myco_agent *next;
     myco_agent *prev;
 };
@@ -57,19 +58,12 @@ struct myco_resource_ {
     int read_locked; // 0 = unlocked, 1 = locked
     int transfer_locked; // 0 = unlocked, 1 = locked
     int version;
+    in_addr_t node_ip;
     myco_resource *next;
     myco_resource *prev;
 };
 
-/**
- * myco_daemon_start:
- *
- * Starts the daemon process.
- *
- * Returns: 0 on success, -1 on error 
- */
-int myco_daemon_start (pid_t pid);
-
+int myco_daemon_start (pid_t pid, const char *node_ip, const char *indexer_ip);
 myco_agent *myco_daemon_find_agent(const char *agent_name);
 int myco_daemon_register_agent(message msg);
 int myco_daemon_unregister_agent(message msg);

+ 19 - 0
src/myco-modules-default.c

@@ -0,0 +1,19 @@
+/* Copyright (C) 2016 Max Riechelmann <max.riechelmann@student.kit.edu>
+   (Karlsruhe Institute of Technology)
+   This library is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Lesser General Public License as published by the
+   Free Software Foundation; either version 2.1 of the License, or (at your
+   option) any later version.
+   This library is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+   details.
+   You should have received a copy of the GNU Lesser General Public License along
+   with this library; if not, write to the Free Software Foundation, Inc., 51
+   Franklin St, Fifth Floor, Boston, MA 02110, USA
+   */
+
+
+// Serialize with protobuf-c
+// Request(local pointer, remote pointer, size)
+// make ping pong example

+ 2 - 1
src/myco-modules.h

@@ -25,6 +25,7 @@
 #ifndef __MYCO_MODULES_H
 #define __MYCO_MODULES_H
 
-#include "myco-modules-kiro.c"
+#include "myco-modules-default.c"
+//#include "myco-modules-kiro.c"
 
 #endif //__MYCO_MODULES_H

+ 1 - 1
test/mycodaemon.c

@@ -9,7 +9,7 @@
 int main() {
 
 
-    if (myco_daemon_start(getpid()) == -1) {
+    if (myco_daemon_start(getpid(), "127.0.0.1", "127.0.0.1") == -1) {
         return EXIT_FAILURE;
     }