From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-04-ewr.dyndns.com (mxout-107-ewr.mailhop.org [216.146.33.107]) by lists.bufferbloat.net (Postfix) with ESMTP id 0CF082E03AD for ; Wed, 20 Apr 2011 13:27:45 -0700 (PDT) Received: from scan-01-ewr.mailhop.org (scanner [10.0.141.223]) by mail-04-ewr.dyndns.com (Postfix) with ESMTP id 723A27E27A4 for ; Tue, 19 Apr 2011 17:29:03 +0000 (UTC) X-Spam-Score: 0.1 () X-Mail-Handler: MailHop by DynDNS X-Originating-IP: 143.225.229.147 Received: from svn.comics.unina.it (unknown [143.225.229.147]) by mail-04-ewr.dyndns.com (Postfix) with ESMTP id 88A887E254A for ; Tue, 19 Apr 2011 17:29:01 +0000 (UTC) Received: from www-data by svn.comics.unina.it with local (Exim 4.69) (envelope-from ) id 1QCEnB-0001z7-5U for bismark-commits@lists.bufferbloat.net; Tue, 19 Apr 2011 19:32:49 +0200 To: bismark-commits@lists.bufferbloat.net From: walter@svn.comics.unina.it Message-Id: Date: Tue, 19 Apr 2011 19:32:49 +0200 Subject: [Bismark-commits] rev 327 - trunk/mserver X-BeenThere: bismark-commits@lists.bufferbloat.net X-Mailman-Version: 2.1.13 Precedence: list List-Id: Commit log for the bismark source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Apr 2011 20:27:46 -0000 Author: walter Date: 2011-04-19 19:32:49 +0200 (Tue, 19 Apr 2011) New Revision: 327 Removed: trunk/mserver/udpproxy.c Modified: trunk/mserver/daemons trunk/mserver/uprate Log: mserver cleaning Modified: trunk/mserver/daemons =================================================================== --- trunk/mserver/daemons 2011-04-16 17:33:41 UTC (rev 326) +++ trunk/mserver/daemons 2011-04-19 17:32:49 UTC (rev 327) @@ -4,14 +4,5 @@ pgrep -f TCP-LISTEN:143 >/dev/null || ./ritg pgrep -f TCP-LISTEN:777 >/dev/null || ./uprate pgrep -f ITGRecv >/dev/null || ( sudo ./ITGRecv >> /tmp/itg.log 2>&1 & ) -#pgrep -f udpproxy >/dev/null || ( ./udpproxy 123 143.215.131.215 5353 >> /tmp/udpproxy.log 2>&1 & ) pgrep -f probeserver >/dev/null || ( ./probeserver >> /tmp/spserver.log 2>&1 & ) -# Kill stucked ITGSend processes -MINUTES=2 -PMATCH='ITGSend' - -#sudo /usr/bin/find /proc/ -maxdepth 3 -name 'cmdline' -mmin +${MINUTES} -exec /bin/grep -l ${PMATCH} "{}" \; | \ -# /usr/bin/cut -d'/' -f3 | \ -# /usr/bin/xargs -n1 -i^ /bin/bash -c '/bin/kill ^ 2>&1 > /dev/null' - Deleted: trunk/mserver/udpproxy.c =================================================================== --- trunk/mserver/udpproxy.c 2011-04-16 17:33:41 UTC (rev 326) +++ trunk/mserver/udpproxy.c 2011-04-19 17:32:49 UTC (rev 327) @@ -1,175 +0,0 @@ -// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -// UDP Proxy Server multi-thread -// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- - -// Librerie -#include -#include -#include // gethostbyname() -#include - -#include -#include -#include // atoi() -#include // close() - -#include // posix threads - -// Costanti -#define QLEN 6 -#define MAX_NUM_THREAD 20 - -// Variabili globali (condivise da tutti i thread) -int num_thread; // numero di thread attivi -char gbuf[1000]; // buffer in cui memorizzare la stringa -struct sockaddr_in pad; // PROXY SERVER -struct sockaddr_in sad; // SERVER -pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; -int gsd; - -// Thread per la gestione di una singola connessione -void *doit(void *vncad) -{ - char lbuf[1000]; // buffer per la stringa modificata - int i, sd; - struct sockaddr_in lcad; - struct timeval timeout = {2,0}; - - pthread_mutex_lock(&mutex); - struct sockaddr_in ncad = *((struct sockaddr_in *)vncad); // copia locale del descrittore della socket - int thread_id = num_thread++; // identificativo logico del thread - strncpy(lbuf, gbuf, 1000); - pthread_mutex_unlock(&mutex); - - printf("Client %d: %s", thread_id, lbuf); - - // Inizializzazione della struttura lcad (Client) - memset((char *)&lcad, 0, sizeof(lcad)); - lcad.sin_family = AF_INET; - - // Creazione di una socket di tipo SOCK_DGRAM - UDP - if ((sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { - fprintf(stderr, "socket creation failed\n"); - exit(1); - } - setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(struct timeval)); - - // Configurazione dell'endpoint locale della socket utilizzando - // i parametri della struttura sockaddr_in cad - if (bind(sd, (struct sockaddr *)&lcad, sizeof(lcad)) < 0) { - fprintf(stderr, "bind failed\n"); - exit(2); - } - - // Invio della stringa al server - sendto(sd, lbuf, strlen(lbuf),0,(struct sockaddr*)&sad, sizeof(sad)); - - // Ricezione della risposta dal server - memset(lbuf, 0, sizeof(lbuf)); - if (recv(sd, lbuf, sizeof(lbuf), 0) < 0) { - printf("Timeout %d\n", thread_id); - } else { - printf("Server %d: %s", thread_id, lbuf); - - // Invio della risposta del server al client - sendto(gsd, lbuf, strlen(lbuf),0,(struct sockaddr*) &ncad, sizeof(ncad)); - } - close(sd); - - pthread_mutex_lock(&mutex); - num_thread--; - pthread_mutex_unlock(&mutex); - - return NULL; -} - - -int main(int argc, char *argv[]) -{ - unsigned short proxy_port; // numero di port del proxy - unsigned short server_port; // numero di port del servizio - struct hostent *ptrh; // struttura per memorizzare la risoluzione del nome del server - pthread_t hThr[MAX_NUM_THREAD]; - int i = 0; - - // Lettura delle opzioni a riga di comando - if (argc != 4) { - fprintf(stderr, "usage: %s \n", argv[0]); - return 0; - } - - // Acquisizione port del proxy - proxy_port = atoi(argv[1]); - if (proxy_port == 0) { - fprintf(stderr, "invalid port number: %s\n", argv[1]); - return 1; - } - - // Conversione del nome in indirizzo IP - if ((ptrh = gethostbyname(argv[2])) == NULL) { - fprintf(stderr, "invalid host address: %s\n", argv[2]); - return 1; - } - - // Acquisizione port del server - server_port = atoi(argv[3]); - if (proxy_port == 0) { - fprintf(stderr, "invalid port number: %s\n", argv[3]); - return 1; - } - - // Inzializzazione della struttura sad (Server) - memset((char *)&sad, 0, sizeof(sad)); - sad.sin_family = AF_INET; - memcpy(&sad.sin_addr, ptrh->h_addr, ptrh->h_length); // copia dell'indirizzo nel campo sin_addr della struttura sad - sad.sin_port = htons(server_port); - - // Inzializzazione della struttura pad (Proxy) - memset((char *)&pad, 0, sizeof(sad)); - pad.sin_family = AF_INET; - pad.sin_addr.s_addr = INADDR_ANY; - pad.sin_port = htons(proxy_port); // conversione di port da "host byte order" a "TCP/IP network order" - - // Creazione di una socket di tipo SOCK_DGRAM - UDP - if ((gsd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { - fprintf(stderr, "error creating socket\n"); - return 1; - } - - // Configurazione dell'endpoint locale della socket utilizzando - // i parametri della struttura sockaddr_in sad - if (bind(gsd, (struct sockaddr *)&pad, sizeof(pad)) < 0) { - fprintf(stderr, "bind fallito\n"); - return 1; - } - - printf("Proxy listening on port %d -> Redirecting to %s:%d\n", proxy_port, argv[2], server_port); - - // Ciclo infinito - while (1) { - char buf[1000]; // buffer in cui memorizzare la stringa - struct sockaddr_in cad; // CLIENT - socklen_t cadlen = sizeof(struct sockaddr_in); // dimensione della struttura cad - - // Ricezione della stringa inviata dal client - memset(buf, 0, sizeof(buf)); - recvfrom(gsd, buf, sizeof(buf), 0, (struct sockaddr*)&cad, &cadlen); - strncpy(gbuf, buf, 1000); - - // Controllo sul numero massimo di socket gestibili - if (num_thread >= MAX_NUM_THREAD) { - fprintf(stderr, "max connections reached: refusing %s\n", buf); - } else { - // Creazione di un thread per gestire la nuova connessione - if (pthread_create(&hThr[i], NULL, doit, &cad) < 0) { - fprintf(stderr, "error creating thread\n"); - } else { - pthread_detach(hThr[i]); - } - - } - } - - // Chiusura della socket in ascolto - close(gsd); -} Modified: trunk/mserver/uprate =================================================================== --- trunk/mserver/uprate 2011-04-16 17:33:41 UTC (rev 326) +++ trunk/mserver/uprate 2011-04-19 17:32:49 UTC (rev 327) @@ -34,13 +34,12 @@ stime=ltime } bytes += $21 - print bytes " " ltime - stime } END{ if (ltime - stime > 0) print ((bytes/125) / (ltime - stime)) }' /tmp/$ip.rate - #rm /tmp/$ip.rate + rm /tmp/$ip.rate ;; esac