emiago / gophone

Gophone CLI SIP phone powered by SIPGO
BSD 2-Clause "Simplified" License
45 stars 1 forks source link

SRV dns resolution #2

Closed amccool closed 6 months ago

amccool commented 6 months ago

@emiago this cmd line tool is very effective for testing. However the domain name of the sip address is not resolving using the SRV record of the sip address domain.

I would be happy to help out if I could see the source.

side note: I would need to plug into the "events" to perform execute additional actions or logging to complete the integration testing loop.

emiago commented 6 months ago

hi @amccool. Can you confirm you have tested with latest binary (I have no versioning yet). This line should do this lookup https://github.com/emiago/sipgo/blob/9a076d63800013d7cede0870315178131c76839f/sip/transport_layer.go#L434

As for source code, if you are doing dial this is invoked. https://github.com/emiago/sipgox/blob/main/phone.go#L418

So you can quickly build your softphone ;)

amccool commented 6 months ago

used the binary (windows) retrieved on 2024/03/27 from here: https://github.com/emiago/gophone/releases/tag/v1.0.0

could you supply some instructions on running the phone.go from sipgox. I seem to be missing something go run phone.go

emiago commented 6 months ago

no I meant, gophone is just exec binary for that function, so you can quickly write main function and execute above. There is in Readme example.

Anyway I would like to test and debug your case scenario. As you are on windows, maybe it is something within resolver.

Can you run gophone.exe with env set in your power shell and paste output here. So this

$env:LOG_LEVEL = debug
$env:SIP_DEBUG = true
\gophone.exe dial ......
amccool commented 6 months ago

I hate posting all this data, but its all internal

_sip._udp.33333333-3333-3bad-c0de-333333333333.devint.dev-r5ead.net SRV service location: priority = 0 weight = 0 port = 5060 svr hostname = sip-registrar.devint.dev-r5ead.net

PS C:\Users\amccool\source\repos\amccool\sipgox> ..\gophone-windows.exe dial sip:a41r103b1@33333333-3333-3bad-c0de-333333333333.devint.dev-r5ead.net 09:03:37.326 DBG Dial > Dialing... recipient=sip:a41r103b1@33333333-3333-3bad-c0de-333333333333.devint.dev-r5ead.net 09:03:37.360 INF Dial > Listening on addr=172.18.26.74:65441 network=udp 09:03:37.364 DBG transportlayer > DNS Resolving host=33333333-3333-3bad-c0de-333333333333.devint.dev-r5ead.net 09:03:37.371 DBG transport > begin listening on UDP 172.18.26.74:65441 09:03:37.408 DBG IP addr resolving failed, doing via dns resolver error="lookup 33333333-3333-3bad-c0de-333333333333.devint.dev-r5ead.net: no such host" 09:03:37.415 WRN transportlayer > DNS resolution is slow dur=50.966 09:03:37.422 DBG transportlayer > Active connection not found addr=:5060 raddr=:5060 09:03:37.432 DBG transportlayer > Via header used for creating connection host=172.18.26.74 network=udp port=0 09:03:37.440 DBG transport > New connection raddr=:5060 09:03:37.450 DBG transactionLayer > Fail to write request on init error="udp conn 172.18.26.74:65444 err. write udp 172.18.26.74:65444->:5060: wsasendto: The requested address is not valid in its context." req="INVITE sip:a41r103b1@33333333-3333-3bad-c0de-333333333333.devint.dev-r5ead.net SIP/2.0" 09:03:37.459 DBG Dial > Closing listener addr=172.18.26.74:65441 09:03:37.46309:03:37.463 DBG transportERR > Read connection closed Dialerror= > "read udp 172.18.26.74:65441: use of closed network connection"Call failed addr=error=172.18.26.74:65441 "udp conn 172.18.26.74:65444 err. write udp 172.18.26.74:65444->:5060: wsasendto: The requested address is not valid in its context.. transaction transport error"09:03:37.475 DBG 09:03:37.477transport DBG >transactionLayer Read listener connection stopped >addr= transaction layer closed 172.18.26.74:65441 09:03:37.483 DBG transportlayer > Layer is closing 09:03:37.494 DBG UDP listener doing hard close ip=172.18.26.74:65444 ref=0 PS C:\Users\amccool\source\repos\amccool\sipgox>

emiago commented 6 months ago

hmm seems we have some skipped checks So SRV lookup did not failed, but question is did sipgo failed to parse IP. I see this line 09:03:37.415 WRN transportlayer > DNS resolution is slow dur=50.966 and connection got still created. In this case it is UDP but for TCP it would fail.

Here I added more logs in binary. So download from this comment in attach, and we should see at least response.

gophone-windows-amd64.zip

but bug is probably in sipgo library here https://github.com/emiago/sipgo/blob/54a4f2ad43f1c00b63bdc7ad0982aacb3891fa1b/sip/transport_layer.go#L439

emiago commented 6 months ago

hmm I think I know what is issue, with some latest refactoring, return value from SRV is probably not resolved to IP

amccool commented 6 months ago

using the new release. looks closer

DNS Resolving host=33333333-3333-3bad-c0de-333333333333.devint.dev-r5ead.net 12:56:05.945 DBG IP addr resolving failed, doing via dns resolver... error="lookup 33333333-3333-3bad-c0de-333333333333.devint.dev-r5ead.net: no such host" 12:56:05.948 DBG SRV resolved addrs=33333333-3333-3bad-c0de-333333333333.devint.dev-r5ead.net:5060 12:56:05.948 DBG Dial > Closing listener addr=172.18.26.74:64979 12:56:05.94912:56:05.949 DBG ERRtransport >Dial Read connection closed >error= "read udp 172.18.26.74:64979: use of closed network connection"Call failed addr=error=172.18.26.74:64979 "SRV resolving failed for \"sip-registrar.devint.dev-r5ead.net\""12:56:05.951 DBG transport12:56:05.951 > Read listener connection stopped DBG addr=transactionLayer172.18.26.74:64979 transaction layer closed 12:56:05.952 DBG transportlayer > Layer is closing

show me how to build this and I can sort out the data

emiago commented 6 months ago

gophone-windows-amd64.zip

Now I am sending you fix. This already landed on sipgo main, as I thought we have skipped resolving sip-registrar.devint.dev-r5ead.net Pls confirm that now works

amccool commented 6 months ago

same error. I see the sipgo change. gimme a hint on building the gophone.go. I dont see where the command line arguments are getting setup

emiago commented 6 months ago

@amccool Here https://github.com/emiago/sipgox?tab=readme-ov-file#dialer

Same code is invoked by gophone. If you figure out, push PR. Thnx

emiago commented 6 months ago

@amccool this is now definetely fixed. Checkout latest release. I have tested. So one problem could be that default was always local resolving first. You can pass -dns_srv to prefer DNS SRV lookup, and local will be as failover.