How to use allow_contact_rewrite in pjsip in android - sip

I am trying to build pjsip VoIP app for android.This is the following description given for property used in account configuration.
/**
* This option is used to update the transport address and the Contact
* header of REGISTER request. When this option is enabled, the library
* will keep track of the public IP address from the response of REGISTER
* request. Once it detects that the address has changed, it will
* unregister current Contact, update the Contact with transport address
* learned from Via header, and register a new Contact to the registrar.
* This will also update the public name of UDP transport if STUN is
* configured.
*
* See also contact_rewrite_method field.
*
* Default: 1 (yes)
*/
pj_bool_t allow_contact_rewrite;
Until now via address is only changed by pjsip.how exactly does this property work??i can see no differences??

This option only kick in once the pjsip client is behind some sort of NAT.
i.e.
[pjsip client / e.g. 10.0.100] -> [NAT / e.g. 1.2.3.4] -> [SIP Server / e.g. 2.3.4.5]
When PJSIP registers with the sip server with the "contact" address of 10.0.100:5060 the SIP Server will send back a response saying that it came from 1.2.3.4: (because of the NAT).
This is when the allow_contact_rewrite kicks in and unregisters the registration and re-registers it with the 1.2.3.4: contact address.
Why it does this is so that if the sip proxy server needs to contact/send request to the SIP UAS it uses the contact header address.
This feature is "assuming" many that the NAT support hole punching to keep the contact address valid over a range of time.
Another option is to setup STUN so that PJSIP can figure out this information ahead of time so that it "knows" the external ip address before it registers (although there is symmetric NAT which can make STUN useless).
All of these options are to try get a setup so that the client can be contacted through the internet from the SIP Proxy server to the pjsip client when a "event" happens (e.g. phone call).
Personally I've found none of these setups to get a contact address that is connectable by the SIP Porxy server to work at all.
The best setup when coming from the internet client that I use is to always use TCP only (no UDP). Enable rport and TCP keep-alive in pjsip. As long as the sip server respects rport and the tcp/ip connection stays alive then everything works fine (i.e. the sip proxy can send requests down the existing open TCP socket).
That just leaves the problem of media connections between the two endpoints, which you have to rely of ICE/STUN/TURN/NAT hole punching to get that going.

Related

How SIP Request Call ID without IP affects server response?

I am facing a situation when my sip client sends a deregister with call ID without IP address.
Call-ID: ZbTZ3VwsZoknVtlvROGGsOO8pt0hpFi.
This message is causing looping of the 200 OK responses as the via header of the next register message from same client is changed.
The situation is as follows
Request
deregister :LanClient--->Proxy-->Server
Response
Repeat:
100 trying :Server-->Proxy--xx->LanClient
200 Ok :Server-->Proxy--xx->Lanclient
goto Repeat
When one deregister message(i.e register message with expires=0) goes to the server the Via header contains the WAN IP of our proxy rather than LAN Client IP.This causes the respones from the server to go the WAN IP than the LAN IP.
What I am curious about is about that out of multiple clients registered with the server only the problem client messages have Call-ID field without an IP address.
I know that we can have call-ID without IP address. How would having an IP or not Having an IP in call ID make a difference in my scenario...
The value of the Call-Id header is just a string, at least from the perspective of the receiver of the request.
When a client deregisters, it should use the same Call-Id that was used for registration.
I don't understand the Via header part. Obviously, consequtive REGISTER requests (and other messages as well) has different Via headers since the branch parameter is new for every transaction.

How to check whether user already authenticated via UDP

Suppose that I have to write a UDP server which should receive authentication token for each client in the first message and then receive different data after some period of time. This UDP server should obviously check whether certain client authenticated previously or not. How should I do it? Should I store "authenticated" flag for each (IP addr, port) pair? Is it ok? If so, what will happen if several clients will have the same IP address (for example, they share it from the same internet provider)?
I think you can't. You'll need to have the token in each message. Multiple requests can come from the same IP, such as a client connecting from behind a NAT.
This a rare case where you might want to use multiple UDP sockets at the server and connect() each of them to one authenticated client, so that you can only receive further messages on each one from each authenticated client. You'll have to send the first reply via hat socket,a denture client will have to be written to adjust its destination accordingly after receiving the first reply.

making SIP calls over TCP using PJSIP

