|
From: Hans-Peter Z. <hp...@14...> - 2002-04-24 16:23:07
|
-----Weitergeleitete Nachricht-----
From: Tomi Manninen <tp...@pr...>
To: Hans-Peter Zorn <hp...@14...>
Subject: LinKT patch
Date: 24 Apr 2002 19:20:22 +0300
Hi Hans-Peter,
Would you consider the applying the attached patch to the mainstream LinKT
code? The patch adds support for LinuxNode compatible zlib compression. =20
I have tried to make sure it won't interfere with anything else in LinKT
and I can say that things have worked FB for me both with compression
enabled and disabled.
PS. The comression scheme in LinuxNode does not have any negotiation=20
capabilities so each end must know forehand that the other end is=20
expecting compression. That's also why enabling the compression is a bit=20
ugly: you have to connect to a "compressed" LinuxNode, ignore the garbage=20
you will get on the screen, then enable zlib compression in settings menu=20
for this user and finally diconnect. Compression will work on the next=20
connection to this peer.
--=20
Tomi Manninen Internet: oh...@sr...
OH2BNS AX.25: oh...@oh...
KP20ME04 Amprnet: oh...@oh...
----
diff -ruN -X dontdiff linkt-0.6.99-20011124-CVS/linkt/Makefile.am linkt-0.6=
.99-20011124-CVS-bns/linkt/Makefile.am
--- linkt-0.6.99-20011124-CVS/linkt/Makefile.am Thu Feb 1 18:01:10 2001
+++ linkt-0.6.99-20011124-CVS-bns/linkt/Makefile.am Sat Feb 9 23:20:23 200=
2
@@ -33,7 +33,8 @@
remote.cpp userinfo.cpp settingsdlg.cpp chanlist.cpp\
bin.cpp crc.cpp dostime.cpp passwords.cpp pathcheck.cpp\
comp.cpp ahuf.cpp filetrans.cpp auto7.cpp \
- pref.cpp cfg.cpp userdata.cpp checksums.cpp
+ pref.cpp cfg.cpp userdata.cpp checksums.cpp \
+ zcomp.cpp
=20
# the library search path.=20
linkt_LDFLAGS =3D $(all_libraries) $(KDE_RPATH)=20
@@ -51,7 +52,7 @@
bin.h crc.h dostime.h passwords.h didadit.h md5.h\
comp.h boxcheck.h sound.h userdata.h checksums.h\
yapp.h local_ax25.h filetrans.h auto7.h pref.h cfg.h \
- gpg.h pathcheck.h=20
+ gpg.h pathcheck.h zcomp.h
=20
# just to make sure, automake makes them=20
BUILTSOURCES =3D main.moc channel.moc output.moc vorschreib.moc ax25k.moc\
diff -ruN -X dontdiff linkt-0.6.99-20011124-CVS/linkt/channel.cpp linkt-0.6=
.99-20011124-CVS-bns/linkt/channel.cpp
--- linkt-0.6.99-20011124-CVS/linkt/channel.cpp Sun Nov 11 22:40:45 2001
+++ linkt-0.6.99-20011124-CVS-bns/linkt/channel.cpp Sun Feb 10 00:27:08 200=
2
@@ -33,6 +33,7 @@
#include "queuelist.h"
#include "yapp.h"
#include "ahuf.h"
+#include "zcomp.h"
#include "gpg.h"
#include "didadit.h"
#include "infobar.h"
@@ -358,6 +359,9 @@
// TOP-Huffman
ahuf =3D new AHUF();
=20
+ // Zlib compression
+ zcomp =3D new ZCOMP();
+
// Connect-Pfad
connectPath =3D new ConnectPathCheck();
connectPath->add( call );
@@ -533,6 +537,7 @@
delete userinfo;
delete remote;
delete ahuf;
+ delete zcomp;
delete password;
delete boxcheck;
}
@@ -966,10 +971,22 @@
char buffer[FRAMESIZE+1];
=20
- if (pollStatus() =3D=3D 0) return;
+ if (pollStatus() =3D=3D 0) return;
=20
bytesTX +=3D len;
=20
+ if ((userinfo->getFlags() & CH_ZCOMP) > 0 || (comp =3D=3D COMP_Z))
+ {
+ do
+ {
+ if ((count =3D zcomp->Compress(str, len, buffer, FRAMESIZE)) > 0)
+ if (write(txfd, buffer, count) !=3D count)
+ send_error =3D true; =20
+ }
+ while (count =3D=3D FRAMESIZE);
+ return;
+ }
+
// Wenn dieses Frame Huffman gepackt sein soll, wird hier gewandelt.
is_huff =3D false;
if (comp !=3D COMP_NO)
@@ -1002,47 +1019,64 @@
//
// Diese Funktion wird aufgerufen, wenn von unserer Verbindung Daten
// gekommen sind.
+
+#define CHBUFLEN 1024
+
void Channel::rxFrame(int socket)
{
- char tmp[1000], output[1000];
- int len, tmplen;
+ char tmp[CHBUFLEN], output[CHBUFLEN];
+ int len, tmplen, count;
=20
- len =3D read(socket, tmp, 1000);
+ len =3D read(socket, tmp, CHBUFLEN);
=20
- if (len > 0)
+ if (len <=3D 0)
+ return;
+
+ if (old_status =3D=3D 1)
+ {
+ statusConnectGot();
+ old_status =3D 4;
+ }
+
+ if ((userinfo->getFlags() & CH_ZCOMP) > 0)
{
- if ((flags & CH_COMP) > 0)
+ do
{
- if ((tmplen =3D decomp_stat_huff( tmp, len, output )) > 0)
- {
- len =3D tmplen;
- memcpy(tmp, output, len);
- tmp[len] =3D '\0';
- }
+ if ((count =3D zcomp->Decompress(tmp, len, output, CHBUFLEN)) > 0)
+ {
+ bytesRX +=3D count;
+ work_with_frame(output, count);
+ }
}
+ while (count =3D=3D CHBUFLEN);
+ return;
+ }
=20
- if ((flags & CH_HUF_RX) > 0)
+ if ((flags & CH_COMP) > 0)
+ {
+ if ((tmplen =3D decomp_stat_huff( tmp, len, output )) > 0)
{
- if ((tmplen =3D ahuf->DeKomprimieren( output, tmp, len )) > 0)
- {
- len =3D tmplen;
- memcpy(tmp, output, len);
- tmp[len] =3D '\0';
- }
+ len =3D tmplen;
+ memcpy(tmp, output, len);
+ tmp[len] =3D '\0';
}
+ }
=20
- bytesRX +=3D len;
-
- if (old_status =3D=3D 1)
+ if ((flags & CH_HUF_RX) > 0)
+ {
+ if ((tmplen =3D ahuf->DeKomprimieren( output, tmp, len )) > 0)
{
- statusConnectGot();
- old_status =3D 4;
+ len =3D tmplen;
+ memcpy(tmp, output, len);
+ tmp[len] =3D '\0';
}
-
- work_with_frame(tmp, len);
- return;
}
+
+ bytesRX +=3D len;
+
+ work_with_frame(tmp, len);
}
+
//------------------------------------------------------------------------=
---
void Channel::checkPi1chlConnect(char *data)
{
@@ -1630,6 +1664,9 @@
didadit =3D NULL;
}
=20
+ if ((userinfo->getFlags() & CH_ZCOMP) > 0)
+ zcomp->End();
+
if (conf->getFlag(CFG_CLOSEWINDISC)) close();
if (txfd !=3D -1)
{
@@ -1679,6 +1716,9 @@
binrx =3D NULL;
}
=20
+ if ((userinfo->getFlags() & CH_ZCOMP) > 0)
+ zcomp->End();
+
if (conf->getFlag(CFG_CLOSEWINDISC)) close();
if (txfd !=3D -1)
{
diff -ruN -X dontdiff linkt-0.6.99-20011124-CVS/linkt/channel.h linkt-0.6.9=
9-20011124-CVS-bns/linkt/channel.h
--- linkt-0.6.99-20011124-CVS/linkt/channel.h Tue Feb 6 01:39:09 2001
+++ linkt-0.6.99-20011124-CVS-bns/linkt/channel.h Sat Feb 9 23:53:39 2002
@@ -51,6 +51,7 @@
class FileTransfer;
class YAPP;
class AHUF;
+class ZCOMP;
class CheckGPG;
class DIDADIT;
class TransferInfo;
@@ -140,6 +141,7 @@
DIDADIT *didadit;
YAPP *yapp;
AHUF *ahuf;
+ ZCOMP *zcomp;
CheckGPG *gpg;
Passwords *password;
int filerx_fd;
diff -ruN -X dontdiff linkt-0.6.99-20011124-CVS/linkt/flags.h linkt-0.6.99-=
20011124-CVS-bns/linkt/flags.h
--- linkt-0.6.99-20011124-CVS/linkt/flags.h Sun Sep 2 20:03:56 2001
+++ linkt-0.6.99-20011124-CVS-bns/linkt/flags.h Sun Feb 10 00:21:41 2002
@@ -41,12 +41,13 @@
#define CH_YAPP 32 // Es wird gerade ein YAPP-File transferiert
#define CH_LINEMODE 64 // Daten Zeilenweise oder Frameweise weitergeben?
#define CH_AUTOBINTX 128 // Wird gerade ein Autobin-File gesendet?
-#define CH_COMP 256 // Online Huffman-Komprimierung (//COMP =3D SP)
+#define CH_COMP 256 // Online Huffman-Komprimierung (//COMP =3D SP)
#define CH_CAN_SEND 512 // Vertr=E4gt der Treiber auf diesem Kanal noch =
ein Frame?
-#define CH_DIDADIT 1024 // DIDADIT-Uebertragung
-#define CH_HUF_TX 2048 // Online Huffman-Komprimierung (#HUF# =3D T=
OP)
-#define CH_HUF_RX 4096 // Online Huffman-Komprimierung (#HUF# =3D T=
OP)
+#define CH_DIDADIT 1024 // DIDADIT-Uebertragung
+#define CH_HUF_TX 2048 // Online Huffman-Komprimierung (#HUF# =3D TOP)
+#define CH_HUF_RX 4096 // Online Huffman-Komprimierung (#HUF# =3D TOP)
#define CH_TSIDTX 8192 // Haben wir unsere Terminal-SID gesendet?
+#define CH_ZCOMP 16384 // Online Zlib compression
=20
#define TYPE_TERMINAL 1
#define TYPE_MAILBOX 2
@@ -164,7 +165,8 @@
#define COMP_FLAG 0
#define COMP_SP 1
#define COMP_HUF 2
-#define COMP_NO 3
+#define COMP_Z 3
+#define COMP_NO 4
=20
diff -ruN -X dontdiff linkt-0.6.99-20011124-CVS/linkt/settingsdlg.cpp linkt=
-0.6.99-20011124-CVS-bns/linkt/settingsdlg.cpp
--- linkt-0.6.99-20011124-CVS/linkt/settingsdlg.cpp Thu Feb 1 20:25:18 200=
1
+++ linkt-0.6.99-20011124-CVS-bns/linkt/settingsdlg.cpp Sun Feb 10 00:08:59=
2002
@@ -200,13 +200,16 @@
hufcomprx->setText( i18n( "#HUF# RX active" ));
hufcomprx->setAutoResize( true );
=20
- allowANSI =3D new QCheckBox( conf_settings );
+ allowANSI =3D new QCheckBox( conf_settings );
allowANSI->setGeometry( 260, 230, 190, 20 );
allowANSI->setText( i18n( "Allow ANSI-Codes" ));
allowANSI->setAutoResize( true );
allowANSI->setEnabled( conf->getFlag(CFG_ALLOWANSI) );
=20
-
+ zlibcomp =3D new QCheckBox( conf_settings );
+ zlibcomp->setGeometry( 260, 250, 190, 20 );
+ zlibcomp->setText( i18n( "ZLib compression active" ));
+ zlibcomp->setAutoResize( true );
=20
QLabel* label;
label =3D new QLabel( conf_settings );
@@ -570,6 +573,8 @@
else
slotHufAllowToggled( huf_allowed->isChecked() );
=20
+ if ((flags & CH_ZCOMP) !=3D 0)
+ zlibcomp->setChecked( true );
=20
remote =3D ((Channel *)chan)->userinfo->getRemotes();
if ((remote & REMOTE_QUIT) !=3D 0)
@@ -767,6 +772,11 @@
else
flags &=3D ~CH_HUFALLOW;
=20
+ if (zlibcomp->isChecked())
+ flags |=3D CH_ZCOMP;
+ else
+ flags &=3D ~CH_ZCOMP;
+
// Geaenderte Flags speichern
((Channel *)chan)->userinfo->setFlags(flags);
=20
@@ -927,7 +937,7 @@
SettingsDlg::SettingsDlg(QWidget *parent)
: QTabDialog(0, i18n("configure"), true)
{
- setFixedSize(455, 330);
+ setFixedSize(455, 350);
=20
chan =3D parent;
=20
diff -ruN -X dontdiff linkt-0.6.99-20011124-CVS/linkt/settingsdlg.h linkt-0=
.6.99-20011124-CVS-bns/linkt/settingsdlg.h
--- linkt-0.6.99-20011124-CVS/linkt/settingsdlg.h Sat Nov 18 19:38:38 2000
+++ linkt-0.6.99-20011124-CVS-bns/linkt/settingsdlg.h Sun Feb 10 00:09:57 2=
002
@@ -80,7 +80,7 @@
// conf_settings
QCheckBox *seven_autosave, *bin_autosave, *rec_con, *rec_discon;
QCheckBox *autosend_pw, *remotes, *huf_allowed, *onlinecomp, *hufcomptx=
;
- QCheckBox *hufcomprx, *didadit, *allowANSI;
+ QCheckBox *hufcomprx, *didadit, *allowANSI, *zlibcomp;
QLineEdit *call, *name;
QRadioButton *type_term, *type_digi, *type_bbs, *type_convers;
QComboBox *swtype;
diff -ruN -X dontdiff linkt-0.6.99-20011124-CVS/linkt/zcomp.cpp linkt-0.6.9=
9-20011124-CVS-bns/linkt/zcomp.cpp
--- linkt-0.6.99-20011124-CVS/linkt/zcomp.cpp Thu Jan 1 02:00:00 1970
+++ linkt-0.6.99-20011124-CVS-bns/linkt/zcomp.cpp Sat Feb 9 23:27:28 2002
@@ -0,0 +1,174 @@
+#include <stdio.h>
+#include <string.h>
+
+#include "zcomp.h"
+
+#undef COMP_DEBUG
+#undef DECOMP_DEBUG
+
+/*
+ * Compress srclen bytes, starting at *src. Result is stored in *dest,
+ * a buffer of length destlen.
+ *
+ * Returns the amount of compressed data. If this equals to the
+ * original destlen, compress() must be called again with a new
+ * dest buffer. (src and srclen is ignored at next call)
+ */
+int ZCOMP::Compress(char *src, int srclen, char *dest, int destlen)
+{
+ int ret =3D -1;
+
+ if ((flags & ZCOMP_INIT) =3D=3D 0 && Init())
+ return -1;
+
+ if ((flags & ZCOMP_COMP) =3D=3D 0) {
+ zout.next_in =3D (unsigned char *) src;
+ zout.avail_in =3D srclen;
+ raw_out +=3D srclen;
+ }
+
+#ifdef COMP_DEBUG
+ fprintf(stderr, "avail_in: %4d \t", zout.avail_in);
+ fprintf(stderr, "avail_out: %4d \t", zout.avail_out);
+ fprintf(stderr, "ret: %2d \t", ret);
+ fprintf(stderr, "flag: %s\n", (flags & ZCOMP_COMP) ? "set" : "unset");
+#endif
+
+ zout.next_out =3D (unsigned char *) dest;
+ zout.avail_out =3D destlen;
+
+ ret =3D deflate(&zout, Z_SYNC_FLUSH);
+
+ if (zout.avail_out =3D=3D 0)
+ flags |=3D ZCOMP_COMP;
+ else
+ flags &=3D ~ZCOMP_COMP;
+
+#ifdef COMP_DEBUG
+ fprintf(stderr, "avail_in: %4d \t", zout.avail_in);
+ fprintf(stderr, "avail_out: %4d \t", zout.avail_out);
+ fprintf(stderr, "ret: %2d \t", ret);
+ fprintf(stderr, "flag: %s\n", (flags & ZCOMP_COMP) ? "set" : "unset");
+ fprintf(stderr, "\n");
+#endif
+ comp_out +=3D (destlen - zout.avail_out);
+
+ if (ret =3D=3D Z_OK)
+ return (destlen - zout.avail_out);
+ else
+ return -1;
+}
+
+/*
+ * Decompress srclen bytes, starting at *src. Result is stored in *dest,
+ * a buffer of length destlen.
+ *
+ * Returns the amount of decompressed data. If this equals to the
+ * original destlen, decompress() must be called again with a new
+ * dest buffer. (src and srclen is ignored at next call)
+ */
+int ZCOMP::Decompress(char *src, int srclen, char *dest, int destlen)
+{
+ int ret =3D -1;
+#ifdef DECOMP_DEBUG
+ unsigned int i;
+#endif
+
+ if ((flags & ZCOMP_INIT) =3D=3D 0 && Init())
+ return -1;
+
+ if ((flags & ZCOMP_DECOMP) =3D=3D 0) {
+ zin.next_in =3D (unsigned char *) src;
+ zin.avail_in =3D srclen;
+ comp_in +=3D srclen;
+ }
+
+ zin.next_out =3D (unsigned char *) dest;
+ zin.avail_out =3D destlen;
+
+#ifdef DECOMP_DEBUG
+ fprintf(stderr, "avail_in: %4d \t", zin.avail_in);
+ fprintf(stderr, "avail_out: %4d \t", zin.avail_out);
+ fprintf(stderr, "ret: %2d \t", ret);
+ fprintf(stderr, "flag: %s\n", flags & ZCOMP_DECOMP ? "set" : "unset");
+#endif
+
+ ret =3D inflate(&zin, Z_SYNC_FLUSH);
+
+ if (zin.avail_in !=3D 0 && zin.avail_out !=3D 0) {
+ fprintf(stderr, "decompress: Did not consume all input but output buffer=
still has room? Panic!!!\n");
+ }
+
+ if (zin.avail_out =3D=3D 0)
+ flags |=3D ZCOMP_DECOMP;
+ else
+ flags &=3D ~ZCOMP_DECOMP;
+
+#ifdef DECOMP_DEBUG
+ fprintf(stderr, "avail_in: %4d \t", zin.avail_in);
+ fprintf(stderr, "avail_out: %4d \t", zin.avail_out);
+ fprintf(stderr, "ret: %2d \t", ret);
+ fprintf(stderr, "flag: %s\n", flags & ZCOMP_DECOMP ? "set" : "unset");
+ for (i =3D 0; i < destlen - zin.avail_out; i++)
+ fprintf(stderr, "%c", (dest[i] =3D=3D '\r') ? '\n' : dest[i]);
+ fprintf(stderr, "\n");
+#endif
+ raw_in +=3D (destlen - zin.avail_out);
+
+ if (ret =3D=3D Z_OK)
+ return (destlen - zin.avail_out);
+ else
+ return -1;
+}
+
+int ZCOMP::Init()
+{
+ int ret;
+
+ memset(&zin, 0, sizeof(zin));
+ memset(&zout, 0, sizeof(zout));
+
+ if ((ret =3D inflateInit(&zin)) !=3D Z_OK) {
+ fprintf(stderr, "ZCOMP: inflateInit failed (%d)\n", ret);
+ return ret;
+ }
+ if ((ret =3D deflateInit(&zout, Z_BEST_COMPRESSION)) !=3D Z_OK) {
+ fprintf(stderr, "ZCOMP: deflateInit failed (%d)\n", ret);
+ inflateEnd(&zin);
+ return ret;
+ }
+
+ raw_in =3D 0;
+ raw_out =3D 0;
+ comp_in =3D 0;
+ comp_out =3D 0;
+ flags =3D ZCOMP_INIT;
+
+ return 0;
+}
+
+void ZCOMP::End()
+{
+ if ((flags & ZCOMP_INIT) > 0) {
+ fprintf(stderr, "ZLib compression statistics:\n");
+ fprintf(stderr, "In: raw %6d compressed %6d (ratio: %.0f%%)\n", raw_i=
n, comp_in, (float) comp_in / raw_in * 100.0);
+ fprintf(stderr, "Out: raw %6d compressed %6d (ratio: %.0f%%)\n", raw_o=
ut, comp_out, (float) comp_out / raw_out * 100.0);
+ comp_out +=3D comp_in;
+ raw_out +=3D raw_in;
+ fprintf(stderr, "Total: raw %6d compressed %6d (ratio: %.0f%%)\n", raw_o=
ut, comp_out, (float) comp_out / raw_out * 100.0);
+
+ deflateEnd(&zout);
+ inflateEnd(&zin);
+ }
+
+ flags =3D 0;
+}
+
+ZCOMP::ZCOMP()
+{
+}
+
+ZCOMP::~ZCOMP()
+{
+ End();
+}
diff -ruN -X dontdiff linkt-0.6.99-20011124-CVS/linkt/zcomp.h linkt-0.6.99-=
20011124-CVS-bns/linkt/zcomp.h
--- linkt-0.6.99-20011124-CVS/linkt/zcomp.h Thu Jan 1 02:00:00 1970
+++ linkt-0.6.99-20011124-CVS-bns/linkt/zcomp.h Sat Feb 9 23:18:02 2002
@@ -0,0 +1,36 @@
+/*
+ * zcomp.h
+ */
+
+#ifndef ZCOMP_H
+#define ZCOMP_H
+
+#include <zlib.h>
+
+#define ZCOMP_INIT 1 /* Initialized flag. */
+#define ZCOMP_COMP 2 /* Call compressor again flag. */
+#define ZCOMP_DECOMP 4 /* Call decompressor again flag. */
+
+class ZCOMP
+{
+public:
+ ZCOMP();
+ ~ZCOMP();
+
+ int Init(void);
+ void End(void);
+
+ int Compress(char *src, int srclen, char *dest, int destlen);
+ int Decompress(char *src, int srclen, char *dest, int destlen);
+
+private:
+ z_stream zin;
+ z_stream zout;
+
+ unsigned int flags;
+
+ unsigned int raw_in, comp_in;
+ unsigned int raw_out, comp_out;
+};
+
+#endif // ZCOMP_H
|