Skip to content

Commit dd43b6d

Browse files
committed
fix: support also sip srv with different sip scheme #155
1 parent 9bbb4fe commit dd43b6d

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

sip/transaction_client_tx_fsm.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ func (tx *ClientTx) actInviteProceeding() fsmInput {
257257
}
258258

259259
func (tx *ClientTx) actInviteFinal() fsmInput {
260-
// tx.Log().Debug("actInviteFinal")
261260

262261
tx.ack()
263262
tx.fsmPassUp()
@@ -273,8 +272,6 @@ func (tx *ClientTx) actInviteFinal() fsmInput {
273272
tx.timer_b = nil
274273
}
275274

276-
// tx.Log().Tracef("timer_d set to %v", tx.timer_d_time)
277-
278275
tx.timer_d = time.AfterFunc(tx.timer_d_time, func() {
279276
tx.spinFsm(client_input_timer_d)
280277
})

sip/transport_layer.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ func (l *TransportLayer) ClientRequestConnection(ctx context.Context, req *Reque
366366
}
367367

368368
if raddr.IP == nil {
369-
if err := l.resolveAddr(ctx, network, host, &raddr); err != nil {
369+
if err := l.resolveAddr(ctx, network, host, req.Recipient.Scheme, &raddr); err != nil {
370370
return nil, err
371371
}
372372

@@ -454,7 +454,7 @@ func (l *TransportLayer) overrideSentBy(c Connection, viaHop *ViaHeader) error {
454454
return nil
455455
}
456456

457-
func (l *TransportLayer) resolveAddr(ctx context.Context, network string, host string, addr *Addr) error {
457+
func (l *TransportLayer) resolveAddr(ctx context.Context, network string, host string, sipScheme string, addr *Addr) error {
458458
log := l.log
459459
defer func(start time.Time) {
460460
if dur := time.Since(start); dur > 50*time.Millisecond {
@@ -463,7 +463,7 @@ func (l *TransportLayer) resolveAddr(ctx context.Context, network string, host s
463463
}(time.Now())
464464

465465
if l.DNSPreferSRV {
466-
err := l.resolveAddrSRV(ctx, network, host, addr)
466+
err := l.resolveAddrSRV(ctx, network, host, sipScheme, addr)
467467
if err == nil {
468468
return nil
469469
}
@@ -477,7 +477,7 @@ func (l *TransportLayer) resolveAddr(ctx context.Context, network string, host s
477477
}
478478

479479
log.Info("IP addr resolving failed, doing via dns SRV resolver...", "error", err)
480-
return l.resolveAddrSRV(ctx, network, host, addr)
480+
return l.resolveAddrSRV(ctx, network, host, sipScheme, addr)
481481
}
482482

483483
func (l *TransportLayer) resolveAddrIP(ctx context.Context, hostname string, addr *Addr) error {
@@ -505,7 +505,7 @@ func (l *TransportLayer) resolveAddrIP(ctx context.Context, hostname string, add
505505
return nil
506506
}
507507

508-
func (l *TransportLayer) resolveAddrSRV(ctx context.Context, network string, hostname string, addr *Addr) error {
508+
func (l *TransportLayer) resolveAddrSRV(ctx context.Context, network string, hostname string, sipScheme string, addr *Addr) error {
509509
log := l.log
510510
var proto string
511511
switch network {
@@ -517,11 +517,11 @@ func (l *TransportLayer) resolveAddrSRV(ctx context.Context, network string, hos
517517
proto = "tcp"
518518
}
519519

520-
log.Debug("Doing SRV lookup", "proto", proto, "host", hostname)
520+
log.Debug("Doing SRV lookup", "scheme", sipScheme, "proto", proto, "host", hostname)
521521

522522
// The returned records are sorted by priority and randomized
523523
// by weight within a priority.
524-
_, addrs, err := l.dnsResolver.LookupSRV(ctx, "sip", proto, hostname)
524+
_, addrs, err := l.dnsResolver.LookupSRV(ctx, sipScheme, proto, hostname)
525525
if err != nil {
526526
return fmt.Errorf("fail to lookup SRV for %q: %w", hostname, err)
527527
}

sip/transport_layer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func TestTransportLayerResolving(t *testing.T) {
160160

161161
tp := NewTransportLayer(net.DefaultResolver, NewParser(), nil)
162162
addr := Addr{}
163-
err := tp.resolveAddr(context.TODO(), "udp", "localhost", &addr)
163+
err := tp.resolveAddr(context.TODO(), "udp", "localhost", "sip", &addr)
164164
require.NoError(t, err)
165165

166166
assert.True(t, addr.IP.To4() != nil)

0 commit comments

Comments
 (0)