I'm using a PJSIP's pjsua dialer (based on pjsua_app.c, PJSIP 2.0.1) with TCP transport and a SIP trunk to make calls to a mobile phone. The dialer registers with a SIP Server over TCP and also sends out INVITES over TCP. UDP transport is not being used.
The environment is something like this -
PJSIP (behind NAT)<--- SIP over TCP ---> SIP Server <--- SIP trunk --> SIP trunk Provider <-- PSTN/Mobile Gateway-->Mobile phone
All calls are made from PJSIP over TCP to the mobile. To disable UDP transport creation I inserted a line "cfg->no_udp = true;" at the end of the function
"static void default_config(struct app_config *cfg)" in pjsua_app.c
I followed the instructions given here to make calls over TCP.
The problem is that we don't receive audio sent from the mobile end into the PJSIP dialer.
But RTP packets from the PJSIP dialer reach the mobile side just fine. We can hear audio in the mobile when the call is established.
We found from packet traces that the reason we dont receive media in the PJSIP dialer is that the SIP server is sending RTP packets received over the SIP trunk to a private IP address.
But when we switch to UDP for registration and send INVITES over TCP the call works fine (audio at both ends).
The wireshark packet capture shows the following -
1. PJSIP registers with server over TCP.
2. Server sends 401 with PJ's public IP and port in VIA
3. PJ registers again but inserts its public ip and port in the
contact header in the next REGISTER message sequence.
So far so good. Same sequence of messages seen when UDP is used to REGISTER.
4. INVITE sent over TCP. Dialog establishment works fine.
But in the record-route header nat=yes is missing.
5. Server sends media to private IP. No media received at PJSIP.
Is this a bug in PJSIP? If so how can this be fixed. Wireshark packet traces are available on request.
Your help and inputs are much appreciated.
Your question doesn't actually make sense as the transport of the signalling between the sip endpoint and the sip server (either UDP or TCP) has no bearing on the media transport between the two sip endpoints (most likely UDP). So there must be something else going on.
Since your talking about private IP addresses, I'm assuming you are coming from a behind a NAT over the internet to a "public" sip server.
In these types of environments I would recommend you setup STUN, TURN and ICE on the sip endpoint.
I would guess the UDP setup you where talking about has the STUN server setup and the TCP setup you where talking about doesn't.
Without further information I can't help much more.
Try to use port other than 5060 in both client and server, and/or reducing the SIP message size.
It seams this is a know issue for sending INVITE request over TCP in PJSIP.
Also you can find here some advices for reducing the SIP message size.
Please make sure that allow_contact_rewrite is set to true so that the media will be received to your end.
I think my answer is too late but this may help some other folks

SIP Client (Peers) - Call received failed

I have to integrate the text, voice and video chat via SIP server into my application. So that I have chosen the "Peers" from http://peers.sourceforge.net/.
I have downloaded the code, registered a sip addressz(peers sip client) and call to another sip account(peers sip client). I can't receive a call in that peers client. If I call to another sip client(X-Lite), I can able to receive a call.
Can anybody tell me what may be the problem and how to fix?
when you want to call a remote party from peers you should use sip:user#domain.com where domain.com is the domain you used in your account. If you used an ip address in domain in your sip account, you should use the same domain.

Is that possible to use SIP in LAN network?

I don't know enough about SIP. As far as I know SIP can not be used in LAN. But it's features are very good. I want to use it for a LAN messenger (with video conference facilities).
Is there any way of using SIP in LAN network ?
The SIP protocol can be used over any reliable transport (TCP, XMPP, instant messaging channel, etc...) to a service (e.g. a server such as a SIP proxy) that knows how to route the SIP INVITE message from the caller to the callee. e.g. If you send an INVITE to bob#foobar.com, there's needs to be a service that knows how to find "bob" and deliver the message. Likewise, when Bob sends back his response messages back, the messages need to route back to the caller who sent the original INVITE.
And you can do SIP without a server - provided the computer already have a connection (direct or indirect) to the other computer intended for the call.
But SIP isn't anything special. If you were to invent your own video conferencing protocol, it would probably look a lot like SIP. SIP's primary job is for both sides of a call to exchange IP/port candidates for connecting directly in addition to codec and bandwidth negotiation data.
After the SIP messages are exchanged, ICE/STUN/TURN take over and RTP packets typically flow. SIP isn't used in the call except to end the call.
What are you really trying to do anyway?
Thread is Old but still I would like to contribute to this. There are various SIP server like http://www.officesip.com/index.html which works in LAN and can be connected to hardware phone too and soft client also.
Jitsi is open source cross platform SIP/xmpp client:https://jitsi.org/
And if you want to XMPP server Openfire is the best:http://www.igniterealtime.org/projects/openfire/
I hope this will definitely help someone..!