Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove funky non-ascii chars
[simgrid.git] / examples / gras / p2p / chord / chord.c
index 2fd9b6a..61b525f 100644 (file)
@@ -1,7 +1,8 @@
-/* 
+/*
  * vim:ts=2:sw=2:expandtab
  */
 
+#include <stdio.h>
 #include "xbt/sysdep.h"
 #include "gras.h"
 
@@ -144,24 +145,23 @@ static int node_cb_get_suc_handler(gras_msg_cb_ctx_t ctx,void *payload_data){
         RETHROW0("Unable to connect!: %s");
       }
       TRY{
-        gras_msg_send(temp_sock,gras_msgtype_by_name("chord_get_suc"),&asking);
+        gras_msg_send(temp_sock,"chord_get_suc",&asking);
       }CATCH(e){
         RETHROW0("Unable to ask!: %s");
       }
-      gras_msg_wait(10.,gras_msgtype_by_name("chord_rep_suc"),&temp_sock,
-                    &outgoing);
+      gras_msg_wait(10.,"chord_rep_suc",&temp_sock, &outgoing);
     }
   }
   
   TRY{
-    gras_msg_send(expeditor,gras_msgtype_by_name("chord_rep_suc"),&outgoing);
+    gras_msg_send(expeditor,"chord_rep_suc",&outgoing);
     INFO0("Successor information sent!");
   }CATCH(e){
     RETHROW2("%s:Timeout sending successor information to %s: %s",
              globals->host,gras_socket_peer_name(expeditor));
   }
   gras_socket_close(expeditor);
