[Pkg-privacy-commits] [onioncat] 31/340: PEERLIST array from code removed and replaced by chained list

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 13:04:22 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch debian
in repository onioncat.

commit 087ff32dfcb8aaf212364c81edfcd8b1bb3f4350
Author: eagle <eagle at 58e1ccc2-750e-0410-8d0d-f93ca75ab447>
Date:   Mon Mar 17 13:17:16 2008 +0000

    PEERLIST array from code removed and replaced by chained list
    
    git-svn-id: http://www.cypherpunk.at/svn/onioncat/trunk@172 58e1ccc2-750e-0410-8d0d-f93ca75ab447
---
 ocat.c      |   3 --
 ocat.h      |   2 -
 ocatroute.c | 131 ------------------------------------------------------------
 3 files changed, 136 deletions(-)

diff --git a/ocat.c b/ocat.c
index b2c9ce7..d8de2d1 100644
--- a/ocat.c
+++ b/ocat.c
@@ -143,9 +143,6 @@ int main(int argc, char *argv[])
 
    log_msg(L_NOTICE, "onioncat (c) Bernhard R. Fischer -- compiled %s %s", __DATE__, __TIME__);
 
-   // init peer structure
-   init_peers();
-
 #ifndef WITHOUT_TUN
    // create TUN device
    tunfd_[0] = tunfd_[1] = tun_alloc(tunname, addr);
diff --git a/ocat.h b/ocat.h
index df50994..45af59a 100644
--- a/ocat.h
+++ b/ocat.h
@@ -1,8 +1,6 @@
 #ifndef OCAT_H
 #define OCAT_H
 
-#define PEERLIST
-
 #include <time.h>
 #ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
diff --git a/ocatroute.c b/ocatroute.c
index f3eea9f..19b8bad 100644
--- a/ocatroute.c
+++ b/ocatroute.c
@@ -30,11 +30,7 @@ static int sockfd_;
 // used for internal communication
 static int lpfd_[2];
 // array of active peers
-#ifndef PEERLIST
-static OcatPeer_t peer_[MAXPEERS];
-#else
 static OcatPeer_t *peer_ = NULL;
-#endif
 // mutex for locking array of peers
 pthread_mutex_t peer_mutex_ = PTHREAD_MUTEX_INITIALIZER;
 // packet queue pointer
@@ -61,50 +57,19 @@ uint16_t ocat_dest_port_ = OCAT_DEST_PORT;
 int vrec_ = 0;
 
 
-void init_peers(void)
-{
-#ifndef PEERLIST
-   memset(peer_, 0, sizeof(OcatPeer_t) * MAXPEERS);
-#endif
-}
-
-
 OcatPeer_t *search_peer(const struct in6_addr *addr)
 {
-#ifndef PEERLIST
-   int i;
-
-   for (i = 0; i < MAXPEERS; i++)
-      if (!memcmp(addr, &peer_[i].addr, sizeof(struct in6_addr)))
-         break;
-         //return &peer_[i];
-
-   if (i >= MAXPEERS)
-      return NULL;
-
-   return &peer_[i];
-#else
    OcatPeer_t *peer;
 
    for (peer = peer_; peer; peer = peer->next)
       if (!memcmp(addr, &peer->addr, sizeof(struct in6_addr)))
          return peer;
    return NULL;
-#endif
 }
 
 
 OcatPeer_t *get_empty_peer(void)
 {
-#ifndef PEERLIST
-   int i;
-
-   for (i = 0; i < MAXPEERS; i++)
-      if (!peer_[i].state)
-         return &peer_[i];
-
-   return NULL;
-#else
    OcatPeer_t *peer;
 
    if (!(peer = calloc(1, sizeof(OcatPeer_t))))
@@ -116,15 +81,11 @@ OcatPeer_t *get_empty_peer(void)
    }
 
    return peer;  
-#endif
 }
 
 
 void delete_peer(OcatPeer_t *peer)
 {
-#ifndef PEERLIST
-   memset(peer, 0, sizeof(OcatPeer_t));
-#else
    OcatPeer_t **p;
    for (p = &peer_; *p; p = &(*p)->next)
       if (*p == peer)
@@ -133,7 +94,6 @@ void delete_peer(OcatPeer_t *peer)
          free(peer);
          return;
       }
