Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
savoirfairelinux
jami-daemon
Commits
65f840b0
Commit
65f840b0
authored
Mar 04, 2012
by
Alexandre Savard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#8320: Make sure stun keep alive is enabled
parent
e698e70c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
35 deletions
+65
-35
daemon/src/sip/sipvoiplink.cpp
daemon/src/sip/sipvoiplink.cpp
+63
-33
daemon/src/sip/sipvoiplink.h
daemon/src/sip/sipvoiplink.h
+2
-2
No files found.
daemon/src/sip/sipvoiplink.cpp
View file @
65f840b0
...
...
@@ -1259,6 +1259,31 @@ bool SIPVoIPLink::SIPNewIpToIpCall(const std::string& id, const std::string& to)
pj_bool_t
stun_sock_on_status_cb
(
pj_stun_sock
*
stun_sock
UNUSED
,
pj_stun_sock_op
op
UNUSED
,
pj_status_t
status
)
{
switch
(
op
)
{
case
PJ_STUN_SOCK_DNS_OP
:
DEBUG
(
"UserAgent: Stun operation dns resolution"
);
break
;
case
PJ_STUN_SOCK_BINDING_OP
:
DEBUG
(
"UserAgent: Stun operation binding"
);
break
;
case
PJ_STUN_SOCK_KEEP_ALIVE_OP
:
DEBUG
(
"UserAgent: Stun operation keep alive"
);
break
;
case
PJ_STUN_SOCK_MAPPED_ADDR_CHANGE
:
DEBUG
(
"UserAgent: Stun operation address mapping change"
);
break
;
default:
DEBUG
(
"UserAgent: Stun unknown operation"
);
break
;
}
if
(
status
==
PJ_SUCCESS
)
{
DEBUG
(
"UserAgent: Stun operation success"
);
}
else
{
ERROR
(
"UserAgent: Stun operation failure"
);
}
return
status
==
PJ_SUCCESS
;
}
...
...
@@ -1268,7 +1293,7 @@ pj_bool_t stun_sock_on_rx_data_cb(pj_stun_sock *stun_sock UNUSED, void *pkt UNUS
}
pj_status_t
SIPVoIPLink
::
stunServerResolve
(
SIPAccount
*
accoun
t
)
pj_status_t
SIPVoIPLink
::
stunServerResolve
(
pj_str_t
serverName
,
pj_uint16_t
por
t
)
{
pj_stun_config
stunCfg
;
pj_stun_config_init
(
&
stunCfg
,
&
cp_
->
factory
,
0
,
pjsip_endpt_get_ioqueue
(
endpt_
),
pjsip_endpt_get_timer_heap
(
endpt_
));
...
...
@@ -1282,21 +1307,19 @@ pj_status_t SIPVoIPLink::stunServerResolve(SIPAccount *account)
pj_stun_sock
*
stun_sock
;
pj_status_t
status
=
pj_stun_sock_create
(
&
stunCfg
,
"stunresolve"
,
pj_AF_INET
(),
&
stun_sock_cb
,
NULL
,
NULL
,
&
stun_sock
);
pj_str_t
stunServer
=
account
->
getStunServerName
();
if
(
status
!=
PJ_SUCCESS
)
{
char
errmsg
[
PJ_ERR_MSG_SIZE
];
pj_strerror
(
status
,
errmsg
,
sizeof
(
errmsg
));
ERROR
(
"Error creating STUN socket for %.*s: %s"
,
(
int
)
s
tunS
erver
.
slen
,
s
tunS
erver
.
ptr
,
errmsg
);
ERROR
(
"
UserAgent:
Error creating STUN socket for %.*s: %s"
,
(
int
)
server
Name
.
slen
,
server
Name
.
ptr
,
errmsg
);
return
status
;
}
status
=
pj_stun_sock_start
(
stun_sock
,
&
s
tunS
erver
,
account
->
getStunP
ort
()
,
NULL
);
status
=
pj_stun_sock_start
(
stun_sock
,
&
server
Name
,
p
ort
,
NULL
);
if
(
status
!=
PJ_SUCCESS
)
{
char
errmsg
[
PJ_ERR_MSG_SIZE
];
pj_strerror
(
status
,
errmsg
,
sizeof
(
errmsg
));
DEBUG
(
"Error starting STUN socket for %.*s: %s"
,
(
int
)
s
tunS
erver
.
slen
,
s
tunS
erver
.
ptr
,
errmsg
);
DEBUG
(
"
UserAgent:
Error starting STUN socket for %.*s: %s"
,
(
int
)
server
Name
.
slen
,
server
Name
.
ptr
,
errmsg
);
pj_stun_sock_destroy
(
stun_sock
);
}
...
...
@@ -1373,13 +1396,13 @@ void SIPVoIPLink::createTlsTransport(SIPAccount *account, std::string remoteAddr
void
SIPVoIPLink
::
createSipTransport
(
SIPAccount
*
account
)
{
shutdownSipTransport
(
account
);
if
(
account
==
NULL
)
{
ERROR
(
"Account is NULL while creating sip transport"
);
ERROR
(
"
UserAgent:
Account is NULL while creating sip transport"
);
return
;
}
shutdownSipTransport
(
account
);
if
(
account
->
isTlsEnabled
())
{
std
::
string
remoteSipUri
(
account
->
getServerUri
());
static
const
char
SIPS_PREFIX
[]
=
"<sips:"
;
...
...
@@ -1388,8 +1411,10 @@ void SIPVoIPLink::createSipTransport(SIPAccount *account)
std
::
string
remoteAddr
(
remoteSipUri
.
substr
(
sips
,
trns
-
sips
));
createTlsTransport
(
account
,
remoteAddr
);
}
else
if
(
account
->
isStunEnabled
())
createStunTransport
(
account
);
}
else
if
(
account
->
isStunEnabled
())
{
pjsip_transport
*
transport
=
createStunTransport
(
account
->
getStunServerName
(),
account
->
getStunPort
());
account
->
transport_
=
transport
;
}
else
{
pjsip_transport
*
transport
=
createUdpTransport
(
account
->
getLocalInterface
(),
account
->
getLocalPort
());
account
->
transport_
=
transport
;
...
...
@@ -1467,39 +1492,43 @@ pjsip_tpselector *SIPVoIPLink::initTransportSelector(pjsip_transport *transport,
return
tp
;
}
void
SIPVoIPLink
::
createStunTransport
(
SIPAccount
*
accoun
t
)
pjsip_transport
*
SIPVoIPLink
::
createStunTransport
(
pj_str_t
serverName
,
pj_uint16_t
por
t
)
{
pj_str_t
stunServer
=
account
->
getStunServerName
();
pj_uint16_t
stunPort
=
PJ_STUN_PORT
;
// account->getStunPort();
DEBUG
(
"UserAgent: Create stun transport server name: %s, port: %d"
,
account
->
getStunServerName
(),
stunPort
);
// account->getStunPort());
if
(
stunServerResolve
(
account
)
!=
PJ_SUCCESS
)
{
ERROR
(
"Can't resolve STUN server"
);
return
;
// pj_str_t stunServer = account->getStunServerName();
// pj_uint16_t stunPort = PJ_STUN_PORT; // account->getStunPort();
pjsip_transport
*
transport
;
DEBUG
(
"UserAgent: Create stun transport server name: %s, port: %d"
,
serverName
,
port
);
// account->getStunPort());
if
(
stunServerResolve
(
serverName
,
port
)
!=
PJ_SUCCESS
)
{
ERROR
(
"UserAgent: Can't resolve STUN server"
);
// Signal client
return
NULL
;
}
pj_sock_t
sock
=
PJ_INVALID_SOCKET
;
pj_sockaddr_in
boundAddr
;
if
(
pj_sockaddr_in_init
(
&
boundAddr
,
&
stunServer
,
0
)
!=
PJ_SUCCESS
)
{
ERROR
(
"Can't initialize IPv4 socket on %*s:%i"
,
stunServer
.
slen
,
stunServer
.
ptr
,
stunPort
);
return
;
if
(
pj_sockaddr_in_init
(
&
boundAddr
,
&
serverName
,
0
)
!=
PJ_SUCCESS
)
{
ERROR
(
"UserAgent: Can't initialize IPv4 socket on %*s:%i"
,
serverName
.
slen
,
serverName
.
ptr
,
port
);
// Signal client
return
NULL
;
}
if
(
pj_sock_socket
(
pj_AF_INET
(),
pj_SOCK_DGRAM
(),
0
,
&
sock
)
!=
PJ_SUCCESS
)
{
ERROR
(
"Can't create or bind socket"
);
return
;
ERROR
(
"UserAgent: Can't create or bind socket"
);
// Signal client
return
NULL
;
}
// Query the mapped IP address and port on the 'outside' of the NAT
pj_sockaddr_in
pub_addr
;
if
(
pjstun_get_mapped_addr
(
&
cp_
->
factory
,
1
,
&
sock
,
&
s
tunS
erver
,
stunP
ort
,
&
s
tunS
erver
,
stunP
ort
,
&
pub_addr
)
!=
PJ_SUCCESS
)
{
ERROR
(
"Can't contact STUN server"
);
if
(
pjstun_get_mapped_addr
(
&
cp_
->
factory
,
1
,
&
sock
,
&
server
Name
,
p
ort
,
&
server
Name
,
p
ort
,
&
pub_addr
)
!=
PJ_SUCCESS
)
{
ERROR
(
"
UserAgent:
Can't contact STUN server"
);
pj_sock_close
(
sock
);
return
;
// signal client
return
NULL
;
}
pjsip_host_port
a_name
=
{
...
...
@@ -1507,15 +1536,17 @@ void SIPVoIPLink::createStunTransport(SIPAccount *account)
pj_ntohs
(
pub_addr
.
sin_port
)
};
std
::
string
listeningAddress
=
std
::
string
(
a_name
.
host
.
ptr
,
a_name
.
host
.
slen
);
//
std::string listeningAddress = std::string(a_name.host.ptr, a_name.host.slen);
account
->
setPublishedAddress
(
listeningAddress
);
account
->
setPublishedPort
(
a_name
.
port
);
//
account->setPublishedAddress(listeningAddress);
//
account->setPublishedPort(a_name.port);
pjsip_udp_transport_attach2
(
endpt_
,
PJSIP_TRANSPORT_UDP
,
sock
,
&
a_name
,
1
,
&
account
->
transport
_
);
&
transport
);
pjsip_tpmgr_dump_transports
(
pjsip_endpt_get_tpmgr
(
endpt_
));
return
transport
;
}
void
SIPVoIPLink
::
shutdownSipTransport
(
SIPAccount
*
account
)
...
...
@@ -1563,7 +1594,6 @@ void SIPVoIPLink::findLocalAddressFromTransport(pjsip_transport *transport, pjsi
int
i_port
=
0
;
// Find the local address and port for this transport
DEBUG
(
"transportType: %d
\n
"
,
transportType
);
if
(
pjsip_tpmgr_find_local_addr
(
tpmgr
,
pool_
,
transportType
,
tp_sel
,
&
localAddress
,
&
i_port
)
!=
PJ_SUCCESS
)
{
WARN
(
"SIPVoIPLink: Could not retreive local address and port from transport, using %s:%s"
,
addr
.
c_str
(),
port
.
c_str
());
return
;
...
...
daemon/src/sip/sipvoiplink.h
View file @
65f840b0
...
...
@@ -306,7 +306,7 @@ class SIPVoIPLink : public VoIPLink {
/**
* Resolve public address for this account
*/
pj_status_t
stunServerResolve
(
SIPAccount
*
);
pj_status_t
stunServerResolve
(
pj_str_t
serverName
,
pj_uint16_t
port
);
/**
* Create the default TLS listener.
...
...
@@ -336,7 +336,7 @@ class SIPVoIPLink : public VoIPLink {
* Create a UDP transport using stun server to resove public address
* @param account The account for which a transport must be created.
*/
void
createStunTransport
(
SIPAccount
*
accoun
t
);
pjsip_transport
*
createStunTransport
(
pj_str_t
serverName
,
pj_uint16_t
por
t
);
/**
* UDP Transports are stored in this map in order to retreive them in case
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment