metaproxy  1.21.0
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
metaproxy_1::filter::FrontendNet::ZAssocChild Class Reference
Inheritance diagram for metaproxy_1::filter::FrontendNet::ZAssocChild:
Inheritance graph
Collaboration diagram for metaproxy_1::filter::FrontendNet::ZAssocChild:
Collaboration graph

Public Member Functions

 ~ZAssocChild ()
 
 ZAssocChild (yazpp_1::IPDU_Observable *the_PDU_Observable, mp::ThreadPoolSocketObserver *m_thread_pool_observer, const mp::Package *package, Port *port, Rep *rep, yazpp_1::LimitConnect &limit, const char *peername)
 

Public Attributes

int m_no_requests
 
Portm_port
 

Private Member Functions

yazpp_1::IPDU_Observer * sessionNotify (yazpp_1::IPDU_Observable *the_PDU_Observable, int fd)
 
void recv_GDU (Z_GDU *apdu, int len)
 
void report (Z_HTTP_Request *hreq)
 
void failNotify ()
 
void timeoutNotify ()
 
void connectNotify ()
 

Private Attributes

mp::ThreadPoolSocketObserverm_thread_pool_observer
 
mp::Session m_session
 
mp::Origin m_origin
 
bool m_delete_flag
 
const mp::Package * m_package
 
Repm_p
 
yazpp_1::LimitConnect & m_limit_http_req
 
std::string m_peer
 

Detailed Description

Definition at line 118 of file filter_frontend_net.cpp.

Constructor & Destructor Documentation

◆ ~ZAssocChild()

mp::filter::FrontendNet::ZAssocChild::~ZAssocChild ( )

Definition at line 350 of file filter_frontend_net.cpp.

351 {
352  int d = m_p->m_peerStat.remove(m_peer);
353  if (m_p->m_msg_config.length())
354  {
355  std::ostringstream os;
356  os << m_p->m_msg_config << " "
357  << m_peer << " closing cnt=" << d;
358  yaz_log(YLOG_LOG, "%s", os.str().c_str());
359  }
360 }

References metaproxy_1::filter::FrontendNet::m_p.

◆ ZAssocChild()

mp::filter::FrontendNet::ZAssocChild::ZAssocChild ( yazpp_1::IPDU_Observable *  the_PDU_Observable,
mp::ThreadPoolSocketObserver m_thread_pool_observer,
const mp::Package *  package,
Port port,
Rep rep,
yazpp_1::LimitConnect &  limit,
const char *  peername 
)

Definition at line 306 of file filter_frontend_net.cpp.

313  : Z_Assoc(PDU_Observable), m_p(rep), m_limit_http_req(limit_http_req)
314  , m_peer(peername)
315 {
316  m_thread_pool_observer = my_thread_pool;
317  m_no_requests = 0;
318  m_delete_flag = false;
319  m_package = package;
320  m_port = port;
321  std::string addr;
322  addr.append(peername);
323  addr.append(" ");
324  addr.append(port->port);
326  m_origin.set_tcpip_address(addr, m_session.id());
327  int session_timeout = 300; // 5 minutes
328  if (peername) {
329  std::list<IP_Pattern>::const_iterator it = m_p->session_timeout.begin();
330  for (; it != m_p->session_timeout.end(); it++)
331  if (mp::util::match_ip(it->pattern, peername))
332  {
333  if (it->verbose > 1)
334  yaz_log(YLOG_LOG, "timeout pattern=%s ip=%s value=%d",
335  it->pattern.c_str(),
336  peername, it->value);
337  session_timeout = it->value;
338  break;
339  }
340  }
341  timeout(session_timeout);
342 }
mp::ThreadPoolSocketObserver * m_thread_pool_observer

References metaproxy_1::filter::FrontendNet::PeerStat::add(), m_delete_flag, m_no_requests, m_origin, m_p, m_package, m_peer, metaproxy_1::filter::FrontendNet::Rep::m_peerStat, m_port, m_session, m_thread_pool_observer, metaproxy_1::filter::FrontendNet::Port::port, and metaproxy_1::filter::FrontendNet::Rep::session_timeout.

Here is the call graph for this function:

Member Function Documentation

◆ connectNotify()

void mp::filter::FrontendNet::ZAssocChild::connectNotify ( )
private

Definition at line 531 of file filter_frontend_net.cpp.

532 {
533 
534 }

◆ failNotify()

void mp::filter::FrontendNet::ZAssocChild::failNotify ( )
private

Definition at line 505 of file filter_frontend_net.cpp.

