version 3.02
This commit is contained in:
parent
7adaaf99be
commit
bc32a3a706
25 changed files with 287 additions and 99 deletions
|
|
@ -29,6 +29,7 @@
|
|||
#include <ssh/ssh_filter.h>
|
||||
#include <xcodec/xcodec_filter.h>
|
||||
#include <zlib/zlib_filter.h>
|
||||
#include <common/count_filter.h>
|
||||
#include "proxy_connector.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -37,19 +38,19 @@
|
|||
// Description: carries data between endpoints through a filter chain //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2015-08-31 //
|
||||
// Last modified: 2016-02-28 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ProxyConnector::ProxyConnector (const std::string& name,
|
||||
WANProxyCodec* interface_codec,
|
||||
WANProxyCodec* local_codec,
|
||||
WANProxyCodec* remote_codec,
|
||||
Socket* local_socket,
|
||||
SocketAddressFamily family,
|
||||
const std::string& remote_name,
|
||||
bool cln, bool ssh)
|
||||
: log_("/wanproxy/" + name + "/connector"),
|
||||
interface_codec_(interface_codec),
|
||||
local_codec_(local_codec),
|
||||
remote_codec_(remote_codec),
|
||||
local_socket_(local_socket),
|
||||
remote_socket_(0),
|
||||
|
|
@ -61,7 +62,8 @@ ProxyConnector::ProxyConnector (const std::string& name,
|
|||
stop_action_(0),
|
||||
request_action_(0),
|
||||
response_action_(0),
|
||||
chain_ready_(0)
|
||||
close_action_(0),
|
||||
flushing_(0)
|
||||
{
|
||||
if (local_socket_ && (remote_socket_ = Socket::create (family, SocketTypeStream, "tcp", remote_name)))
|
||||
{
|
||||
|
|
@ -70,7 +72,7 @@ ProxyConnector::ProxyConnector (const std::string& name,
|
|||
}
|
||||
else
|
||||
{
|
||||
conclude ();
|
||||
close_action_ = event_system.track (0, StreamModeWait, callback (this, &ProxyConnector::conclude));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -84,6 +86,8 @@ ProxyConnector::~ProxyConnector ()
|
|||
request_action_->cancel ();
|
||||
if (response_action_)
|
||||
response_action_->cancel ();
|
||||
if (close_action_)
|
||||
close_action_->cancel ();
|
||||
if (local_socket_)
|
||||
local_socket_->close ();
|
||||
if (remote_socket_)
|
||||
|
|
@ -103,15 +107,15 @@ void ProxyConnector::connect_complete (Event e)
|
|||
break;
|
||||
case Event::Error:
|
||||
INFO(log_) << "Connect failed: " << e;
|
||||
conclude ();
|
||||
conclude (e);
|
||||
return;
|
||||
default:
|
||||
ERROR(log_) << "Unexpected event: " << e;
|
||||
conclude ();
|
||||
conclude (e);
|
||||
return;
|
||||
}
|
||||
|
||||
if (build_chains (interface_codec_, remote_codec_, local_socket_, remote_socket_))
|
||||
if (build_chains (local_codec_, remote_codec_, local_socket_, remote_socket_))
|
||||
{
|
||||
request_action_ = local_socket_->read (callback (this, &ProxyConnector::on_request_data));
|
||||
response_action_ = remote_socket_->read (callback (this, &ProxyConnector::on_response_data));
|
||||
|
|
@ -158,7 +162,7 @@ bool ProxyConnector::build_chains (WANProxyCodec* cdc1, WANProxyCodec* cdc2, Soc
|
|||
if (cdc1->counting_)
|
||||
{
|
||||
request_chain_.append (new CountFilter (cdc1->request_output_bytes_));
|
||||
response_chain_.prepend (new CountFilter (cdc1->response_input_bytes_));
|
||||
response_chain_.prepend (new CountFilter (cdc1->response_input_bytes_, 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -208,6 +212,8 @@ void ProxyConnector::on_request_data (Event e)
|
|||
{
|
||||
if (request_action_)
|
||||
request_action_->cancel (), request_action_ = 0;
|
||||
if (flushing_ & REQUEST_CHAIN_FLUSHING)
|
||||
return;
|
||||
|
||||
switch (e.type_)
|
||||
{
|
||||
|
|
@ -217,11 +223,12 @@ void ProxyConnector::on_request_data (Event e)
|
|||
break;
|
||||
case Event::EOS:
|
||||
DEBUG(log_) << "Flushing request";
|
||||
flushing_ |= REQUEST_CHAIN_FLUSHING;
|
||||
request_chain_.flush (REQUEST_CHAIN_READY);
|
||||
break;
|
||||
default:
|
||||
DEBUG(log_) << "Unexpected event: " << e;
|
||||
conclude ();
|
||||
conclude (e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -230,6 +237,8 @@ void ProxyConnector::on_response_data (Event e)
|
|||
{
|
||||
if (response_action_)
|
||||
response_action_->cancel (), response_action_ = 0;
|
||||
if (flushing_ & RESPONSE_CHAIN_FLUSHING)
|
||||
return;
|
||||
|
||||
switch (e.type_)
|
||||
{
|
||||
|
|
@ -239,23 +248,25 @@ void ProxyConnector::on_response_data (Event e)
|
|||
break;
|
||||
case Event::EOS:
|
||||
DEBUG(log_) << "Flushing response";
|
||||
flushing_ |= RESPONSE_CHAIN_FLUSHING;
|
||||
response_chain_.flush (RESPONSE_CHAIN_READY);
|
||||
break;
|
||||
default:
|
||||
DEBUG(log_) << "Unexpected event: " << e;
|
||||
conclude ();
|
||||
conclude (e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void ProxyConnector::flush (int flg)
|
||||
{
|
||||
chain_ready_ |= flg;
|
||||
if ((chain_ready_ & REQUEST_CHAIN_READY) && (chain_ready_ & RESPONSE_CHAIN_READY))
|
||||
conclude ();
|
||||
flushing_ |= flg;
|
||||
if ((flushing_ & (REQUEST_CHAIN_READY | RESPONSE_CHAIN_READY)) == (REQUEST_CHAIN_READY | RESPONSE_CHAIN_READY))
|
||||
if (! close_action_)
|
||||
close_action_ = event_system.track (0, StreamModeWait, callback (this, &ProxyConnector::conclude));
|
||||
}
|
||||
|
||||
void ProxyConnector::conclude ()
|
||||
void ProxyConnector::conclude (Event e)
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,8 +26,10 @@
|
|||
#ifndef PROGRAMS_WANPROXY_PROXY_CONNECTOR_H
|
||||
#define PROGRAMS_WANPROXY_PROXY_CONNECTOR_H
|
||||
|
||||
#define REQUEST_CHAIN_READY 0x10000
|
||||
#define RESPONSE_CHAIN_READY 0x20000
|
||||
#define REQUEST_CHAIN_FLUSHING 0x10000
|
||||
#define RESPONSE_CHAIN_FLUSHING 0x20000
|
||||
#define REQUEST_CHAIN_READY 0x40000
|
||||
#define RESPONSE_CHAIN_READY 0x80000
|
||||
|
||||
#include <common/filter.h>
|
||||
#include <event/action.h>
|
||||
|
|
@ -41,14 +43,14 @@
|
|||
// Description: carries data between endpoints through a filter chain //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2015-08-31 //
|
||||
// Last modified: 2016-02-28 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ProxyConnector : public Filter
|
||||
{
|
||||
LogHandle log_;
|
||||
WANProxyCodec* interface_codec_;
|
||||
WANProxyCodec* local_codec_;
|
||||
WANProxyCodec* remote_codec_;
|
||||
Socket* local_socket_;
|
||||
Socket* remote_socket_;
|
||||
|
|
@ -59,7 +61,8 @@ class ProxyConnector : public Filter
|
|||
Action* stop_action_;
|
||||
Action* request_action_;
|
||||
Action* response_action_;
|
||||
int chain_ready_;
|
||||
Action* close_action_;
|
||||
int flushing_;
|
||||
|
||||
public:
|
||||
ProxyConnector (const std::string&, WANProxyCodec*, WANProxyCodec*,
|
||||
|
|
@ -71,7 +74,7 @@ public:
|
|||
void on_request_data (Event e);
|
||||
void on_response_data (Event e);
|
||||
virtual void flush (int flg);
|
||||
void conclude ();
|
||||
void conclude (Event e);
|
||||
};
|
||||
|
||||
#endif /* !PROGRAMS_WANPROXY_PROXY_CONNECTOR_H */
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
// Description: listens on a port spawning a connector for each client //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2015-08-31 //
|
||||
// Last modified: 2016-02-28 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ ProxyListener::ProxyListener (const std::string& name,
|
|||
SocketAddressFamily remote_family,
|
||||
const std::string& remote_address,
|
||||
bool cln, bool ssh)
|
||||
: log_("/wanproxy/proxy/" + name + "/listener"),
|
||||
: log_("/wanproxy/" + name + "/listener"),
|
||||
name_(name),
|
||||
local_codec_(local_codec),
|
||||
remote_codec_(remote_codec),
|
||||
|
|
|
|||
|
|
@ -34,11 +34,11 @@
|
|||
// Description: session start and global application management //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2015-08-31 //
|
||||
// Last modified: 2016-02-28 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define PROGRAM_VERSION "3.0"
|
||||
#define PROGRAM_VERSION "3.02"
|
||||
|
||||
WanProxyCore wanproxy;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
// Description: global data for the wanproxy application //
|
||||
// Project: WANProxy XTech //
|
||||
// Author: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2015-08-31 //
|
||||
// Last modified: 2016-02-28 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
|
@ -109,10 +109,31 @@ public:
|
|||
if (reload_action_)
|
||||
reload_action_->cancel (), reload_action_ = 0;
|
||||
delete listener_; listener_ = 0;
|
||||
print_stream_counts ();
|
||||
std::map<UUID, XCodecCache*>::iterator it;
|
||||
for (it = caches_.begin(); it != caches_.end(); it++)
|
||||
delete it->second;
|
||||
caches_.clear ();
|
||||
|
||||
}
|
||||
|
||||
void print_stream_counts ()
|
||||
{
|
||||
if (local_codec_.counting_)
|
||||
{
|
||||
INFO("wanproxy/core") << "Local codec request input bytes: " << local_codec_.request_input_bytes_;
|
||||
INFO("wanproxy/core") << "Local codec request output bytes: " << local_codec_.request_output_bytes_;
|
||||
INFO("wanproxy/core") << "Local codec response input bytes: " << local_codec_.response_input_bytes_;
|
||||
INFO("wanproxy/core") << "Local codec response output bytes: " << local_codec_.response_output_bytes_;
|
||||
}
|
||||
|
||||
if (remote_codec_.counting_)
|
||||
{
|
||||
INFO("wanproxy/core") << "Remote codec request input bytes: " << remote_codec_.request_input_bytes_;
|
||||
INFO("wanproxy/core") << "Remote codec request output bytes: " << remote_codec_.request_output_bytes_;
|
||||
INFO("wanproxy/core") << "Remote codec response input bytes: " << remote_codec_.response_input_bytes_;
|
||||
INFO("wanproxy/core") << "Remote codec response output bytes: " << remote_codec_.response_output_bytes_;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue