Browse Source

fix: use real port to request and add go.mod

pull/9/head
chaslin 6 years ago
committed by Justine Tunney
parent
commit
89db24411f
5 changed files with 42 additions and 9 deletions
  1. +5
    -0
      .gitignore
  2. +3
    -0
      go.mod
  3. +0
    -0
      go.sum
  4. +15
    -5
      sip/receiver.go
  5. +19
    -4
      sip/route.go

+ 5
- 0
.gitignore View File

@ -1,2 +1,7 @@
*.test
/fone/fone
.*
/sftp-config.json
/main
/main.go
/main_test.go

+ 3
- 0
go.mod View File

@ -0,0 +1,3 @@
module github.com/jart/gosip
go 1.14

+ 0
- 0
go.sum View File


+ 15
- 5
sip/receiver.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -59,8 +59,18 @@ func addReceived(msg *Msg, addr *net.UDPAddr) {
return
}
if int(msg.Via.Port) != addr.Port {
if msg.Via.Param.Get("rport") == nil {
msg.Via.Param = &Param{"rport", string(addr.Port), msg.Via.Param}
rport := msg.Via.Param.Get("rport")
port := strconv.Itoa(addr.Port)
if rport == nil {
msg.Via.Param = &Param{"rport", port, msg.Via.Param}
} else {
// implied rport is 5060, but some NAT will use another port,we use real port instead
if len(rport.Value) == 0 {
rport.Value = port
}
}
}
if msg.Via.Host != addr.IP.String() {


+ 19
- 4
sip/route.go View File

@ -1,11 +1,11 @@
// Copyright 2020 Justine Alexandra Roberts Tunney
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -16,9 +16,11 @@ package sip
import (
"errors"
"github.com/jart/gosip/util"
"log"
"net"
"strconv"
"github.com/jart/gosip/util"
)
type AddressRoute struct {
@ -70,10 +72,23 @@ func RouteMessage(via *Via, contact *Addr, msg *Msg) (host string, port uint16,
if via.CompareHostPort(msg.Via) {
msg.Via = msg.Via.Next
}
host, port = msg.Via.Host, msg.Via.Port
if received := msg.Via.Param.Get("received"); received != nil {
host = received.Value
}
// fix: Get real port from rport field.
// Request path like UAC->NAT->UAS will change port(according to NAT type) sometime,
// we should use rport as real port in request-line
if rport := msg.Via.Param.Get("rport"); rport != nil && len(rport.Value) > 0 {
i, err := strconv.ParseInt(rport.Value, 10, 16)
if err != nil {
return "", 0, err
}
port = uint16(i)
}
} else {
if contact.CompareHostPort(msg.Route) {
msg.Route = msg.Route.Next


Loading…
Cancel
Save