RestComm / restcomm-android-sdk

Android Mobile SDK to easily integrate communication features (WebRTC, messaging, presence, voice, video, screensharing) based on RestComm into native Mobile Applications
http://www.restcomm.com/
GNU Affero General Public License v3.0
153 stars 109 forks source link

SDK not supporting IPV6 when on cellular network #844

Closed SlackingVeteran closed 6 years ago

SlackingVeteran commented 6 years ago

RC android sdk is working great under wifi network but does not seem to support LTE network. Probably because of IPV6 in LTE? If current network is wifi it does not care if ipaddress is ipv6 or ipv4 it returns the address in either of the cases but if current network is cellular then RC connects only when on IPV4.

@atsakiridis you were helping out in issue #633 It seems to be same issue. I remember you mentioning that webrtc for media and JAIN SIP for signalling both supports ipv6, has this been tested yet? its been a long time since #633 was posted just wondering if any contributors has update on it. I am about to give ipv6 a try by myself as well just to see if everything works as expected.

SlackingVeteran commented 6 years ago

Error logs when LTE with IPV6: https://gist.github.com/suyashbhatt/cfb69328cd4229cc968e212351b7ea06

My suspect from the logs is that ipv6 address are being messed up with square brackets. for example in line 140 of error log Via: SIP/2.0/TCP [fe80::3ea3:13e7:928d:857d]:5090;rport ipv6 address is enclosed in brackets and again in line 143 ipaddress and the port are enclosed in brackets like this: Contact: <sip:[fe80::3ea3:13e7:928d:857d:5090];transport=tcp;registering_acc=my-cool-domain.com>. With the port 5090 inside brackets, the sip address is invalid. I am doing some more research into this but if anyone could provide some info on where root of the cause could be, than that would help me address this issue

Update: I finally managed to get it working, had to brainstorm on how SIP is trying to communicate with RC server in first place.

I had to go back and forth by testing lots of thing. First thing was to understand how sip was sending request to RC. when wifi is connected phone/pc has 2 ip addresses, 1 is local and another is global (which remote computers can see or when you check your ip in any ipaddress checking website). when sip is sending request, this is what it sends when connected to wifi:

Sending SIP request: 
                                                                                           REGISTER sip:envoychat.com:5080 SIP/2.0
                                                                                           Call-ID: 86b33fd068696cbfaaaef4902507b00c@10.0.0.67
                                                                                           CSeq: 1 REGISTER
                                                                                           From: "alice" <sip:alice@envoychat.com>;tag=1517349930988
                                                                                           To: "alice" <sip:alice@envoychat.com>
                                                                                           Via: SIP/2.0/TCP 10.0.0.67:5090;rport
                                                                                           Max-Forwards: 70
                                                                                           Route: <sip:165.227.90.178:5080;dns_route=true;transport=tcp;lr>
                                                                                           Contact: <sip:10.0.0.67:5090;transport=tcp;registering_acc=envoychat.com>
                                                                                           User-Agent: TelScale Restcomm Android Client UNOFFICIAL#1
                                                                                           Expires: 3600
                                                                                           Content-Length: 0

In above example Contact is sip:10.0.0.67:5090 where 10.0.0.67 is ipaddress within my wifi network. Now in case of Cellular data devices have lot of interfaces, in my example I had rmnet-data0, rmnet-data1, rmnet-data2, rmnet-data3, rmnet-data4, rmnet-data5, rmnet-data6, rmnet-data7 and v4-rmnet-data0. But the active interface was rmnet-data0 which had 2 inet6 address (Network carrier were forcing the use of ipv6 address). One of the address being global scope ip and another being link scope. Link scope address is valid only on that device so it did not work as expected when ipv6 was allowed in sdk. Since there is no local ipv6 while in cellular network, I had to use ipv4 of local scope. now the interface I used was v4-rmnet-data0 and regex used in JainSipClient does not cover it. I have done all the possible tests I could on multiple phones and emulators and everything seems to work perfectly. I will post a pull-request with the fix soon..

SlackingVeteran commented 6 years ago

Issue resolved with ipv6 on cellular data

atsakiridis commented 6 years ago

