Revert use of protobuf's Gzip streams.
Unfortunately some Red Hat-based distributions lack the required header. See https://bugzilla.redhat.com/show_bug.cgi?id=815587 This reverts commit261a389a76. This reverts commitb6736eb0a5.
This commit is contained in:
@@ -155,6 +155,8 @@ AS_IF([test x"$with_utempter" != xno],
|
|||||||
[AC_MSG_WARN([Unable to find libutempter; utmp entries will not be made.])],
|
[AC_MSG_WARN([Unable to find libutempter; utmp entries will not be made.])],
|
||||||
[AC_MSG_ERROR([--with-utempter was given but libutempter was not found.])])])])
|
[AC_MSG_ERROR([--with-utempter was given but libutempter was not found.])])])])
|
||||||
|
|
||||||
|
AC_SEARCH_LIBS([compress], [z], , [AC_MSG_ERROR([Unable to find zlib.])])
|
||||||
|
|
||||||
AC_ARG_WITH([skalibs],
|
AC_ARG_WITH([skalibs],
|
||||||
[AS_HELP_STRING([--with-skalibs[=DIR]],
|
[AS_HELP_STRING([--with-skalibs[=DIR]],
|
||||||
[root directory of skalibs installation])],
|
[root directory of skalibs installation])],
|
||||||
|
|||||||
@@ -3,4 +3,4 @@ AM_CXXFLAGS = $(WARNING_CXXFLAGS) $(PICKY_CXXFLAGS) $(HARDEN_CFLAGS) $(MISC_CXXF
|
|||||||
|
|
||||||
noinst_LIBRARIES = libmoshnetwork.a
|
noinst_LIBRARIES = libmoshnetwork.a
|
||||||
|
|
||||||
libmoshnetwork_a_SOURCES = network.cc network.h networktransport.cc networktransport.h transportfragment.cc transportfragment.h transportsender.cc transportsender.h transportstate.h
|
libmoshnetwork_a_SOURCES = network.cc network.h networktransport.cc networktransport.h transportfragment.cc transportfragment.h transportsender.cc transportsender.h transportstate.h compressor.cc compressor.h
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
#include <zlib.h>
|
||||||
|
|
||||||
|
#include "compressor.h"
|
||||||
|
#include "dos_assert.h"
|
||||||
|
|
||||||
|
using namespace Network;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
string Compressor::compress_str( const string &input )
|
||||||
|
{
|
||||||
|
long unsigned int len = BUFFER_SIZE;
|
||||||
|
dos_assert( Z_OK == compress( buffer, &len,
|
||||||
|
reinterpret_cast<const unsigned char *>( input.data() ),
|
||||||
|
input.size() ) );
|
||||||
|
return string( reinterpret_cast<char *>( buffer ), len );
|
||||||
|
}
|
||||||
|
|
||||||
|
string Compressor::uncompress_str( const string &input )
|
||||||
|
{
|
||||||
|
long unsigned int len = BUFFER_SIZE;
|
||||||
|
dos_assert( Z_OK == uncompress( buffer, &len,
|
||||||
|
reinterpret_cast<const unsigned char *>( input.data() ),
|
||||||
|
input.size() ) );
|
||||||
|
return string( reinterpret_cast<char *>( buffer ), len );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* construct on first use */
|
||||||
|
Compressor & Network::get_compressor( void )
|
||||||
|
{
|
||||||
|
static Compressor the_compressor;
|
||||||
|
return the_compressor;
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
#ifndef COMPRESSOR_H
|
||||||
|
#define COMPRESSOR_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace Network {
|
||||||
|
class Compressor {
|
||||||
|
private:
|
||||||
|
static const int BUFFER_SIZE = 2048 * 2048; /* effective limit on terminal size */
|
||||||
|
|
||||||
|
unsigned char *buffer;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Compressor() : buffer( NULL ) { buffer = new unsigned char[ BUFFER_SIZE ]; }
|
||||||
|
~Compressor() { if ( buffer ) { delete[] buffer; } }
|
||||||
|
|
||||||
|
std::string compress_str( const std::string &input );
|
||||||
|
std::string uncompress_str( const std::string &input );
|
||||||
|
|
||||||
|
/* unused */
|
||||||
|
Compressor( const Compressor & );
|
||||||
|
Compressor & operator=( const Compressor & );
|
||||||
|
};
|
||||||
|
|
||||||
|
Compressor & get_compressor( void );
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -17,15 +17,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <google/protobuf/io/gzip_stream.h>
|
|
||||||
#include <google/protobuf/io/zero_copy_stream_impl.h>
|
|
||||||
|
|
||||||
#include "byteorder.h"
|
#include "byteorder.h"
|
||||||
#include "transportfragment.h"
|
#include "transportfragment.h"
|
||||||
#include "transportinstruction.pb.h"
|
#include "transportinstruction.pb.h"
|
||||||
|
#include "compressor.h"
|
||||||
#include "fatal_assert.h"
|
#include "fatal_assert.h"
|
||||||
|
|
||||||
using namespace google::protobuf::io;
|
|
||||||
using namespace Network;
|
using namespace Network;
|
||||||
using namespace TransportBuffers;
|
using namespace TransportBuffers;
|
||||||
|
|
||||||
@@ -117,24 +115,15 @@ Instruction FragmentAssembly::get_assembly( void )
|
|||||||
{
|
{
|
||||||
assert( fragments_arrived == fragments_total );
|
assert( fragments_arrived == fragments_total );
|
||||||
|
|
||||||
ZeroCopyInputStream **streams = new ZeroCopyInputStream *[fragments_total];
|
string encoded;
|
||||||
|
|
||||||
for ( int i = 0; i < fragments_total; i++ ) {
|
for ( int i = 0; i < fragments_total; i++ ) {
|
||||||
assert( fragments.at( i ).initialized );
|
assert( fragments.at( i ).initialized );
|
||||||
streams[i] = new ArrayInputStream( fragments.at( i ).contents.data(),
|
encoded += fragments.at( i ).contents;
|
||||||
fragments.at( i ).contents.size() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Instruction ret;
|
Instruction ret;
|
||||||
{
|
fatal_assert( ret.ParseFromString( get_compressor().uncompress_str( encoded ) ) );
|
||||||
ConcatenatingInputStream stream( streams, fragments_total );
|
|
||||||
GzipInputStream gzip_stream( &stream, GzipInputStream::ZLIB );
|
|
||||||
fatal_assert( ret.ParseFromZeroCopyStream( &gzip_stream ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( int i = 0; i < fragments_total; i++ ) {
|
|
||||||
delete streams[i];
|
|
||||||
}
|
|
||||||
delete[] streams;
|
|
||||||
|
|
||||||
fragments.clear();
|
fragments.clear();
|
||||||
fragments_arrived = 0;
|
fragments_arrived = 0;
|
||||||
@@ -169,18 +158,7 @@ vector<Fragment> Fragmenter::make_fragments( const Instruction &inst, int MTU )
|
|||||||
last_instruction = inst;
|
last_instruction = inst;
|
||||||
last_MTU = MTU;
|
last_MTU = MTU;
|
||||||
|
|
||||||
string payload;
|
string payload = get_compressor().compress_str( inst.SerializeAsString() );
|
||||||
{
|
|
||||||
StringOutputStream stream( &payload );
|
|
||||||
GzipOutputStream::Options gzip_options;
|
|
||||||
gzip_options.format = GzipOutputStream::ZLIB;
|
|
||||||
GzipOutputStream gzip_stream( &stream, gzip_options );
|
|
||||||
fatal_assert( inst.SerializeToZeroCopyStream( &gzip_stream ) );
|
|
||||||
if ( !gzip_stream.Close() ) {
|
|
||||||
throw std::string( "zlib error: " ) + gzip_stream.ZlibErrorMessage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t fragment_num = 0;
|
uint16_t fragment_num = 0;
|
||||||
vector<Fragment> ret;
|
vector<Fragment> ret;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user