506 {
507  // TODO: send Package to signal "close"
508  if (m_session.is_closed())
509  {
510  if (m_no_requests == 0)
511  delete this;
512  return;
513  }
514  m_no_requests++;
515 
516  m_session.close();
517 
518  mp::Package *p = new mp::Package(m_session, m_origin);
519 
520  ThreadPoolPackage *tp = new ThreadPoolPackage(p, this, m_p);
521  p->copy_route(*m_package);
524 }
void cleanup(IThreadPoolMsg *m, void *info)

References metaproxy_1::filter::FrontendNet::m_p.

◆ recv_GDU()

void mp::filter::FrontendNet::ZAssocChild::recv_GDU ( Z_GDU *  apdu,
int  len 
)
private

Definition at line 434 of file filter_frontend_net.cpp.

435 {
436  m_no_requests++;
437 
438  mp::Package *p = new mp::Package(m_session, m_origin);
439 
440  if (z_pdu && z_pdu->which == Z_GDU_HTTP_Request)
441  {
442  Z_HTTP_Request *hreq = z_pdu->u.HTTP_Request;
443 
444  const char *f = z_HTTP_header_lookup(hreq->headers, "X-Forwarded-For");
445  if (f)
446  p->origin().set_tcpip_address(std::string(f), m_session.id());
447 
448  if (m_p->m_stat_req.length()
449  && !strcmp(hreq->path, m_p->m_stat_req.c_str()))
450  {
451  report(hreq);
452  delete p;
453  delete this;
454  return;
455  }
456  }
457 
458  p->copy_route(*m_package);
459  p->request() = yazpp_1::GDU(z_pdu);
460 
461  if (m_p->m_msg_config.length())
462  {
463  if (z_pdu)
464  {
465  std::ostringstream os;
466  os << m_p->m_msg_config << " "
467  << *p << " "
468  << "0.000000" << " "
469  << *z_pdu;
470  yaz_log(YLOG_LOG, "%s", os.str().c_str());
471  }
472  }
473  if (z_pdu && z_pdu->which == Z_GDU_HTTP_Request)
474  {
475  Z_HTTP_Request *hreq = z_pdu->u.HTTP_Request;
476  std::string peername = p->origin().get_address();
477 
478  m_limit_http_req.cleanup(false);
479  int con_sz = m_limit_http_req.get_total(peername.c_str());
480  std::list<IP_Pattern>::const_iterator it = m_p->http_req_max.begin();
481  for (; it != m_p->http_req_max.end(); it++)
482  {
483  if (mp::util::match_ip(it->pattern, peername))
484  {
485  if (it->verbose > 1 ||
486  (it->value && con_sz >= it->value && it->verbose > 0))
487  yaz_log(YLOG_LOG, "http-req-max pattern=%s ip=%s con_sz=%d value=%d", it->pattern.c_str(), peername.c_str(), con_sz, it->value);
488  if (con_sz < it->value)
489  break;
490  mp::odr o;
491  Z_GDU *gdu_res = o.create_HTTP_Response(m_session, hreq, 500);
492  int len;
493  send_GDU(gdu_res, &len);
494  delete p;
495  delete this;
496  return;
497  }
498  }
499  m_limit_http_req.add_connect(peername.c_str());
500  }
501  ThreadPoolPackage *tp = new ThreadPoolPackage(p, this, m_p);
503 }

References metaproxy_1::filter::FrontendNet::m_p.

◆ report()

void mp::filter::FrontendNet::ZAssocChild::report ( Z_HTTP_Request *  hreq)
private

Definition at line 362 of file filter_frontend_net.cpp.

