From a619282f8a9cb2342cb51b47b610e431296b6d07 Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Mon, 13 Oct 2003 10:52:58 +0000 Subject: [PATCH] Added experimental hydra compression --- configure | 142 ----------------------------------------------- configure.in | 3 +- mbcico/hydra.c | 74 +++++++++++++++++++++--- mbcico/hydra.h | 1 + mbsebbs/Makefile | 2 +- mbsebbs/door.c | 1 + 6 files changed, 71 insertions(+), 152 deletions(-) diff --git a/configure b/configure index 45b89c6d..51604072 100755 --- a/configure +++ b/configure @@ -4324,149 +4324,7 @@ fi if test "$result" = "yes"; then LIBS="$LIBS -lz" - -for ac_header in zlib.h -do -as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` -if eval "test \"\${$as_ac_Header+set}\" = set"; then - echo "$as_me:$LINENO: checking for $ac_header" >&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$as_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -fi -echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 -else - # Is the header compilable? -echo "$as_me:$LINENO: checking $ac_header usability" >&5 -echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6 -cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_header_compiler=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_header_compiler=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -echo "${ECHO_T}$ac_header_compiler" >&6 - -# Is the header present? -echo "$as_me:$LINENO: checking $ac_header presence" >&5 -echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6 -cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - ac_header_preproc=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi -rm -f conftest.err conftest.$ac_ext -echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -echo "${ECHO_T}$ac_header_preproc" >&6 - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc in - yes:no ) - { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - ( - cat <<\_ASBOX -## ------------------------------------ ## -## Report this to bug-autoconf@gnu.org. ## -## ------------------------------------ ## -_ASBOX - ) | - sed "s/^/$as_me: WARNING: /" >&2 - ;; - no:yes ) - { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - ( - cat <<\_ASBOX -## ------------------------------------ ## -## Report this to bug-autoconf@gnu.org. ## -## ------------------------------------ ## -_ASBOX - ) | - sed "s/^/$as_me: WARNING: /" >&2 - ;; -esac -echo "$as_me:$LINENO: checking for $ac_header" >&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$as_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - eval "$as_ac_Header=$ac_header_preproc" -fi -echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 - -fi -if test `eval echo '${'$as_ac_Header'}'` = yes; then - cat >>confdefs.h <<_ACEOF -#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - -fi echo "$as_me:$LINENO: checking for ANSI C header files" >&5 echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6 diff --git a/configure.in b/configure.in index 00eb7fef..8189042c 100644 --- a/configure.in +++ b/configure.in @@ -126,7 +126,7 @@ fi AC_CHECK_LIB(z,compress,result=yes,result=no) if test "$result" = "yes"; then LIBS="$LIBS -lz" - AC_CHECK_HEADERS(zlib.h) + dnl AC_CHECK_HEADERS(zlib.h) fi dnl Checks for header files. @@ -137,7 +137,6 @@ AC_HEADER_SYS_WAIT AC_CHECK_HEADERS(malloc.h sys/file.h sys/ioctl.h sys/time.h termios.h syslog.h sys/vfs.h unistd.h netinet/in.h regex.h) AC_CHECK_HEADERS(sys/resource.h usersec.h utime.h ulimit.h gshadow.h shadow.h) AC_CHECK_HEADERS(limits.h utmp.h utmpx.h lastlog.h rpc/key_prot.h) -dnl AC_CHECK_HEADERS(zlib.h) FIXME: enable when ready for endusers. AC_CHECK_HEADERS(iconv.h) AC_STRUCT_TIMEZONE diff --git a/mbcico/hydra.c b/mbcico/hydra.c index 9fc013bc..506fb3fb 100644 --- a/mbcico/hydra.c +++ b/mbcico/hydra.c @@ -229,7 +229,7 @@ int put_hexbyte(char *outbuf, char c) /* TODO: error handling */ enum HyPktTypes hyrxpkt(char *rxbuf, int *rxlen, int tot) { - static char rxencbuf[H_BUFLEN]; + static char rxencbuf[H_ZIPBUFLEN]; static enum HyPktTypes pkttype = H_NOPKT; static char *inbuf = rxencbuf, *outbuf; int c, i, n; @@ -357,7 +357,7 @@ enum HyPktTypes hyrxpkt(char *rxbuf, int *rxlen, int tot) /* TODO: support packet prefix string */ void hytxpkt(enum HyPktTypes pkttype, char *txbuf, int txlen) { - static char txencbuf[H_BUFLEN]; + static char txencbuf[H_ZIPBUFLEN]; char *outbuf, *inbuf; enum HyPktFormats format; @@ -529,12 +529,14 @@ int resync(off_t off) int hydra_batch(int role, file_list *to_send) { - static char txbuf[H_BUFLEN], rxbuf[H_BUFLEN]; + static char txbuf[H_ZIPBUFLEN], rxbuf[H_ZIPBUFLEN]; + static char txzbuf[H_ZIPBUFLEN], rxzbuf[H_ZIPBUFLEN]; struct stat txstat; /* file stat being transmitted */ FILE *txfp = NULL; /* file currently being transmitted */ FILE *rxfp = NULL; /* file currently being received */ char *inbuf, *outbuf; int rxlen, txlen; /* length of receive/transmit buffer */ + unsigned long rxzlen, txzlen; /* length of receive/transmit compressed buffer */ long txwindow, rxwindow; /* window sizes */ long txpos; off_t rxpos; /* file positions */ @@ -558,6 +560,7 @@ int hydra_batch(int role, file_list *to_send) struct timeval rxstarttime, rxendtime; struct timezone tz; int sverr; + int rcz; Syslog('h', "Hydra: resettimers"); RESETTIMERS(); @@ -1009,12 +1012,45 @@ int hydra_batch(int role, file_list *to_send) } } else { // FIXME: Here we must add the compression code +#ifdef HAVE_ZLIB_H + if (txoptions & HOPT_CANPLZ) { + txzlen = H_ZIPBUFLEN; + rcz = compress(txzbuf, &txzlen, txbuf, txlen); + if (rcz == Z_OK) { + Syslog('h', "Compressed OK, srclen=%d, destlen=%d, will send compressed=%s", txlen, txzlen, + (txzlen < txlen) ?"yes":"no"); + if (txzlen < txlen) { + txpos += txlen; + sentbytes += txlen; + goodbytes += txlen; + txzlen += 4; + hytxpkt(HPKT_ZIPDATA, txzbuf, txzlen); + } else { + txpos += txlen; + sentbytes += txlen; + goodbytes += txlen; + txlen += 4; + hytxpkt(HPKT_DATA, txbuf, txlen); + } + } else { + /* + * Compress failed, send data uncompressed + */ + Syslog('h', "Compress error"); + txpos += txlen; + sentbytes += txlen; + goodbytes += txlen; + txlen += 4; + hytxpkt(HPKT_DATA, txbuf, txlen); + } + } +#else txpos += txlen; sentbytes += txlen; goodbytes += txlen; txlen += 4; hytxpkt(HPKT_DATA, txbuf, txlen); - +#endif if (goodbytes > goodneeded) { blksize *= 2; if (blksize > H_MAXBLKLEN) { @@ -1241,7 +1277,7 @@ int hydra_batch(int role, file_list *to_send) */ txoptions = rxoptions; put_flags(txbuf, rxoptions); - Syslog('h', "Hydra: options: %s (%08lx)", txbuf, rxoptions); + Syslog('+', "Hydra: options: %s (%08lx)", txbuf, rxoptions); /* * get desired window sizes @@ -1383,13 +1419,35 @@ int hydra_batch(int role, file_list *to_send) case HRX_DATA: Syslog('h', "SM 'HRX' entering 'DATA'"); - // FIXME: Here the zlib extensions. +#ifdef HAVE_ZLIB_H + if (((pkttype == HPKT_DATA) || (pkttype == HPKT_ZIPDATA)) && (rxlen > 4)) { + longnum = get_long(rxbuf); + Syslog('h', "Hydra: rcvd %sDATA (0x%08lx, 0x%08lx) %lu", (pkttype == HPKT_ZIPDATA) ? "ZIP":"", + longnum, rxpos, rxlen-4); +#else if ((pkttype == HPKT_DATA) && (rxlen > 4)) { longnum = get_long(rxbuf); Syslog('h', "Hydra: rcvd DATA (0x%08lx, 0x%08lx) %lu", longnum, rxpos, rxlen-4); +#endif Nopper(); - if (longnum == rxpos) { +#ifdef HAVE_ZLIB_H + if (pkttype == HPKT_ZIPDATA) { + rxzlen = H_ZIPBUFLEN; + rcz = uncompress(rxzbuf, &rxzlen, rxbuf + 4, rxlen - 4); + if (rcz == Z_OK) { + /* + * Uncompress data and put the data into the normal + * receive buffer. + */ + Syslog('h', "uncompressed size %d => %d", rxlen -4, rxzlen); + memcpy(rxbuf + 4, rxzbuf, rxzlen); + rxlen = rxzlen + 4; + } else { + Syslog('h', "Uncompress error, fatal what should we do"); + } + } +#endif if (fwrite(rxbuf + 4, 1, rxlen - 4, rxfp) != (rxlen - 4)) { WriteError("$Hydra: error writing to file"); rxpos = -2; @@ -1637,6 +1695,8 @@ int hydra(int role) if (session_flags & SESSION_WAZOO) request = create_freqlist(remote); + Syslog('h', "H_BUFLEN=%d H_ZIPBUFLEN=%d", H_BUFLEN, H_ZIPBUFLEN); + /* * Send only file requests during first batch if remote supports diff --git a/mbcico/hydra.h b/mbcico/hydra.h index 37ab0cbf..4ca8e238 100644 --- a/mbcico/hydra.h +++ b/mbcico/hydra.h @@ -80,6 +80,7 @@ #define H_OVERHEAD 8 /* Max. no. control bytes in a pkt */ #define H_MAXPKTLEN ((H_MAXBLKLEN + H_OVERHEAD + 5) * 3) /* Encoded pkt */ #define H_BUFLEN (H_MAXPKTLEN + 16) /* Buffer sizes: max.enc.pkt + slack */ +#define H_ZIPBUFLEN (((H_BUFLEN * 11) / 10) + 12) /* Compressed data pkt */ #define H_PKTPREFIX 31 /* Max length of pkt prefix string */ #define H_FLAGLEN 3 /* Length of a flag field */ #define H_RETRIES 10 /* No. retries in case of an error */ diff --git a/mbsebbs/Makefile b/mbsebbs/Makefile index 7ca91565..a0686ded 100644 --- a/mbsebbs/Makefile +++ b/mbsebbs/Makefile @@ -164,7 +164,7 @@ user.o: ../config.h ../lib/libs.h ../lib/mbse.h ../lib/structs.h ../lib/users.h mbnewusr.o: ../config.h ../lib/libs.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/mberrors.h mbnewusr.h funcs.h input.h language.h misc.h timeout.h newuser.h input.o: ../config.h ../lib/libs.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h ../lib/mberrors.h input.h timeout.h language.h whoson.o: ../config.h ../lib/libs.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h input.h language.h exitinfo.h whoson.h -door.o: ../config.h ../lib/libs.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/mberrors.h input.h timeout.h exitinfo.h whoson.h door.h +door.o: ../config.h ../lib/libs.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/mberrors.h language.h input.h timeout.h exitinfo.h whoson.h door.h dispfile.o: ../config.h ../lib/libs.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/msgtext.h ../lib/msg.h ../lib/clcomm.h funcs.h language.h oneline.h misc.h timeout.h timecheck.h exitinfo.h mail.h email.h input.h dispfile.h filesub.h userlist.o: ../config.h ../lib/libs.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h userlist.h language.h input.h timeout.h timestats.o: ../config.h ../lib/libs.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h timestats.h funcs.h language.h input.h exitinfo.h diff --git a/mbsebbs/door.c b/mbsebbs/door.c index b8d16fcc..0edb6c11 100644 --- a/mbsebbs/door.c +++ b/mbsebbs/door.c @@ -37,6 +37,7 @@ #include "../lib/common.h" #include "../lib/clcomm.h" #include "../lib/mberrors.h" +#include "language.h" #include "input.h" #include "timeout.h" #include "exitinfo.h"