<?xml version="1.0"?>
-<!-- $Id: config.xml,v 1.18 2006-04-06 12:04:19 adam Exp $ -->
+<!-- $Id: config.xml,v 1.19 2006-04-06 16:25:20 adam Exp $ -->
<proxy xmlns="http://indexdata.dk/yazproxy/schema/0.9/"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
</target>
<max-clients>30</max-clients>
<max-connect>10</max-connect>
+ <period-connect>10</period-connect>
<limit-connect>5</limit-connect>
<log>client-requests server-requests client-ip</log>
<docpath>doc</docpath>
-/* $Id: limit-connect.h,v 1.2 2006-03-30 14:16:34 adam Exp $
+/* $Id: limit-connect.h,v 1.3 2006-04-06 16:25:21 adam Exp $
Copyright (c) 1998-2006, Index Data.
This file is part of the yazproxy.
void add_connect(const char *peername);
int get_total(const char *peername);
void cleanup(bool all);
+ void set_period(int sec);
private:
struct Peer;
-/* $Id: proxy.h,v 1.31 2006-04-06 12:04:19 adam Exp $
+/* $Id: proxy.h,v 1.32 2006-04-06 16:25:21 adam Exp $
Copyright (c) 1998-2006, Index Data.
This file is part of the yazproxy.
} m_timeout_mode;
int m_initial_reduce;
- int m_connect_max;
+ int m_max_connect;
+ int m_max_connect_period;
int m_limit_connect;
+ int m_limit_connect_period;
int m_search_max;
Yaz_bw m_bw_stat;
int m_pdu_max;
-/* $Id: limit-connect.cpp,v 1.1 2006-03-30 10:35:15 adam Exp $
+/* $Id: limit-connect.cpp,v 1.2 2006-04-06 16:25:21 adam Exp $
Copyright (c) 1998-2006, Index Data.
This file is part of the yazproxy.
m_peers = 0;
}
+
LimitConnect::~LimitConnect()
{
cleanup(true);
}
+void LimitConnect::set_period(int sec)
+{
+ m_period = sec;
+}
+
LimitConnect::Peer::Peer(int sz, const char *peername) : m_bw(sz)
{
m_peername = xstrdup(peername);
-/* $Id: proxyp.h,v 1.15 2006-04-06 01:16:55 adam Exp $
+/* $Id: proxyp.h,v 1.16 2006-04-06 16:25:21 adam Exp $
Copyright (c) 1998-2006, Index Data.
This file is part of the yazproxy.
const char **default_client_query_charset);
void get_generic_info(int *log_mask, int *max_clients,
- int *max_connect, int *limit_connect);
+ int *max_connect, int *limit_connect,
+ int *period_connect);
int get_file_access_info(const char *path);
-/* $Id: yaz-proxy-config.cpp,v 1.29 2006-04-06 12:04:19 adam Exp $
+/* $Id: yaz-proxy-config.cpp,v 1.30 2006-04-06 16:25:21 adam Exp $
Copyright (c) 1998-2006, Index Data.
This file is part of the yazproxy.
xmlNodePtr find_target_node(const char *name, const char *db);
xmlNodePtr find_target_db(xmlNodePtr ptr, const char *db);
const char *get_text(xmlNodePtr ptr);
+ void get_period(xmlNodePtr ptr, int *period);
int check_type_1_attributes(ODR odr, xmlNodePtr ptr,
Z_AttributeList *attrs,
char **addinfo);
}
return 0;
}
+
+void Yaz_ProxyConfigP::get_period(xmlNodePtr ptr, int *period)
+{
+ struct _xmlAttr *attr;
+ *period = 60;
+ for (attr = ptr->properties; attr; attr = attr->next)
+ {
+ if (!strcmp((const char *) attr->name, "period") &&
+ attr->children && attr->children->type == XML_TEXT_NODE)
+ *period = atoi((const char *) attr->children->content);
+ }
+}
#endif
#if HAVE_XSLT
void Yaz_ProxyConfig::get_generic_info(int *log_mask,
int *max_clients,
int *max_connect,
- int *limit_connect)
+ int *limit_connect,
+ int *period_connect)
{
*max_connect = 0;
*limit_connect = 0;
}
}
else if (ptr->type == XML_ELEMENT_NODE &&
+ !strcmp((const char *) ptr->name, "period-connect"))
+ {
+ const char *t = m_cp->get_text(ptr);
+ if (t)
+ *period_connect = atoi(t);
+ }
+ else if (ptr->type == XML_ELEMENT_NODE &&
!strcmp((const char *) ptr->name, "max-connect"))
{
const char *t = m_cp->get_text(ptr);
if (t)
+ {
*max_connect = atoi(t);
+ }
}
else if (ptr->type == XML_ELEMENT_NODE &&
!strcmp((const char *) ptr->name, "limit-connect"))
{
const char *t = m_cp->get_text(ptr);
if (t)
+ {
*limit_connect = atoi(t);
+ }
}
else if (ptr->type == XML_ELEMENT_NODE &&
!strcmp((const char *) ptr->name, "target"))
-/* $Id: yaz-proxy.cpp,v 1.50 2006-04-06 12:04:20 adam Exp $
+/* $Id: yaz-proxy.cpp,v 1.51 2006-04-06 16:25:21 adam Exp $
Copyright (c) 1998-2006, Index Data.
This file is part of the yazproxy.
m_bw_max = 0;
m_pdu_max = 0;
m_search_max = 0;
- m_connect_max = 0;
+ m_max_connect = 0;
+ m_max_connect_period = 0;
m_limit_connect = 0;
+ m_limit_connect_period = 0;
m_timeout_mode = timeout_normal;
m_timeout_gdu = 0;
m_max_record_retrieve = 0;
m_config_fname = xstrdup(config);
int r = m_config->read_xml(config);
if (!r)
+ {
+ int period = 60;
m_config->get_generic_info(&m_log_mask, &m_max_clients,
- &m_connect_max, &m_limit_connect);
+ &m_max_connect, &m_limit_connect, &period);
+ m_connect.set_period(period);
+ }
return r;
}
else
{
m_log_mask = 0;
+ int period = 60;
cfg->get_generic_info(&m_log_mask, &m_max_clients,
- &m_connect_max, &m_limit_connect);
+ &m_max_connect, &m_limit_connect,
+ &period);
+ m_connect.set_period(period);
}
}
else
m_connect.add_connect(peername);
int connect_total = m_connect.get_total(peername);
- int connect_max = m_connect_max;
+ int connect_max = m_max_connect;
if (connect_max && connect_total > connect_max)
{
yaz_log(YLOG_LOG, "%sconnect not accepted total=%d max=%d",