Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
make sonarqube happy
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 29 May 2016 18:58:54 +0000 (20:58 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 29 May 2016 19:00:02 +0000 (21:00 +0200)
- Merge similar switch cases
- Use snprintf instead of sprintf. The change is a bit more intrusive
  for homogeneity with the other P2P tests

examples/msg/app-bittorrent/messages.c
examples/msg/dht-kademlia/common.h
examples/msg/dht-kademlia/dht-kademlia.c
examples/msg/dht-kademlia/dht-kademlia.tesh
examples/msg/dht-kademlia/node.c

index a0cfe07..ce8f93e 100644 (file)
@@ -94,8 +94,6 @@ int task_message_size(e_message_type type)
     size = MESSAGE_UNCHOKE_SIZE;
     break;
   case MESSAGE_INTERESTED:
-    size = MESSAGE_INTERESTED_SIZE;
-    break;
   case MESSAGE_NOTINTERESTED:
     size = MESSAGE_INTERESTED_SIZE;
     break;
index 14770e2..aac88ed 100644 (file)
@@ -22,7 +22,7 @@
 
 #define random_lookup_interval 100
 
-#define MAILBOX_NAME_SIZE (identifier_size / 4) /* hex encoded */
+#define MAILBOX_NAME_SIZE 16 /* (identifier_size / 4)  (hex encoded) */
 
 #define COMM_SIZE 1
 #define COMP_SIZE 0
index 186c620..1b0dc44 100644 (file)
@@ -274,8 +274,8 @@ unsigned int find_node(node_t node, unsigned int id_to_find, unsigned int count_
   */
 unsigned int ping(node_t node, unsigned int id_to_ping)
 {
-  char mailbox[MAILBOX_NAME_SIZE + 1];
-  sprintf(mailbox, "%0*x", MAILBOX_NAME_SIZE, id_to_ping);
+  char mailbox[MAILBOX_NAME_SIZE];
+  snprintf(mailbox,MAILBOX_NAME_SIZE, "%d", id_to_ping);
 
   unsigned int destination_found = 0;
   double timeout = MSG_get_clock() + ping_timeout;
@@ -342,7 +342,7 @@ void random_lookup(node_t node)
   */
 void send_find_node(node_t node, unsigned int id, unsigned int destination)
 {
-  char mailbox[MAILBOX_NAME_SIZE + 1];
+  char mailbox[MAILBOX_NAME_SIZE];
   /* Gets the mailbox to send to */
   get_node_mailbox(id, mailbox);
   /* Build the task */
index 61f4fd8..c2666bb 100644 (file)
@@ -4,19 +4,19 @@ p Testing the Kademlia implementation with MSG
 
 ! output sort 19
 $ $SG_TEST_EXENV ${bindir:=.}/dht-kademlia ${srcdir:=.}/cluster.xml ${srcdir:=.}/../msg/dht-kademlia/dht-kademlia_d.xml "--log=root.fmt:[%10.6r]%e(%02i:%P@%h)%e%m%n"
-> [  0.000000] ( 1:node@node-0.acme.org) Hi, I'm going to create the network with id 00000000
-> [  0.000000] ( 2:node@node-1.acme.org) Hi, I'm going to join the network with id 00000001
-> [  0.000000] ( 3:node@node-2.acme.org) Hi, I'm going to join the network with id 00000003
-> [  0.000000] ( 4:node@node-3.acme.org) Hi, I'm going to join the network with id 00000007
-> [  0.000000] ( 5:node@node-4.acme.org) Hi, I'm going to join the network with id 0000000f
-> [  0.000000] ( 6:node@node-5.acme.org) Hi, I'm going to join the network with id 0000001f
-> [  0.000000] ( 7:node@node-6.acme.org) Hi, I'm going to join the network with id 0000003f
-> [  0.000000] ( 8:node@node-7.acme.org) Hi, I'm going to join the network with id 0000007f
-> [  0.000000] ( 9:node@node-8.acme.org) Hi, I'm going to join the network with id 000000ff
-> [  0.000000] (10:node@node-9.acme.org) Hi, I'm going to join the network with id 000001ff
-> [  0.000000] (11:node@node-10.acme.org) Hi, I'm going to join the network with id 000003ff
-> [  0.000000] (12:node@node-11.acme.org) Hi, I'm going to join the network with id 000007ff
-> [  0.000000] (13:node@node-12.acme.org) Hi, I'm going to join the network with id 00000fff
+> [  0.000000] ( 1:node@node-0.acme.org) Hi, I'm going to create the network with id 0
+> [  0.000000] ( 2:node@node-1.acme.org) Hi, I'm going to join the network with id 1
+> [  0.000000] ( 3:node@node-2.acme.org) Hi, I'm going to join the network with id 3
+> [  0.000000] ( 4:node@node-3.acme.org) Hi, I'm going to join the network with id 7
+> [  0.000000] ( 5:node@node-4.acme.org) Hi, I'm going to join the network with id 15
+> [  0.000000] ( 6:node@node-5.acme.org) Hi, I'm going to join the network with id 31
+> [  0.000000] ( 7:node@node-6.acme.org) Hi, I'm going to join the network with id 63
+> [  0.000000] ( 8:node@node-7.acme.org) Hi, I'm going to join the network with id 127
+> [  0.000000] ( 9:node@node-8.acme.org) Hi, I'm going to join the network with id 255
+> [  0.000000] (10:node@node-9.acme.org) Hi, I'm going to join the network with id 511
+> [  0.000000] (11:node@node-10.acme.org) Hi, I'm going to join the network with id 1023
+> [  0.000000] (12:node@node-11.acme.org) Hi, I'm going to join the network with id 2047
+> [  0.000000] (13:node@node-12.acme.org) Hi, I'm going to join the network with id 4095
 > [780.000000] ( 7:node@node-6.acme.org) 5/5 FIND_NODE have succeeded
 > [780.000000] ( 9:node@node-8.acme.org) 5/5 FIND_NODE have succeeded
 > [780.000000] ( 3:node@node-2.acme.org) 5/5 FIND_NODE have succeeded
index 08aa37c..99ee294 100644 (file)
@@ -20,7 +20,7 @@ node_t node_init(unsigned int node_id)
 
   node->id = node_id;
   node->table = routing_table_init(node_id);
-  sprintf(node->mailbox, "%0*x", MAILBOX_NAME_SIZE, node_id);
+  snprintf(node->mailbox,MAILBOX_NAME_SIZE-1, "%d", node_id);
   node->find_node_failed = 0;
   node->find_node_success = 0;
 
@@ -136,11 +136,10 @@ unsigned int get_node_prefix(unsigned int id, unsigned int nb_bits)
   return 0;
 }
 
-/** @brief Gets the mailbox name of a host given its identifier
-  */
+/** @brief Gets the mailbox name of a host given its identifier */
 void get_node_mailbox(unsigned int id, char *mailbox)
 {
-  sprintf(mailbox, "%0*x", MAILBOX_NAME_SIZE, id);
+  snprintf(mailbox,MAILBOX_NAME_SIZE-1, "%d", id);
 }
 
 /** Constructor, build a new contact information. */