From c5a389968b7de1970378f45c85506d783c15a70e Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Mon, 26 Jan 2004 12:12:08 +0000 Subject: [PATCH] Finished PLZ binkp, bumped version --- ChangeLog | 11 ++++++----- TODO | 4 +--- configure | 2 +- configure.in | 2 +- lib/execute.c | 8 ++++---- mbcico/binkp.c | 47 +++++++++++++++++++++++++++++++++++++++-------- 6 files changed, 52 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index d7abfa02..5855887c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ $Id$ -v0.39.7 14-Jan-2004 +v0.39.8 26-Jan-2004 + + +v0.39.7 14-Jan-2004 - 26-Jan-2004 remark: Calling points is availbale now, but I know in the past that I @@ -17,7 +20,7 @@ v0.39.7 14-Jan-2004 and after running the external program to make sure diskbuffers are committed. Added a milliseconds timer. - Before and after execute and execsh a 100 ms pause is inserted + Before and after execute and execsh a 200 ms pause is inserted to prevent (un)archiver and other errors. mbcico: @@ -35,9 +38,7 @@ v0.39.7 14-Jan-2004 session close delay time. During binkp handshake increased the timer of the receiver to avoid handshake timeouts. - Added PLZ compression option to binkp. Not yet 100% finished - but it seems to work. Not yet tested against latest Radius beta. - Be carefull! + Added PLZ compression option to binkp. mbfido: Removed sync calls that are now in execute. diff --git a/TODO b/TODO index 4e4d564b..1e106c0e 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,6 @@ $Id$ - MBSE BBS V0.39.7 TODO list. + MBSE BBS V0.39.8 TODO list. --------------------------- These are a list of things that must be implemented one way or @@ -123,8 +123,6 @@ mbcico: L: Implement binkp option ND. - L: Implement binkp zlib compression. - mbfile: L: Add a check to see if the magic filenames are (still) valid. diff --git a/configure b/configure index 524ec049..16da66a1 100755 --- a/configure +++ b/configure @@ -1275,7 +1275,7 @@ SUBDIRS="lib mbcico mbfido mbmon mbsebbs mbtask mbsetup unix lang examples html PACKAGE="mbsebbs" MAJOR="0" MINOR="39" -REVISION="7" +REVISION="8" VERSION="$MAJOR.$MINOR.$REVISION" COPYRIGHT="Copyright (C) 1997-2004 Michiel Broek, All Rights Reserved" SHORTRIGHT="Copyright (C) 1997-2004 M. Broek" diff --git a/configure.in b/configure.in index a36b74da..1ecc0534 100644 --- a/configure.in +++ b/configure.in @@ -13,7 +13,7 @@ dnl PACKAGE="mbsebbs" MAJOR="0" MINOR="39" -REVISION="7" +REVISION="8" VERSION="$MAJOR.$MINOR.$REVISION" COPYRIGHT="Copyright (C) 1997-2004 Michiel Broek, All Rights Reserved" SHORTRIGHT="Copyright (C) 1997-2004 M. Broek" diff --git a/lib/execute.c b/lib/execute.c index 6b091f45..64b0a977 100644 --- a/lib/execute.c +++ b/lib/execute.c @@ -140,12 +140,12 @@ int execute(char *cmd, char *file, char *pkt, char *in, char *out, char *err) #ifdef __linux__ sync(); #endif - msleep(100); + msleep(200); rc = _execute(cmd, file, pkt, in, out, err); - msleep(100); #ifdef __linux sync(); #endif + msleep(200); return rc; } @@ -217,12 +217,12 @@ int execsh(char *cmd, char *in, char *out, char *err) #ifdef __linux__ sync(); #endif - msleep(100); + msleep(200); rc = _execsh(cmd, in, out, err); - msleep(100); #ifdef __linux__ sync(); #endif + msleep(200); return rc; } diff --git a/mbcico/binkp.c b/mbcico/binkp.c index c80dcc0f..a97631c6 100644 --- a/mbcico/binkp.c +++ b/mbcico/binkp.c @@ -132,6 +132,7 @@ struct binkprec { int Minor; /* Minor protocol version */ unsigned char *MD_Challenge; /* Received challenge data */ int PLZflag; /* Zlib packet compression */ + int cmpblksize; /* Ideal next blocksize */ /* Receiver buffer */ char *rxbuf; /* Receiver buffer */ @@ -233,6 +234,7 @@ int binkp(int role) bp.local_EOB = FALSE; bp.remote_EOB = FALSE; bp.msgs_on_queue = 0; + bp.cmpblksize = SND_BLKSIZE; #ifdef HAVE_ZLIB_H bp.PLZflag = WeCan; #else @@ -1077,6 +1079,7 @@ TrType binkp_receiver(void) rxbytes = bp.rxbytes; bp.rxfp = openfile(binkp2unix(bp.rname), bp.rtime, bp.rsize, &rxbytes, binkp_resync); bp.rxbytes = rxbytes; + bp.rxcompressed = 0; if (bp.DidSendGET) { Syslog('b', "Binkp: DidSendGET is set"); @@ -1203,6 +1206,10 @@ TrType binkp_receiver(void) closefile(); bp.rxpos = bp.rxpos - bp.rxbytes; gettimeofday(&rxtvend, &bp.tz); +#ifdef HAVE_ZLIB_H + if (bp.rxcompressed && (bp.PLZflag == Active)) + Syslog('+', "Binkp: %s", compress_stat(bp.rxpos, bp.rxcompressed)); +#endif Syslog('+', "Binkp: OK %s", transfertime(rxtvstart, rxtvend, bp.rxpos, FALSE)); rcvdbytes += bp.rxpos; bp.RxState = RxWaitF; @@ -1351,6 +1358,7 @@ TrType binkp_transmitter(void) } bp.txpos = bp.stxpos = tmp->offset; + bp.txcompressed = 0; Syslog('+', "Binkp: send \"%s\" as \"%s\"", MBSE_SS(tmp->local), MBSE_SS(tmp->remote)); Syslog('+', "Binkp: size %lu bytes, dated %s", (unsigned long)tmp->size, date(tmp->date)); rc = binkp_send_command(MM_FILE, "%s %lu %ld %ld", MBSE_SS(tmp->remote), @@ -1395,7 +1403,7 @@ TrType binkp_transmitter(void) } else if (bp.TxState == TxReadS) { fseek(bp.txfp, bp.txpos, SEEK_SET); - bp.txlen = fread(bp.txbuf, 1, SND_BLKSIZE, bp.txfp); + bp.txlen = fread(bp.txbuf, 1, bp.cmpblksize, bp.txfp); eof = feof(bp.txfp); if ((bp.txlen == 0) || eof) { @@ -1434,6 +1442,10 @@ TrType binkp_transmitter(void) if (bp.txpos >= 0) { bp.stxpos = bp.txpos - bp.stxpos; +#ifdef HAVE_ZLIB_H + if (bp.txcompressed && (bp.PLZflag == Active)) + Syslog('+', "Binkp: %s", compress_stat(bp.stxpos, bp.txcompressed)); +#endif Syslog('+', "Binkp: OK %s", transfertime(txtvstart, txtvend, bp.stxpos, TRUE)); } else { Syslog('+', "Binkp: transmitter skipped file after %ld seconds", txtvend.tv_sec - txtvstart.tv_sec); @@ -1548,7 +1560,7 @@ int binkp_send_frame(int cmd, char *buf, int len) unsigned short header = 0; int rc, id; #ifdef HAVE_ZLIB_H - int rcz; + int rcz, last; unsigned long zlen; char *zbuf; #endif @@ -1577,6 +1589,7 @@ int binkp_send_frame(int cmd, char *buf, int len) } #ifdef HAVE_ZLIB_H + last = bp.cmpblksize; if ((bp.PLZflag == Active) && (len > 20)) { zbuf = calloc(BINKP_ZIPBUFLEN, sizeof(char)); rcz = compress2(zbuf, &zlen, buf, len, 9); @@ -1585,6 +1598,19 @@ int binkp_send_frame(int cmd, char *buf, int len) len, zlen, (zlen < len) ?"yes":"no"); if (zlen < len) { bp.txcompressed += (len - zlen); + /* + * Calculate the perfect blocksize for the next block + * using the current compression ratio. This gives + * a dynamic optimal blocksize. The average maximum + * blocksize on the line will be 4096 bytes. + */ + if (!cmd) { + bp.cmpblksize = ((len * 4) / zlen) * 512; + if (bp.cmpblksize < SND_BLKSIZE) + bp.cmpblksize = SND_BLKSIZE; + if (bp.cmpblksize > (BINKP_PLZ_BLOCK -1)) + bp.cmpblksize = (BINKP_PLZ_BLOCK -1); + } /* * Rebuild header for compressed block */ @@ -1604,6 +1630,8 @@ int binkp_send_frame(int cmd, char *buf, int len) rc = PUTCHAR(header & 0x00ff); if (len && !rc) rc = PUT(buf, len); + if (!cmd) + bp.cmpblksize = SND_BLKSIZE; } } else { rc = PUTCHAR((header >> 8) & 0x00ff); @@ -1611,6 +1639,8 @@ int binkp_send_frame(int cmd, char *buf, int len) rc = PUTCHAR(header & 0x00ff); if (len && !rc) rc = PUT(buf, len); + if (!cmd) + bp.cmpblksize = SND_BLKSIZE; } free(zbuf); } else { @@ -1619,13 +1649,18 @@ int binkp_send_frame(int cmd, char *buf, int len) rc = PUTCHAR(header & 0x00ff); if (len && !rc) rc = PUT(buf, len); + if (!cmd) + bp.cmpblksize = SND_BLKSIZE; } + if (!cmd && (last != bp.cmpblksize)) + Syslog('b', "Binkp: adjusting next blocksize to %d bytes", bp.cmpblksize); #else rc = PUTCHAR((header >> 8) & 0x00ff); if (!rc) rc = PUTCHAR(header & 0x00ff); if (len && !rc) rc = PUT(buf, len); + bp.cmpblksize = SND_BLKSIZE; #endif FLUSHOUT(); @@ -1896,7 +1931,7 @@ void parse_m_nul(char *msg) */ int binkp_poll_frame(void) { - int c, rc = 0, bcmd; + int c, rc = 0, bcmd; #ifdef HAVE_ZLIB_H int plz = FALSE; unsigned long zlen; @@ -1946,15 +1981,12 @@ int binkp_poll_frame(void) } if ((bp.rxlen == (bp.blklen + 1) && (bp.rxlen >= 1))) { bp.GotFrame = TRUE; - Syslog('b', "Binkp: got a complete %s frame, mode %scompressed", bp.cmd?"CMD":"DATA", plz?"":"un"); #ifdef HAVE_ZLIB_H if (plz) { - Syslog('b', "Binkp: rcvd compressed block %d bytes", bp.rxlen -1); zbuf = calloc(BINKP_ZIPBUFLEN, sizeof(char)); rc = uncompress(zbuf, &zlen, bp.rxbuf, bp.rxlen -1); - Syslog('b', "Binkp: uncompress rc=%d %d => %d", rc, bp.rxlen -1, zlen); if (rc == Z_OK) { - bp.rxcompressed = (zlen - (bp.rxlen -1)); + bp.rxcompressed += (zlen - (bp.rxlen -1)); memmove(bp.rxbuf, zbuf, zlen); bp.rxlen = zlen +1; bp.blklen = zlen; @@ -1966,7 +1998,6 @@ int binkp_poll_frame(void) free(zbuf); } #endif - Syslog('b', "Binkp: bp.rxlen=%d bp.blklen=%d", bp.rxlen, bp.blklen); bp.rxbuf[bp.rxlen-1] = '\0'; if (bp.cmd) { bp.messages++;