Commit ef240e04 authored by Simon Morlat's avatar Simon Morlat

Reuse connections created by client domain registrations when forwarding a...

Reuse connections created by client domain registrations when forwarding a request to the multi-domain server.
parent 006cf1b0
......@@ -214,6 +214,17 @@ const url_t *DomainRegistrationManager::getPublicUri(const tport_t *tport) const
return NULL;
}
tport_t *DomainRegistrationManager::lookupTport(const url_t *destUrl){
for (auto it = mRegistrations.begin(); it != mRegistrations.end(); ++it) {
const shared_ptr<DomainRegistration> &dr = *it;
if (url_cmp(dr->getProxy(), destUrl) == 0){
return dr->getTport();
}
}
return nullptr;
}
void DomainRegistrationManager::onLocalRegExpireUpdated(unsigned int count) {
if (count > 0 && !mDomainRegistrationsStarted) {
for_each(mRegistrations.begin(), mRegistrations.end(), mem_fn(&DomainRegistration::start));
......
......@@ -44,6 +44,12 @@ class DomainRegistration {
bool isUs(const url_t *url);
bool hasTport(const tport_t *tport) const;
const url_t *getPublicUri() const;
const url_t *getProxy()const{
return mProxy;
}
tport_t *getTport()const{
return mCurrentTport;
}
~DomainRegistration();
private:
......@@ -103,6 +109,11 @@ class DomainRegistrationManager : public LocalRegExpireListener, public std::ena
void onRegUpdated();
void onLocalRegExpireUpdated(unsigned int count);
/**
* Search for a DomainRegistration whose remote proxy matches destUrl, and return the tport_t it uses.
*/
tport_t *lookupTport(const url_t *destUrl);
private:
Agent *mAgent;
......
......@@ -20,7 +20,9 @@
#include <flexisip/agent.hh>
#include <flexisip/transaction.hh>
#include "flexisip/module-router.hh"
#include "etchosts.hh"
#include "domain-registrations.hh"
#include <sstream>
#include <sofia-sip/su_md5.h>
......@@ -295,8 +297,10 @@ void ForwardModule::sendRequest(shared_ptr<RequestSipEvent> &ev, url_t *dest) {
tp_name_t name = {0, 0, 0, 0, 0, 0};
tport_t *tport = nullptr;
if (ev->getOutgoingAgent() != nullptr) {
// tport_by_name can only work for IPs
if (tport_name_by_url(ms->getHome(), &name, reinterpret_cast<url_string_t*>(dest)) == 0) {
if ((tport = getAgent()->getDRM()->lookupTport(dest)) != nullptr){
LOGD("Found outgoing tport from domain registration manager.");
} else if (tport_name_by_url(ms->getHome(), &name, reinterpret_cast<url_string_t*>(dest)) == 0) {
// tport_by_name can only work for IPs
tport = tport_by_name(nta_agent_tports(getSofiaAgent()), &name);
if (!tport) {
LOGD("Could not existing tport to send message to %s", url_as_string(ms->getHome(), dest));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment