ghettovoice / gosip

SIP in Go
BSD 2-Clause "Simplified" License
413 stars 90 forks source link

Why does the via header not carry the rport field? #27

Closed yangjiechina closed 3 years ago

yangjiechina commented 3 years ago

Hi GhettoVoice, gosip is a very good library, but in the public network environment, I initiated the registration, has not received the response of the server, capture packet analysis, is the request does not have the rport field caused. Here's my solution:

    // add empty cotent
hop, _ := msg.ViaHop() 
hop.Params.Add("rport",sip.String{""})

for _, conn := range p.connections.All() {
    parts := strings.Split(string(conn.Key()), ":")
    if parts[2] == port {
        logger := log.AddFieldsFrom(p.Log(), conn, msg)
        logger.Tracef("writing SIP message to %s %s", p.Network(), raddr)

        if _, err = conn.WriteTo([]byte(msg.String()), raddr); err != nil {
            return &ProtocolError{
                Err:      err,
                Op:       fmt.Sprintf("write SIP message to the %s connection", conn.Key()),
                ProtoPtr: fmt.Sprintf("%p", p),
            }
        }

        return nil
    }
}
yangjiechina commented 3 years ago

5060_3.zip

yangjiechina commented 3 years ago

5060_3.zip

This is My capture packets. The previous failed to use the GOSIP library, the later successful use the EXOSIP library

ghettovoice commented 3 years ago

Hello @yangjiechina , do you sure that you are using latest version from master?

Current master version sends via UDP transport from the same port where it listening, so no need to append rport. Sure only if gosip is running in the public network. If behind NAT then you also need to append rport to each outbound request, so the remote ua will be restricted to respond on the port from which the request arrived.