Example #1
0
/// Find the flow corresponding to the specified transport and remote IP
/// address and port.
Flow* FlowTable::find_flow(pjsip_transport* transport, const pj_sockaddr* raddr)
{
  Flow* flow = NULL;
  FlowKey key(transport->key.type, raddr);

  char buf[100];
  LOG_DEBUG("Find flow for transport %s (%d), remote address %s",
            transport->obj_name, transport->key.type,
            pj_sockaddr_print(raddr, buf, sizeof(buf), 3));

  pthread_mutex_lock(&_flow_map_lock);

  std::map<FlowKey, Flow*>::iterator i = _tp2flow_map.find(key);

  if (i != _tp2flow_map.end())
  {
    // Found a matching flow, so return this one.
    flow = i->second;

    // Increment the reference count on the flow.
    flow->inc_ref();

    LOG_DEBUG("Found flow record %p", flow);
  }

  pthread_mutex_unlock(&_flow_map_lock);

  return flow;
}
Example #2
0
/// Find or create a flow corresponding to the specified transport and remote
/// IP address and port. This is a single method to ensure it is atomic.
Flow* FlowTable::find_create_flow(pjsip_transport* transport, const pj_sockaddr* raddr)
{
  Flow* flow = NULL;
  FlowKey key(transport->key.type, raddr);

  char buf[100];
  LOG_DEBUG("Find or create flow for transport %s (%d), remote address %s",
            transport->obj_name, transport->key.type,
            pj_sockaddr_print(raddr, buf, sizeof(buf), 3));

  pthread_mutex_lock(&_flow_map_lock);

  std::map<FlowKey, Flow*>::iterator i = _tp2flow_map.find(key);

  if (i == _tp2flow_map.end())
  {
    // No matching flow, so create a new one.
    flow = new Flow(this, transport, raddr);

    // Add the new flow to the maps.
    _tp2flow_map.insert(std::make_pair(key, flow));
    _tk2flow_map.insert(std::make_pair(flow->token(), flow));

    LOG_DEBUG("Added flow record %p", flow);

    report_flow_count();
  }
  else
  {
    // Found a matching flow, so return this one.
    flow = i->second;

    LOG_DEBUG("Found flow record %p", flow);
  }

  // Add a reference to the flow.
  flow->inc_ref();

  pthread_mutex_unlock(&_flow_map_lock);

  return flow;
}
Example #3
0
/// Find the flow corresponding to the specified flow token.
Flow* FlowTable::find_flow(const std::string& token)
{
  Flow* flow = NULL;

  LOG_DEBUG("Find flow for flow token %s", token.c_str());

  pthread_mutex_lock(&_flow_map_lock);

  std::map<std::string, Flow*>::iterator i = _tk2flow_map.find(token);
  if (i != _tk2flow_map.end())
  {
    // Found a flow matching the token.
    flow = i->second;

    // Add a reference to the flow.
    flow->inc_ref();

    LOG_DEBUG("Found flow record %p", flow);
  }

  pthread_mutex_unlock(&_flow_map_lock);

  return flow;
}