@suyashbhatt thanks for the contribution, much appreciated! Yeah, interface selection is always tricky, and tends to break easily. We'll try to review your PR as soon as we get some free cycles and get back to you -hopefully by next week!

Also can you accept our CLA from here, so that we can accept your code?

atsakiridis commented 6 years ago

@suyashbhatt one thing though, after you fixed the issue with IPV6, did you manage to make an actual call? If so can you share the logcat?

In that sense you might have already made the first step for this issue too :)

SlackingVeteran commented 6 years ago

Yes, I was able to make actual call after fixing it. I will post the logs

On Jan 31, 2018 3:06 AM, "Antonis Tsakiridis" notifications@github.com wrote:

@suyashbhatt https://github.com/suyashbhatt one thing though, after you fixed the issue with IPV6, did you manage to make an actual call? If so can you share the logcat?

In that sense you might have already made the first step for this https://github.com/RestComm/restcomm-android-sdk/issues/647 issue too :)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/RestComm/restcomm-android-sdk/issues/844#issuecomment-361854296, or mute the thread https://github.com/notifications/unsubscribe-auth/AFG8nmpdVvnDtORTHDtxydCcpzvWnTRlks5tQB71gaJpZM4RyXB1 .

SlackingVeteran commented 6 years ago

I have posted logs in pull-request #845

SlackingVeteran commented 6 years ago

And yes #647 is also fixed, it was basically the same thing. I was not able to test IPv6 on wifi network but cellular data works as expected.

atsakiridis commented 6 years ago

Thanks for following up with this @suyashbhatt! Just had a look at the logs and seems ipv4 is still used for signaling:

01-31 04:12:23.056 431-14098/org.restcomm.android.olympus.premium.debug I/JainSipClient: Use IPV4 is true
01-31 04:12:23.057 431-14098/org.restcomm.android.olympus.premium.debug I/JainSipClient: interface2Address(): Current address (if): 192.0.0.4 (v4-rmnet_data0)
01-31 04:12:23.057 431-14098/org.restcomm.android.olympus.premium.debug I/JainSipClient: regular expression matched
01-31 04:12:23.058 431-14098/org.restcomm.android.olympus.premium.debug I/JainSipClient: Use IPV4 is true
01-31 04:12:23.058 431-14098/org.restcomm.android.olympus.premium.debug I/JainSipClient:  is ipv4 in interface  (v4-rmnet_data0)
01-31 04:12:23.059 431-14098/org.restcomm.android.olympus.premium.debug I/JainSipClient: interface2Address(): Interface not matching or down: name:rmnet_data2 (rmnet_data2) isUp: false
01-31 04:12:23.059 431-14098/org.restcomm.android.olympus.premium.debug I/JainSipClient: interface2Address(): Current address (if): 2607:FC20:6515:8963:0:4D:DB05:E601 (rmnet_data1)
01-31 04:12:23.060 431-14098/org.restcomm.android.olympus.premium.debug I/JainSipClient: regular expression matched
01-31 04:12:23.060 431-14098/org.restcomm.android.olympus.premium.debug I/JainSipClient: Use IPV4 is true
01-31 04:12:23.061 431-14098/org.restcomm.android.olympus.premium.debug I/JainSipClient: interface2Address(): Interface not matching or down: name:rmnet_data4 (rmnet_data4) isUp: false
01-31 04:12:23.061 431-14098/org.restcomm.android.olympus.premium.debug I/JainSipClient: interface2Address(): Interface not matching or down: name:bond0 (bond0) isUp: false
01-31 04:12:23.062 431-14098/org.restcomm.android.olympus.premium.debug I/JainSipClient: interface2Address(): Interface not matching or down: name:rmnet_data3 (rmnet_data3) isUp: false
01-31 04:12:23.062 431-14098/org.restcomm.android.olympus.premium.debug I/JainSipClient: interface2Address(): Interface not matching or down: name:rmnet_data6 (rmnet_data6) isUp: false
01-31 04:12:23.062 431-14098/org.restcomm.android.olympus.premium.debug I/JainSipClient: interface2Address(): Interface not matching or down: name:rmnet_data5 (rmnet_data5) isUp: false
01-31 04:12:23.063 431-14098/org.restcomm.android.olympus.premium.debug V/JainSipClient: interface2Address(): stringAddress: 192.0.0.4, for currently active network: rmnet, interfaces: [name:dummy0 (dummy0), name:epdg1 (epdg1), name:epdg0 (epdg0), name:lo (lo), name:epdg4 (epdg4), name:epdg3 (epdg3), name:epdg2 (epdg2), name:sit0 (sit0), name:rmnet_data7 (rmnet_data7), name:rmnet_data0 (rmnet_data0), name:p2p0 (p2p0), name:v4-rmnet_data0 (v4-rmnet_data0), name:wlan0 (wlan0), name:rmnet_data2 (rmnet_data2), name:rmnet_data1 (rmnet_data1), name:rmnet_data4 (rmnet_data4), name:bond0 (bond0), name:rmnet_data3 (rmnet_data3), name:rmnet_data6 (rmnet_data6), name:rmnet_data5 (rmnet_data5), name:rmnet_ipa0 (rmnet_ipa0)]
01-31 04:12:23.063 431-14098/org.restcomm.android.olympus.premium.debug V/JainSipClient: getIPAddress(): 192.0.0.4