-  return(1);
+  return 0;
 }
 
 static int closest_preceding_node(int id){
@@ -190,13 +190,15 @@ static int node_cb_notify_handler(gras_msg_cb_ctx_t ctx,void *payload_data){
     globals->pre_port=incoming.port;
     INFO0("Set as my new predecessor!");
   }
-  return(1);
+  return 0;
 }
 
 static void fix_fingers(){
+       get_suc_t get_suc_msg;
   xbt_ex_t e;
   gras_socket_t temp_sock=NULL;
   gras_socket_t temp_sock2=NULL;
+  rep_suc_t rep_suc_msg;
   node_data_t *globals=(node_data_t*)gras_userdata_get();
 
   TRY{
@@ -204,18 +206,18 @@ static void fix_fingers(){
   }CATCH(e){
     RETHROW0("Unable to contact known host: %s");
   }
-  get_suc_t get_suc_msg;get_suc_msg.id=globals->id;
+
+  get_suc_msg.id=globals->id;
   TRY{
-    gras_msg_send(temp_sock,gras_msgtype_by_name("chord_get_suc"),&get_suc_msg);
+    gras_msg_send(temp_sock,"chord_get_suc",&get_suc_msg);
   }CATCH(e){
     gras_socket_close(temp_sock);
     RETHROW0("Unable to contact known host to get successor!: %s");
   }
-  rep_suc_t rep_suc_msg;
+
   TRY{
     INFO0("Waiting for reply!");
-    gras_msg_wait(6000,gras_msgtype_by_name("chord_rep_suc"),&temp_sock2,
-                  &rep_suc_msg);
+    gras_msg_wait(6000,"chord_rep_suc",&temp_sock2, &rep_suc_msg);
   }CATCH(e){
     RETHROW1("%s: Error waiting for successor:%s",globals->host);
   }
@@ -232,6 +234,8 @@ static void fix_fingers(){
 static void check_predecessor(){
   node_data_t *globals = (node_data_t*)gras_userdata_get();
   gras_socket_t temp_sock;
+   ping_t ping;
+  pong_t pong;
   xbt_ex_t e;
   if (globals->pre_id == -1){
     return;
@@ -243,18 +247,17 @@ static void check_predecessor(){
     globals->pre_host[0] = 0;
     globals->pre_port = 0;
   }
-  ping_t ping;
-  pong_t pong;
+
   ping.id = 0;
   TRY{
-    gras_msg_send( temp_sock, gras_msgtype_by_name("chord_ping"),&ping);
+    gras_msg_send( temp_sock, "chord_ping",&ping);
   }CATCH(e){
     globals->pre_id = -1;
     globals->pre_host[0] = 0;
     globals->pre_port = 0;
   }
   TRY{
-    gras_msg_wait( 60, gras_msgtype_by_name("chord_pong"), &temp_sock, &pong);
+    gras_msg_wait( 60, "chord_pong", &temp_sock, &pong);
   }CATCH(e){
     globals->pre_id = -1;
     globals->pre_host[0] = 0;
@@ -267,12 +270,16 @@ int node(int argc,char **argv){
   node_data_t *globals=NULL;
   gras_socket_t temp_sock=NULL;
   gras_socket_t temp_sock2=NULL;
+  get_suc_t get_suc_msg;
+  rep_suc_t rep_suc_msg;
 
   xbt_ex_t e;
 
   int create=0;
   int other_port=-1;
   char *other_host;
+  notify_t notify_msg;
+  int l;
 
   /* 1. Init the GRAS infrastructure and declare my globals */
   gras_init(&argc,argv);
@@ -301,7 +308,6 @@ int node(int argc,char **argv){
   globals->sock=gras_socket_server(globals->port);
   gras_os_sleep(1.0);
 
-  register_messages();
   register_messages();
 
   globals->finger=(finger_elem*)calloc(1,sizeof(finger_elem));
@@ -319,19 +325,18 @@ int node(int argc,char **argv){
     }CATCH(e){
       RETHROW0("Unable to contact known host: %s");
     }
-    get_suc_t get_suc_msg;get_suc_msg.id=globals->id;
+
+       get_suc_msg.id=globals->id;
     TRY{
-      gras_msg_send(temp_sock,gras_msgtype_by_name("chord_get_suc"),
-                    &get_suc_msg);
+      gras_msg_send(temp_sock,"chord_get_suc", &get_suc_msg);
     }CATCH(e){
       gras_socket_close(temp_sock);
       RETHROW0("Unable to contact known host to get successor!: %s");
     }
-    rep_suc_t rep_suc_msg;
+
     TRY{
       INFO0("Waiting for reply!");
-      gras_msg_wait(10.,gras_msgtype_by_name("chord_rep_suc"),&temp_sock2,
-                    &rep_suc_msg);
+      gras_msg_wait(10.,"chord_rep_suc",&temp_sock2, &rep_suc_msg);
     }CATCH(e){
       RETHROW1("%s: Error waiting for successor:%s",globals->host);
     }
@@ -347,25 +352,23 @@ int node(int argc,char **argv){
     }CATCH(e){
       RETHROW0("Unable to contact successor: %s");
     }
-    notify_t notify_msg;
-    notify_msg.id=globals->id;
+
+       notify_msg.id=globals->id;
     snprintf(notify_msg.host,1024,globals->host);
     notify_msg.port=globals->port;
     TRY{
-      gras_msg_send(temp_sock,gras_msgtype_by_name("chord_notify"),&notify_msg);
+      gras_msg_send(temp_sock,"chord_notify",&notify_msg);
     }CATCH(e){
       RETHROW0("Unable to notify successor! %s");
     }
   }
   
-  gras_cb_register(gras_msgtype_by_name("chord_get_suc"),
-                   &node_cb_get_suc_handler);
-  gras_cb_register(gras_msgtype_by_name("chord_notify"),
-                   &node_cb_notify_handler);
-  /*gras_cb_register(gras_msgtype_by_name("chord_ping"),&node_cb_ping_handler);*/
+  gras_cb_register("chord_get_suc", &node_cb_get_suc_handler);
+  gras_cb_register("chord_notify",  &node_cb_notify_handler);
+  /*gras_cb_register("chord_ping",&node_cb_ping_handler);*/
  /* gras_timer_repeat(600.,fix_fingers);*/
   /*while(1){*/
-  int l;
+
   for(l=0;l<50;l++){
     TRY{
       gras_msg_handle(6000000.0);