emiago / sipgox

Extra libs for sipgo
BSD 2-Clause "Simplified" License
63 stars 8 forks source link

Possible to call from unreachable network? #16

Open 0xffffa opened 1 week ago

0xffffa commented 1 week ago

When attempting to make an outbound call using a sip server from an unreachable network I get the error below, is it possible to make an outbound call from an unreachable network?

"error":"udp conn 192.168.56.1:65484 err. write udp 192.168.56.1:65484->199.87.144.66:5060: wsasendto: A socket operation was attempted to an unreachable network."

{"level":"debug","caller":"transactionLayer","error":"udp conn 192.168.56.1:65484 err. write udp 192.168.56.1:65484->199.87.144.66:5060: wsasendto: A socket operation was attempted to an unreachable network.","req":"REGISTER sip:user@siperserver.com:5060 SIP/2.0","time":"2024-10-13T00:58:04-04:00","message":"Fail to write request on init"}

The code used:

    var (
        // Callcentric SIP account details
        sipUsername       = "username"
        sipPassword       = "password"
        sipDomain         = "sipserver.com"
        sipPort           = 5060
        destinationNumber = "" // The number you want to call
    )
    ua, _ := sipgo.NewUA(sipgo.WithUserAgentHostname(sipDomain))
    defer ua.Close()

    phone := sipgox.NewPhone(ua)

    // Run dial
    ctx, _ := context.WithTimeout(context.Background(), 30*time.Second)

    // Blocks until call is answered
    dialog, err := phone.Dial(ctx, sip.Uri{User: destinationNumber, Host: sipDomain, Port: sipPort}, sipgox.DialOptions{
        Username: sipUsername,
        Password: sipPassword,
    })
    if err != nil {
        panic(err)
    }
    defer dialog.Close() // Close dialog for cleanup

    select {
    case <-dialog.Context().Done():
        return
    case <-time.After(5 * time.Second):
        dialog.Hangup(context.TODO())
    }
emiago commented 1 week ago

currently sipgo is choosing one of interfaces you have, and it is not taking in account routing. You have to tell sipgox phone on which interface to listen to avoid above problem.

0xffffa commented 1 week ago

currently sipgo is choosing one of interfaces you have, and it is not taking in account routing. You have to tell sipgox phone on which interface to listen to avoid above problem.

But this would require an open port regardless of the interface right?

emiago commented 1 week ago

well all other network issues you have to take in account. it is p2p

0xffffa commented 1 week ago

well all other network issues you have to take in account. it is p2p

Okay sorry I'm a bit new to voip and sip systems. But to clarify for anyone else wondering, I need to setup a pbx to get around this issue and use that as the interface?

The ultimate endgoal is to use my sip trunk provider to make a call to pstn from golang. From my knowledge its sip client -> siptrunk provider -> sip trunk handles outbound call to pstn and relays back to you or is this incorrect?

emiago commented 1 week ago

routing back is not simple in case of call. So that is why you need to make sure you are reachable or your provider. Specially due to NAT. SIP uses Contact header to let other side how to be reachable, which is basically here limited to binding on interface. but there are also other. I think I have built in some NAT handling in sipgox.

Anyway checkout also diago, as it allows also external (public IP) transport build. sipgox is very limited. You may see this on diago.Transport structure, but you can also override default client

emiago commented 1 week ago

I would like to fix any issue more on diago project than here.