Do you think you can do a test with useIPv4 set to false and provide the logcat?

Also I'm afraid we won't be able to close #647 until we do a thorough verification that all aspects of ipv6 are covered and part of this should probably be testing in a ipv6-only network. So let's leave it open for now. Unless, you want to bite the bullet and go all the way of course ;)

SlackingVeteran commented 6 years ago

I had few hiccups with useIPv4 set to false, for some reason addresses were messed up. for example this was the sip address I got sip:[fe80::3ea3:13e7:928d:857d:5090] where its supposed to be sip:[fe80::3ea3:13e7:928d:857d:]:5090 I will have to find the actual cause behind the mess-ups in addresses when ipv4 is fully disabled.

atsakiridis commented 6 years ago

Ok @suyashbhatt, appreciate the efforts! Please let us know if you need any help there

SlackingVeteran commented 6 years ago

Hi @atsakiridis, I dont think header is much of the issue right now, though it might create issue later after successful connection is made with the server. At this moment I am still trying to find why client is unable to connect to server regardless of using either local link or global ipv6 (I assume local link should be used while making connection). At first my server did not have ipv6 so connection would never be successful, but then I added ipv6 to my server and still unable to find out why client is unable to connect to host/server. Following are the known issues that needs to be fixed before we get ipv6 support:

  1. dns query returns both ipv4 and ipv6 for the host/server and ipv4 is used regardless of useIPv4 = false

6022-6229/org.restcomm.android.olympus.premium.debug I/JainSipMessageBuilder: createRouteHeader(): DNS query time: 381 ms, hops: [165.227.90.178:5080/tcp, [2604:a880:400:d0::896:9001]:5080/tcp]

6022-6229/org.restcomm.android.olympus.premium.debug W/System.err: Caused by: android.javax.sip.SipException: Could not connect to /165.227.90.178:5080

  1. need to get ipv6 from wifi interface. From current implementation when Network Status is WIFI, getIPAddress method will return only ipv4

  2. Need to fix messed up sip address in header when using ipv6 if it causes issue. (Optional)

Since log is not helping much on why send request is failing when both client and server are using ipv6, I might need your help in this. I think I have an idea but I could be wrong on this as well. There is little or some possibility that sendRequest, sendMessage or any other network io methods are using ipv4 only. I have this assumption coz ipv4 from dns query is being used regardless of using ipv6 and its unable to establish connection with server. It would be great if you could point me to correct direction, or possibly help get better logs on why it is unable to connect. Following is the log where its unclear why client is unable to connect to service:

02-05 03:53:10.550 10944-10974/org.restcomm.android.olympus.premium.debug I/JainSipClient: Sending SIP request: 
                                                                                           REGISTER sip:[2604:a880:400:d0::896:9001]:5080 SIP/2.0
                                                                                           Call-ID: 7bbf5e3f679c1798c543fc91749754dc@2607:fc20:1395:6b3b:0:45:b1d6:6601
                                                                                           CSeq: 1 REGISTER
                                                                                           From: "alice" <sip:alice@[2604:a880:400:d0::896:9001]>;tag=1517820790528
                                                                                           To: "alice" <sip:alice@[2604:a880:400:d0::896:9001]>
                                                                                           Via: SIP/2.0/TCP [2607:fc20:1395:6b3b:0:45:b1d6:6601]:5090;rport
                                                                                           Max-Forwards: 70
                                                                                           Route: <sip:[2604:a880:400:d0::896:9001]:5080;dns_route=true;transport=tcp;lr>
                                                                                           Contact: <sip:[2607:fc20:1395:6b3b:0:45:b1d6:6601:5090];transport=tcp;registering_acc=[2604:a880:400:d0::896:9001]>
                                                                                           User-Agent: TelScale Restcomm Android Client UNOFFICIAL#1
                                                                                           Expires: 3600
                                                                                           Content-Length: 0
02-05 03:53:14.251 10944-10965/org.restcomm.android.olympus.premium.debug V/FA: Inactivity, disconnecting from the service
02-05 03:53:18.582 10944-10974/org.restcomm.android.olympus.premium.debug W/System.err: org.restcomm.android.sdk.SignalingClient.JainSipClient.JainSipException
02-05 03:53:18.582 10944-10974/org.restcomm.android.olympus.premium.debug W/System.err:     at org.restcomm.android.sdk.SignalingClient.JainSipClient.JainSipClient.jainSipClientRegister(JainSipClient.java:568)
02-05 03:53:18.582 10944-10974/org.restcomm.android.olympus.premium.debug W/System.err:     at org.restcomm.android.sdk.SignalingClient.JainSipClient.JainSipJob$JainSipFsm.process(JainSipJob.java:186)
02-05 03:53:18.582 10944-10974/org.restcomm.android.olympus.premium.debug W/System.err:     at org.restcomm.android.sdk.SignalingClient.JainSipClient.JainSipJob.startFsm(JainSipJob.java:783)
02-05 03:53:18.582 10944-10974/org.restcomm.android.olympus.premium.debug W/System.err:     at org.restcomm.android.sdk.SignalingClient.JainSipClient.JainSipJobManager.add(JainSipJobManager.java:53)
02-05 03:53:18.582 10944-10974/org.restcomm.android.olympus.premium.debug W/System.err:     at org.restcomm.android.sdk.SignalingClient.JainSipClient.JainSipJobManager.add(JainSipJobManager.java:61)
02-05 03:53:18.582 10944-10974/org.restcomm.android.olympus.premium.debug W/System.err:     at org.restcomm.android.sdk.SignalingClient.JainSipClient.JainSipClient.open(JainSipClient.java:226)
02-05 03:53:18.583 10944-10974/org.restcomm.android.olympus.premium.debug W/System.err:     at org.restcomm.android.sdk.SignalingClient.SignalingHandler.handleMessage(SignalingHandler.java:75)
02-05 03:53:18.583 10944-10974/org.restcomm.android.olympus.premium.debug W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:105)
02-05 03:53:18.583 10944-10974/org.restcomm.android.olympus.premium.debug W/System.err:     at android.os.Looper.loop(Looper.java:164)
02-05 03:53:18.583 10944-10974/org.restcomm.android.olympus.premium.debug W/System.err:     at android.os.HandlerThread.run(HandlerThread.java:65)
02-05 03:53:18.583 10944-10974/org.restcomm.android.olympus.premium.debug W/System.err: Caused by: android.javax.sip.SipException: Could not connect to /2604:a880:400:d0::896:9001:5080
02-05 03:53:18.583 10944-10974/org.restcomm.android.olympus.premium.debug W/System.err:     at android.gov.nist.javax.sip.stack.SIPClientTransactionImpl.sendRequest(SIPClientTransactionImpl.java:1099)
02-05 03:53:18.583 10944-10974/org.restcomm.android.olympus.premium.debug W/System.err:     at org.restcomm.android.sdk.SignalingClient.JainSipClient.JainSipClient.jainSipClientRegister(JainSipClient.java:559)
02-05 03:53:18.583 10944-10974/org.restcomm.android.olympus.premium.debug W/System.err:     ... 9 more
02-05 03:53:18.584 10944-10974/org.restcomm.android.olympus.premium.debug W/System.err: Caused by: java.io.IOException: Could not connect to /2604:a880:400:d0::896:9001:5080
02-05 03:53:18.584 10944-10974/org.restcomm.android.olympus.premium.debug W/System.err:     at android.gov.nist.javax.sip.stack.IOHandler.sendBytes(IOHandler.java:391)
02-05 03:53:18.584 10944-10974/org.restcomm.android.olympus.premium.debug W/System.err:     at android.gov.nist.javax.sip.stack.TCPMessageChannel.sendMessage(TCPMessageChannel.java:350)
02-05 03:53:18.584 10944-10974/org.restcomm.android.olympus.premium.debug W/System.err:     at android.gov.nist.javax.sip.stack.MessageChannel.sendMessage(MessageChannel.java:286)
02-05 03:53:18.584 10944-10974/org.restcomm.android.olympus.premium.debug W/System.err:     at android.gov.nist.javax.sip.stack.SIPTransactionImpl.sendMessage(SIPTransactionImpl.java:925)
02-05 03:53:18.584 10944-10974/org.restcomm.android.olympus.premium.debug W/System.err:     at android.gov.nist.javax.sip.stack.SIPClientTransactionImpl.sendMessage(SIPClientTransactionImpl.java:495)
02-05 03:53:18.584 10944-10974/org.restcomm.android.olympus.premium.debug W/System.err:     at android.gov.nist.javax.sip.stack.SIPClientTransactionImpl.sendRequest(SIPClientTransactionImpl.java:1092)
02-05 03:53:18.584 10944-10974/org.restcomm.android.olympus.premium.debug W/System.err:     ... 10 more
02-05 03:53:18.586 10944-10974/org.restcomm.android.olympus.premium.debug V/SignalingHandler: onClientOpenedReply: jobId: 1517820789501, connectivityStatus: RCConnectivityStatusNone, status: ERROR_DEVICE_REGISTER_COULD_NOT_CONNECT, text: Device could not connect to Service
atsakiridis commented 6 years ago

Thanks for taking the time to investigate this @suyashbhatt! Android SDK underneath, for SIP implementation uses JAIN SIP, so let me check with our JAIN SIP lead, if he can verify that JAIN SIP fully supports IPV6. @jaimecasero any hints?

SlackingVeteran commented 6 years ago

Any updates here?

jaimecasero commented 6 years ago

JAIN-SIP should support IPV6. As part of a customer integration, we recently added some support for IPV6 ScopedAddrs, and some header parsing fixings.

SlackingVeteran commented 6 years ago

@atsakiridis I have ipv6 enabled on my server but turns out RC does not use ipv6 in server side. Thus all connections over ipv6 to RC server are refused. Is there any way I can enable it? /bin/restcomm/restcomm.conf needs PRIVATE_IP, SUBNET_MASK, NETWORK BROADCAST_ADDRESS and STATIC_ADDRESS. Ipv6 networking does not have broadcast, it supports multicast. Is there any proper way to set these values so that RC could be used over both ipv6 and ipv4? JBoss supports ipv6 connection but I dont know how RC server configuration works, any help on this would be appreciated.

Thanks, Suyash

atsakiridis commented 6 years ago

@suyashbhatt I would suggest that you ask that on restcomm@googlegroups.com, so that the Restcomm Connect guys can get back to you. This is outside the scope of restcomm SDKs.

SlackingVeteran commented 6 years ago

Well eventually this is about test of ipv6 capability of android sdk.

And actually all I wanted was to fix RC connection under cellular network, which has been fixed with me last pull request. I was just trying to help. there was no need for me to dive this deep into ipv6 concerns.. Thanks for advice though, I will close the issue with this.

gsaslis commented 6 years ago

@suyashbhatt haven't gone into too much detail here, but was this essentially a duplicate of #647 ?

SlackingVeteran commented 6 years ago

@gsaslis, yes. Seems like sdk does support ipv6 after all my test. But its ther RC that cannot be deployed with ipv6 support at the moment. Or at least there is no documentation on how to do it. I tried a lot, got ipv6 connection to my server but RC doesnt use ipv6 at all, admin apge or olympus or anything else in RC cannot be accessed with ipv6.

Just to make clear, SDK does support ipv6. JainSip and sdk has everything that is required for ipv6 connection. It is trying to make connection through ipv6 but server is not accessable at all.