363 {
364  mp::odr o;
365 
366  Z_GDU *gdu_res = o.create_HTTP_Response(m_session, hreq, 200);
367 
368  Z_HTTP_Response *hres = gdu_res->u.HTTP_Response;
369 
370  mp::wrbuf w;
371  size_t i;
372  int number_total = 0;
373 
374  for (i = 0; m_p->m_duration_lim[i] != 0.0; i++)
375  number_total += m_p->m_duration_freq[i];
376  number_total += m_p->m_duration_freq[i];
377 
378  wrbuf_puts(w, "<?xml version=\"1.0\"?>\n");
379  wrbuf_puts(w, "<frontend_net>\n");
380  wrbuf_printf(w, " <responses frequency=\"%d\">\n", number_total);
381  for (i = 0; m_p->m_duration_lim[i] != 0.0; i++)
382  {
383  if (m_p->m_duration_freq[i] > 0)
384  wrbuf_printf(
385  w, " <response duration_start=\"%f\" "
386  "duration_end=\"%f\" frequency=\"%d\"/>\n",
387  i > 0 ? m_p->m_duration_lim[i - 1] : 0.0,
389  }
390 
391  if (m_p->m_duration_freq[i] > 0)
392  wrbuf_printf(
393  w, " <response duration_start=\"%f\" frequency=\"%d\"/>\n",
394  m_p->m_duration_lim[i - 1], m_p->m_duration_freq[i]);
395 
396  if (m_p->m_duration_max != 0.0)
397  wrbuf_printf(
398  w, " <response duration_max=\"%f\"/>\n",
400  if (m_p->m_duration_min != 0.0)
401  wrbuf_printf(
402  w, " <response duration_min=\"%f\"/>\n",
404  if (m_p->m_duration_total != 0.0)
405  wrbuf_printf(
406  w, " <response duration_average=\"%f\"/>\n",
407  m_p->m_duration_total / number_total);
408 
409  wrbuf_puts(w, " </responses>\n");
410 
411  int thread_busy;
412  int thread_total;
413  m_thread_pool_observer->get_thread_info(thread_busy, thread_total);
414 
415  wrbuf_printf(w, " <thread_info busy=\"%d\" total=\"%d\"/>\n",
416  thread_busy, thread_total);
417 
418  wrbuf_malloc_info(w);
419 
420  {
421  char buf[200];
422  if (nmem_get_status(buf, sizeof(buf) - 1) == 0)
423  wrbuf_puts(w, buf);
424  }
425  wrbuf_puts(w, "</frontend_net>\n");
426 
427  hres->content_len = w.len();
428  hres->content_buf = (char *) w.buf();
429 
430  int len;
431  send_GDU(gdu_res, &len);
432 }
void get_thread_info(int &tbusy, int &total)

References metaproxy_1::filter::FrontendNet::m_p.

◆ sessionNotify()

yazpp_1::IPDU_Observer * mp::filter::FrontendNet::ZAssocChild::sessionNotify ( yazpp_1::IPDU_Observable *  the_PDU_Observable,
int  fd 
)
private

Definition at line 344 of file filter_frontend_net.cpp.

346 {
347  return 0;
348 }

◆ timeoutNotify()

void mp::filter::FrontendNet::ZAssocChild::timeoutNotify ( )
private

Definition at line 526 of file filter_frontend_net.cpp.

Member Data Documentation

◆ m_delete_flag

bool metaproxy_1::filter::FrontendNet::ZAssocChild::m_delete_flag
private

Definition at line 143 of file filter_frontend_net.cpp.

Referenced by ZAssocChild().

◆ m_limit_http_req

yazpp_1::LimitConnect& metaproxy_1::filter::FrontendNet::ZAssocChild::m_limit_http_req
private

Definition at line 146 of file filter_frontend_net.cpp.

◆ m_no_requests

int metaproxy_1::filter::FrontendNet::ZAssocChild::m_no_requests

Definition at line 128 of file filter_frontend_net.cpp.

Referenced by ZAssocChild().

◆ m_origin

mp::Origin metaproxy_1::filter::FrontendNet::ZAssocChild::m_origin
private

Definition at line 142 of file filter_frontend_net.cpp.

Referenced by ZAssocChild().

◆ m_p

Rep* metaproxy_1::filter::FrontendNet::ZAssocChild::m_p
private

Definition at line 145 of file filter_frontend_net.cpp.

Referenced by ZAssocChild().

◆ m_package

const mp::Package* metaproxy_1::filter::FrontendNet::ZAssocChild::m_package
private

Definition at line 144 of file filter_frontend_net.cpp.

Referenced by ZAssocChild().

◆ m_peer

std::string metaproxy_1::filter::FrontendNet::ZAssocChild::m_peer
private

Definition at line 147 of file filter_frontend_net.cpp.

Referenced by ZAssocChild().

◆ m_port

Port* metaproxy_1::filter::FrontendNet::ZAssocChild::m_port

Definition at line 129 of file filter_frontend_net.cpp.

Referenced by ZAssocChild().

◆ m_session

mp::Session metaproxy_1::filter::FrontendNet::ZAssocChild::m_session
private

Definition at line 141 of file filter_frontend_net.cpp.

Referenced by ZAssocChild().

◆ m_thread_pool_observer

mp::ThreadPoolSocketObserver* metaproxy_1::filter::FrontendNet::ZAssocChild::m_thread_pool_observer
private

Definition at line 140 of file filter_frontend_net.cpp.

Referenced by ZAssocChild().


The documentation for this class was generated from the following file: