projects
/
metaproxy-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
multi: allow backend-auth to be given for target element
[metaproxy-moved-to-github.git]
/
src
/
filter_frontend_net.cpp
diff --git
a/src/filter_frontend_net.cpp
b/src/filter_frontend_net.cpp
index
3839101
..
a3ab5f7
100644
(file)
--- a/
src/filter_frontend_net.cpp
+++ b/
src/filter_frontend_net.cpp
@@
-1,5
+1,5
@@
/* This file is part of Metaproxy.
/* This file is part of Metaproxy.
- Copyright (C) 2005-2008 Index Data
+ Copyright (C) 2005-2012 Index Data
Metaproxy is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Metaproxy is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
@@
-18,15
+18,19
@@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "config.hpp"
#include "config.hpp"
-#include "util.hpp"
+#include <sstream>
+#include <iomanip>
+#include <metaproxy/util.hpp>
#include "pipe.hpp"
#include "pipe.hpp"
-#include "filter.hpp"
-#include "package.hpp"
+#include <metaproxy/filter.hpp>
+#include <metaproxy/package.hpp>
#include "thread_pool_observer.hpp"
#include "filter_frontend_net.hpp"
#include <yazpp/z-assoc.h>
#include <yazpp/pdu-assoc.h>
#include <yazpp/socket-manager.h>
#include "thread_pool_observer.hpp"
#include "filter_frontend_net.hpp"
#include <yazpp/z-assoc.h>
#include <yazpp/pdu-assoc.h>
#include <yazpp/socket-manager.h>
+#include <yazpp/limit-connect.h>
+#include <yaz/timing.h>
#include <yaz/log.h>
#include <iostream>
#include <yaz/log.h>
#include <iostream>
@@
-37,14
+41,21
@@
namespace metaproxy_1 {
class My_Timer_Thread;
class ZAssocServer;
namespace filter {
class My_Timer_Thread;
class ZAssocServer;
namespace filter {
+ class FrontendNet::Port {
+ friend class Rep;
+ friend class FrontendNet;
+ std::string port;
+ std::string route;
+ };
class FrontendNet::Rep {
friend class FrontendNet;
int m_no_threads;
class FrontendNet::Rep {
friend class FrontendNet;
int m_no_threads;
- std::vector<std::string> m_ports;
+ std::vector<Port> m_ports;
int m_listen_duration;
int m_session_timeout;
int m_listen_duration;
int m_session_timeout;
+ int m_connect_max;
+ std::string m_msg_config;
yazpp_1::SocketManager mySocketManager;
yazpp_1::SocketManager mySocketManager;
-
ZAssocServer **az;
};
}
ZAssocServer **az;
};
}
@@
-62,9
+73,12
@@
namespace metaproxy_1 {
public:
~ZAssocChild();
ZAssocChild(yazpp_1::IPDU_Observable *the_PDU_Observable,
public:
~ZAssocChild();
ZAssocChild(yazpp_1::IPDU_Observable *the_PDU_Observable,
- mp::ThreadPoolSocketObserver *m_thread_pool_observer,
- const mp::Package *package);
+ mp::ThreadPoolSocketObserver *m_thread_pool_observer,
+ const mp::Package *package,
+ std::string route,
+ const char *msg_config);
int m_no_requests;
int m_no_requests;
+ std::string m_route;
private:
yazpp_1::IPDU_Observer* sessionNotify(
yazpp_1::IPDU_Observable *the_PDU_Observable,
private:
yazpp_1::IPDU_Observer* sessionNotify(
yazpp_1::IPDU_Observable *the_PDU_Observable,
@@
-80,24
+94,28
@@
namespace metaproxy_1 {
mp::Origin m_origin;
bool m_delete_flag;
const mp::Package *m_package;
mp::Origin m_origin;
bool m_delete_flag;
const mp::Package *m_package;
+ const char *m_msg_config;
};
class ThreadPoolPackage : public mp::IThreadPoolMsg {
public:
};
class ThreadPoolPackage : public mp::IThreadPoolMsg {
public:
- ThreadPoolPackage(mp::Package *package, mp::ZAssocChild *ses) :
- m_assoc_child(ses), m_package(package) { };
+ ThreadPoolPackage(mp::Package *package, mp::ZAssocChild *ses,
+ const char *msg_config);
~ThreadPoolPackage();
IThreadPoolMsg *handle();
~ThreadPoolPackage();
IThreadPoolMsg *handle();
- void result();
+ void result(const char *t_info);
private:
private:
+ yaz_timing_t timer;
mp::ZAssocChild *m_assoc_child;
mp::Package *m_package;
mp::ZAssocChild *m_assoc_child;
mp::Package *m_package;
-
+ const char *m_msg_config;
};
class ZAssocServer : public yazpp_1::Z_Assoc {
public:
~ZAssocServer();
};
class ZAssocServer : public yazpp_1::Z_Assoc {
public:
~ZAssocServer();
- ZAssocServer(yazpp_1::IPDU_Observable *PDU_Observable, int timeout);
+ ZAssocServer(yazpp_1::IPDU_Observable *PDU_Observable, int timeout,
+ int connect_max, std::string route,
+ const char *msg_config);
void set_package(const mp::Package *package);
void set_thread_pool(ThreadPoolSocketObserver *m_thread_pool_observer);
private:
void set_package(const mp::Package *package);
void set_thread_pool(ThreadPoolSocketObserver *m_thread_pool_observer);
private:
@@
-113,15
+131,31
@@
namespace metaproxy_1 {
mp::ThreadPoolSocketObserver *m_thread_pool_observer;
const mp::Package *m_package;
int m_session_timeout;
mp::ThreadPoolSocketObserver *m_thread_pool_observer;
const mp::Package *m_package;
int m_session_timeout;
+ int m_connect_max;
+ yazpp_1::LimitConnect limit_connect;
+ std::string m_route;
+ const char *m_msg_config;
};
}
};
}
+mp::ThreadPoolPackage::ThreadPoolPackage(mp::Package *package,
+ mp::ZAssocChild *ses,
+ const char *msg_config) :
+ m_assoc_child(ses), m_package(package), m_msg_config(msg_config)
+{
+ if (msg_config)
+ timer = yaz_timing_create();
+ else
+ timer = 0;
+}
+
mp::ThreadPoolPackage::~ThreadPoolPackage()
{
mp::ThreadPoolPackage::~ThreadPoolPackage()
{
+ yaz_timing_destroy(&timer); // timer may be NULL
delete m_package;
}
delete m_package;
}
-void mp::ThreadPoolPackage::result()
+void mp::ThreadPoolPackage::result(const char *t_info)
{
m_assoc_child->m_no_requests--;
{
m_assoc_child->m_no_requests--;
@@
-166,25
+200,42
@@
void mp::ThreadPoolPackage::result()
{
m_assoc_child->close();
}
{
m_assoc_child->close();
}
+
+ if (m_msg_config)
+ {
+ yaz_timing_stop(timer);
+ double duration = yaz_timing_get_real(timer);
+
+ std::ostringstream os;
+ os << m_msg_config << " "
+ << *m_package << " "
+ << std::fixed << std::setprecision (6) << duration;
+
+ yaz_log(YLOG_LOG, "%s %s", os.str().c_str(), t_info);
+ }
+
delete this;
}
mp::IThreadPoolMsg *mp::ThreadPoolPackage::handle()
{
delete this;
}
mp::IThreadPoolMsg *mp::ThreadPoolPackage::handle()
{
- m_package->move();
+ m_package->move(m_assoc_child->m_route);
return this;
}
mp::ZAssocChild::ZAssocChild(yazpp_1::IPDU_Observable *PDU_Observable,
return this;
}
mp::ZAssocChild::ZAssocChild(yazpp_1::IPDU_Observable *PDU_Observable,
- mp::ThreadPoolSocketObserver *my_thread_pool,
- const mp::Package *package)
- : Z_Assoc(PDU_Observable)
+ mp::ThreadPoolSocketObserver *my_thread_pool,
+ const mp::Package *package,
+ std::string route,
+ const char *msg_config)
+ : Z_Assoc(PDU_Observable), m_msg_config(msg_config)
{
m_thread_pool_observer = my_thread_pool;
m_no_requests = 0;
m_delete_flag = false;
m_package = package;
{
m_thread_pool_observer = my_thread_pool;
m_no_requests = 0;
m_delete_flag = false;
m_package = package;
+ m_route = route;
const char *peername = PDU_Observable->getpeername();
if (!peername)
peername = "unknown";
const char *peername = PDU_Observable->getpeername();
if (!peername)
peername = "unknown";
@@
-208,8
+259,9
@@
void mp::ZAssocChild::recv_GDU(Z_GDU *z_pdu, int len)
mp::Package *p = new mp::Package(m_session, m_origin);
mp::Package *p = new mp::Package(m_session, m_origin);
- mp::ThreadPoolPackage *tp = new mp::ThreadPoolPackage(p, this);
- p->copy_filter(*m_package);
+ mp::ThreadPoolPackage *tp = new mp::ThreadPoolPackage(p, this,
+ m_msg_config);
+ p->copy_route(*m_package);
p->request() = yazpp_1::GDU(z_pdu);
m_thread_pool_observer->put(tp);
}
p->request() = yazpp_1::GDU(z_pdu);
m_thread_pool_observer->put(tp);
}
@@
-229,8
+281,9
@@
void mp::ZAssocChild::failNotify()
mp::Package *p = new mp::Package(m_session, m_origin);
mp::Package *p = new mp::Package(m_session, m_origin);
- mp::ThreadPoolPackage *tp = new mp::ThreadPoolPackage(p, this);
- p->copy_filter(*m_package);
+ mp::ThreadPoolPackage *tp = new mp::ThreadPoolPackage(p, this,
+ m_msg_config);
+ p->copy_route(*m_package);
m_thread_pool_observer->put(tp);
}
m_thread_pool_observer->put(tp);
}
@@
-245,8
+298,10
@@
void mp::ZAssocChild::connectNotify()
}
mp::ZAssocServer::ZAssocServer(yazpp_1::IPDU_Observable *PDU_Observable,
}
mp::ZAssocServer::ZAssocServer(yazpp_1::IPDU_Observable *PDU_Observable,
- int timeout)
- : Z_Assoc(PDU_Observable), m_session_timeout(timeout)
+ int timeout, int connect_max,
+ std::string route, const char *msg_config)
+ : Z_Assoc(PDU_Observable), m_session_timeout(timeout),
+ m_connect_max(connect_max), m_route(route), m_msg_config(msg_config)
{
m_package = 0;
}
{
m_package = 0;
}
@@
-265,9
+320,19
@@
void mp::ZAssocServer::set_thread_pool(ThreadPoolSocketObserver *observer)
yazpp_1::IPDU_Observer *mp::ZAssocServer::sessionNotify(yazpp_1::IPDU_Observable
*the_PDU_Observable, int fd)
{
yazpp_1::IPDU_Observer *mp::ZAssocServer::sessionNotify(yazpp_1::IPDU_Observable
*the_PDU_Observable, int fd)
{
+
+ const char *peername = the_PDU_Observable->getpeername();
+ if (peername)
+ {
+ limit_connect.add_connect(peername);
+ limit_connect.cleanup(false);
+ int con_sz = limit_connect.get_total(peername);
+ if (m_connect_max && con_sz > m_connect_max)
+ return 0;
+ }
mp::ZAssocChild *my =
new mp::ZAssocChild(the_PDU_Observable, m_thread_pool_observer,
mp::ZAssocChild *my =
new mp::ZAssocChild(the_PDU_Observable, m_thread_pool_observer,
- m_package);
+ m_package, m_route, m_msg_config);
my->timeout(m_session_timeout);
return my;
}
my->timeout(m_session_timeout);
return my;
}
@@
-297,6
+362,7
@@
mp::filter::FrontendNet::FrontendNet() : m_p(new Rep)
m_p->m_no_threads = 5;
m_p->m_listen_duration = 0;
m_p->m_session_timeout = 300; // 5 minutes
m_p->m_no_threads = 5;
m_p->m_listen_duration = 0;
m_p->m_session_timeout = 300; // 5 minutes
+ m_p->m_connect_max = 0;
m_p->az = 0;
}
m_p->az = 0;
}
@@
-357,20
+423,28
@@
void mp::filter::FrontendNet::process(Package &package) const
delete tt;
}
delete tt;
}
-void mp::filter::FrontendNet::configure(const xmlNode * ptr, bool test_only)
+void mp::filter::FrontendNet::configure(const xmlNode * ptr, bool test_only,
+ const char *path)
{
if (!ptr || !ptr->children)
{
throw mp::filter::FilterException("No ports for Frontend");
}
{
if (!ptr || !ptr->children)
{
throw mp::filter::FilterException("No ports for Frontend");
}
- std::vector<std::string> ports;
+ std::vector<Port> ports;
for (ptr = ptr->children; ptr; ptr = ptr->next)
{
if (ptr->type != XML_ELEMENT_NODE)
continue;
if (!strcmp((const char *) ptr->name, "port"))
{
for (ptr = ptr->children; ptr; ptr = ptr->next)
{
if (ptr->type != XML_ELEMENT_NODE)
continue;
if (!strcmp((const char *) ptr->name, "port"))
{
- std::string port = mp::xml::get_text(ptr);
+ Port port;
+ const struct _xmlAttr *attr;
+ for (attr = ptr->properties; attr; attr = attr->next)
+ {
+ if (!strcmp((const char *) attr->name, "route"))
+ port.route = mp::xml::get_text(attr);
+ }
+ port.port = mp::xml::get_text(ptr);
ports.push_back(port);
}
ports.push_back(port);
}
@@
-392,6
+466,14
@@
void mp::filter::FrontendNet::configure(const xmlNode * ptr, bool test_only)
+ timeout_str);
m_p->m_session_timeout = timeout;
}
+ timeout_str);
m_p->m_session_timeout = timeout;
}
+ else if (!strcmp((const char *) ptr->name, "connect-max"))
+ {
+ m_p->m_connect_max = mp::xml::get_int(ptr, 0);
+ }
+ else if (!strcmp((const char *) ptr->name, "message"))
+ {
+ m_p->m_msg_config = mp::xml::get_text(ptr);
+ }
else
{
throw mp::filter::FilterException("Bad element "
else
{
throw mp::filter::FilterException("Bad element "
@@
-406,6
+488,23
@@
void mp::filter::FrontendNet::configure(const xmlNode * ptr, bool test_only)
void mp::filter::FrontendNet::set_ports(std::vector<std::string> &ports)
{
void mp::filter::FrontendNet::set_ports(std::vector<std::string> &ports)
{
+ std::vector<Port> nports;
+ size_t i;
+
+ for (i = 0; i < ports.size(); i++)
+ {
+ Port nport;
+
+ nport.port = ports[i];
+
+ nports.push_back(nport);
+ }
+ set_ports(nports);
+}
+
+
+void mp::filter::FrontendNet::set_ports(std::vector<Port> &ports)
+{
m_p->m_ports = ports;
m_p->az = new mp::ZAssocServer *[m_p->m_ports.size()];
m_p->m_ports = ports;
m_p->az = new mp::ZAssocServer *[m_p->m_ports.size()];
@@
-419,11
+518,15
@@
void mp::filter::FrontendNet::set_ports(std::vector<std::string> &ports)
// create ZAssoc with PDU Assoc
m_p->az[i] = new mp::ZAssocServer(as,
// create ZAssoc with PDU Assoc
m_p->az[i] = new mp::ZAssocServer(as,
- m_p->m_session_timeout);
- if (m_p->az[i]->server(m_p->m_ports[i].c_str()))
+ m_p->m_session_timeout,
+ m_p->m_connect_max,
+ m_p->m_ports[i].route,
+ m_p->m_msg_config.length() > 0 ?
+ m_p->m_msg_config.c_str() : 0);
+ if (m_p->az[i]->server(m_p->m_ports[i].port.c_str()))
{
throw mp::filter::FilterException("Unable to bind to address "
{
throw mp::filter::FilterException("Unable to bind to address "
- + std::string(m_p->m_ports[i]));
+ + std::string(m_p->m_ports[i].port));
}
}
}
}
}
}