-#endif
 }
 
 
@@ -333,11 +293,7 @@ void *socket_receiver(void *p)
    fd_set rset;
    struct ip6_hdr *ihd;
    ihd = (struct ip6_hdr*) &buf[4];
-#ifdef PEERLIST
    OcatPeer_t *peer;
-#else
-   int i;
-#endif
 
    if (pipe(lpfd_) < 0)
       log_msg(L_FATAL, "[init_socket_receiver] could not create pipe for socket_receiver: \"%s\"", strerror(errno)), exit(1);
@@ -350,19 +306,6 @@ void *socket_receiver(void *p)
 
       // create set for all available peers to read
       pthread_mutex_lock(&peer_mutex_);
-#ifndef PEERLIST
-      for (i = 0; i < MAXPEERS; i++)
-      {
-         // only select active peers
-         if (peer_[i].state != PEER_ACTIVE)
-            continue;
-         if ((fd = peer_[i].tcpfd) >= FD_SETSIZE)
-            log_msg(L_FATAL, "%d >= FD_SETIZE(%d)", fd, FD_SETSIZE), exit(1);
-         FD_SET(fd, &rset);
-         if (fd > maxfd)
-            maxfd = fd;
-      }
-#else
       for (peer = peer_; peer; peer = peer->next)
       {
          // only select active peers
@@ -374,7 +317,6 @@ void *socket_receiver(void *p)
          if (fd > maxfd)
             maxfd = fd;
       }
-#endif
       pthread_mutex_unlock(&peer_mutex_);
 
       log_msg(L_DEBUG, "[socket_receiver] is selecting...");
@@ -392,20 +334,11 @@ void *socket_receiver(void *p)
       }
 
       //FIXME: should only run until num select returned
-#ifndef PEERLIST
-      for (i = 0; i < MAXPEERS; i++)
-#else
       for (peer = peer_; peer; peer = peer->next)
-#endif
       {
          pthread_mutex_lock(&peer_mutex_);
-#ifndef PEERLIST
-         state = peer_[i].state;
-         fd = peer_[i].tcpfd;
-#else
          state = peer->state;
          fd = peer->tcpfd;
-#endif
          pthread_mutex_unlock(&peer_mutex_);
 
          if (state != PEER_ACTIVE)
@@ -429,11 +362,7 @@ void *socket_receiver(void *p)
                log_msg(L_NOTICE, "[socket_receiver] fd %d reached EOF, closing.", fd);
                close(fd);
                pthread_mutex_lock(&peer_mutex_);
-#ifndef PEERLIST
-               delete_peer(&peer_[i]);
-#else
                delete_peer(peer);
-#endif
                pthread_mutex_unlock(&peer_mutex_);
                continue;
             }
@@ -446,18 +375,6 @@ void *socket_receiver(void *p)
             }
 
             pthread_mutex_lock(&peer_mutex_);
-#ifndef PEERLIST
-            // update timestamp
-            peer_[i].time = time(NULL);
-            peer_[i].in += len;
-            // set IP address if it is not set yet and frame is valid
-            if (plen && !memcmp(&peer_[i].addr, &in6addr_any, sizeof(struct in6_addr)))
-            {
-               memcpy(&peer_[i].addr, &ihd->ip6_src, sizeof(struct in6_addr));
-               log_msg(L_NOTICE, "[socket_receiver] incoming connection on %d from %s is now identified", fd,
-                     inet_ntop(AF_INET6, &peer_[i].addr, addr, INET6_ADDRSTRLEN));
-            }
-#else
             // update timestamp
             peer->time = time(NULL);
             peer->in += len;
@@ -468,7 +385,6 @@ void *socket_receiver(void *p)
                log_msg(L_NOTICE, "[socket_receiver] incoming connection on %d from %s is now identified", fd,
                      inet_ntop(AF_INET6, &peer->addr, addr, INET6_ADDRSTRLEN));
             }
-#endif
             pthread_mutex_unlock(&peer_mutex_);
             
             log_msg(L_DEBUG, "[socket_receiver] trying fhdr rewriting");
@@ -780,28 +696,13 @@ void packet_forwarder(void)
 
 void *socket_cleaner(void *p)
 {
-#ifndef PEERLIST
-   int i;
-#else
    OcatPeer_t *peer;
-#endif
 
    for (;;)
    {
       sleep(CLEANER_WAKEUP);
       log_msg(L_DEBUG, "wakeup");
       pthread_mutex_lock(&peer_mutex_);
-#ifndef PEERLIST
-      for (i = 0; i < MAXPEERS; i++)
-      {
-         if (peer_[i].state && peer_[i].time + MAX_IDLE_TIME < time(NULL))
-         {
-            log_msg(L_NOTICE, "peer %d timed out, closing.", peer_[i].tcpfd);
-            close(peer_[i].tcpfd);
-            delete_peer(&peer_[i]);
-         }
-      }
-#else
       for (peer = peer_; peer; peer = peer->next)
       {
          if (peer->state && peer->time + MAX_IDLE_TIME < time(NULL))
@@ -811,7 +712,6 @@ void *socket_cleaner(void *p)
             delete_peer(peer);
          }
       }
-#endif
       pthread_mutex_unlock(&peer_mutex_);
    }
 }
@@ -825,11 +725,7 @@ void *ocat_controller(void *p)
    int rlen, cfd;
    struct tm *tm;
    OcatThread_t *th;
-#ifndef PEERLIST
-   int i;
-#else
    OcatPeer_t *peer;
-#endif
 
    memset(&in, 0, sizeof(in));
    in.sin_family = AF_INET;
@@ -873,21 +769,6 @@ void *ocat_controller(void *p)
          else if (!strncmp(buf, "status", 6))
          {
             pthread_mutex_lock(&peer_mutex_);
-#ifndef PEERLIST
-            for (i = 0; i < MAXPEERS; i++)
-               if (peer_[i].state == PEER_ACTIVE)
-               {
-                  tm = localtime(&peer_[i].otime);
-                  strftime(timestr, 32, "%c", tm);
-                  sprintf(buf, "[%s]\n fd = %d\n addr = %s\n dir = \"%s\"\n idle = %lds\n bytes_in = %ld\n bytes_out = %ld\n setup_delay = %lds\n opening_time = \"%s\"\n",
-                        ipv6tonion(&peer_[i].addr, onionstr), peer_[i].tcpfd,
-                        inet_ntop(AF_INET6, &peer_[i].addr, addrstr, INET6_ADDRSTRLEN),
-                        peer_[i].dir == PEER_INCOMING ? "in" : "out",
-                        time(NULL) - peer_[i].time, peer_[i].in, peer_[i].out, peer_[i].sdelay, timestr);
-                  if (write(fd, buf, strlen(buf)) != strlen(buf))
-                     log_msg(L_ERROR, "couldn't write %d bytes to control socket %d", strlen(buf), fd);
-               }
-#else
             for (peer = peer_; peer; peer = peer->next)
                if (peer->state == PEER_ACTIVE)
                {
@@ -901,23 +782,12 @@ void *ocat_controller(void *p)
                   if (write(fd, buf, strlen(buf)) != strlen(buf))
                      log_msg(L_ERROR, "couldn't write %d bytes to control socket %d", strlen(buf), fd);
                }
-#endif
             pthread_mutex_unlock(&peer_mutex_);
          }
          else if (!strncmp(buf, "close ", 6))
          {
             cfd = atoi(&buf[6]);
             pthread_mutex_lock(&peer_mutex_);
-#ifndef PEERLIST
-            for (i = 0; i < MAXPEERS; i++)
-               if (peer_[i].tcpfd == cfd)
-               {
-                  log_msg(L_NOTICE, "close request for %d", cfd);
-                  close(cfd);
-                  delete_peer(&peer_[i]);
-                  break;
-               }
-#else
             for (peer = peer_; peer; peer = peer->next)
                if (peer->tcpfd == cfd)
                {
@@ -926,7 +796,6 @@ void *ocat_controller(void *p)
                   delete_peer(peer);
                   break;
                }
-#endif
             pthread_mutex_unlock(&peer_mutex_);
          }
          else if (!strncmp(buf, "threads", 7))

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/onioncat.git



More information about the Pkg-privacy-commits mailing list