Got rid of the nasty hacks... and replaced it by another one.
authorIvo Timmermans <ivo@lychnis.net>
Sun, 30 Apr 2000 01:15:47 +0000 (01:15 +0000)
committerIvo Timmermans <ivo@lychnis.net>
Sun, 30 Apr 2000 01:15:47 +0000 (01:15 +0000)
src/net.c
src/protocol.c

index 147b399..ea66f13 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -921,9 +921,10 @@ cp
 */
 int handle_incoming_meta_data(conn_list_t *cl)
 {
 */
 int handle_incoming_meta_data(conn_list_t *cl)
 {
-  int x, l = sizeof(x), lenin;
+  int x, l = sizeof(x);
   unsigned char tmp[1600];
   int request;
   unsigned char tmp[1600];
   int request;
+  int lenin = 0;
 cp
   if(getsockopt(cl->meta_socket, SOL_SOCKET, SO_ERROR, &x, &l) < 0)
     {
 cp
   if(getsockopt(cl->meta_socket, SOL_SOCKET, SO_ERROR, &x, &l) < 0)
     {
@@ -936,7 +937,7 @@ cp
       return -1;
     }
 
       return -1;
     }
 
-  if((lenin = read(cl->meta_socket, &tmp, sizeof(tmp))) <= 0)
+  if(read(cl->meta_socket, &tmp, 1) <= 0)
     {
       syslog(LOG_ERR, "Receive failed: %m");
       return -1;
     {
       syslog(LOG_ERR, "Receive failed: %m");
       return -1;
@@ -947,6 +948,35 @@ cp
   if(debug_lvl > 3)
     syslog(LOG_DEBUG, "got request %d", request);
 
   if(debug_lvl > 3)
     syslog(LOG_DEBUG, "got request %d", request);
 
+  /* This is a hack.  After an ACK request, multiple ADD_HOSTs can
+     follow.  So if the request is one of these, only read as much
+     bytes as necessary.  (Luckily the ADD_HOST request is of fixed
+     length) :P -- ivo */
+     
+  if(request != ACK)
+    {
+      if(request == ADD_HOST)
+       {
+         if((lenin = read(cl->meta_socket, &tmp[1], sizeof(add_host_t) - 1)) <= 0)
+           {
+             syslog(LOG_ERR, "Receive failed for ADD_HOST: %m");
+             return -1;
+           }
+       }
+      else
+       {
+         if((lenin = read(cl->meta_socket, &tmp[1], sizeof(tmp) - 1)) <= 0)
+           {
+             if(errno != EAGAIN) /* talk about hacks... */
+               {
+                 syslog(LOG_ERR, "Receive failed: %m");
+                 return -1;
+               }
+           }
+       }
+    }
+  
+  lenin++;
   if(request_handlers[request] == NULL)
     syslog(LOG_ERR, "Unknown request %d.", request);
   else
   if(request_handlers[request] == NULL)
     syslog(LOG_ERR, "Unknown request %d.", request);
   else
@@ -1056,7 +1086,7 @@ cp
 }
 
 /*
 }
 
 /*
-  this is where it al happens...
+  this is where it all happens...
 */
 void main_loop(void)
 {
 */
 void main_loop(void)
 {
index b6ac322..68ac136 100644 (file)
@@ -492,23 +492,6 @@ cp
   
   cl->status.active = 1;
   syslog(LOG_NOTICE, "Connection with %s activated.", cl->hostname);
   
   cl->status.active = 1;
   syslog(LOG_NOTICE, "Connection with %s activated.", cl->hostname);
-
-  /*
-                        === FIXME ===
-    Now I'm going to cheat. The meta protocol is actually
-    a stream of requests, that may come in in the same TCP
-    packet. This is the only place that it will happen,
-    though.
-    I may change it in the future, if it appears that this
-    is not retainable.
-  */
-  if(len > 1) /* An ADD_HOST follows */
-    {
-      if(request_handlers[d[1]] == NULL)
-       syslog(LOG_ERR, "Unknown request %d.", d[1]);
-      if(request_handlers[d[1]](cl, d + 1, len - 1) < 0)
-       return -1;
-    }
 cp
   return 0;
 }
 cp
   return 0;
 }
@@ -613,18 +596,6 @@ cp
   conn_list = ncn;
   ncn->status.active = 1;
   notify_others(ncn, cl, send_add_host);
   conn_list = ncn;
   ncn->status.active = 1;
   notify_others(ncn, cl, send_add_host);
-
-  /*
-    again, i'm cheating here. see the comment in ack_h.
-    Naughty zarq! Now you see what cheating will get you... [GS]
-  */
-  if(len > sizeof(*tmp)) /* Another ADD_HOST follows */
-    {
-      if(request_handlers[d[sizeof(*tmp)]] == NULL)
-       syslog(LOG_ERR, "Unknown request %d.", d[sizeof(*tmp)]);
-      if(request_handlers[d[sizeof(*tmp)]](cl, d + sizeof(*tmp), len - sizeof(*tmp)) < 0)
-       return -1;
-    }
 cp
   return 0;
 }
 cp
   return 0;
 }
@@ -647,11 +618,11 @@ cp
   fw = lookup_conn(tmp->to);
   
   if(!fw)
   fw = lookup_conn(tmp->to);
   
   if(!fw)
-  {
-    syslog(LOG_ERR, "Attempting to forward key request to " IP_ADDR_S ", which does not exist?",
-          IP_ADDR_V(tmp->to));
-    return -1;
-  }
+    {
+      syslog(LOG_ERR, "Attempting to forward key request to " IP_ADDR_S ", which does not exist?",
+            IP_ADDR_V(tmp->to));
+      return -1;
+    }
 
   if(debug_lvl > 3)
     syslog(LOG_DEBUG, "Forwarding request for public key to " IP_ADDR_S,
 
   if(debug_lvl > 3)
     syslog(LOG_DEBUG, "Forwarding request for public key to " IP_ADDR_S,