Class: OverSIP::SIP::NonInviteClientTransaction

Inherits:
ClientTransaction show all
Defined in:
lib/oversip/sip/client_transaction.rb

Instance Attribute Summary

Attributes inherited from ClientTransaction

#connection, #core, #request, #state

Instance Method Summary collapse

Methods inherited from ClientTransaction

get_class

Methods included from Logger

close, fg_system_msg2str, init_logger_mq, load_methods, #log_id, syslog_system_msg2str, syslog_user_msg2str

Constructor Details

#initialize(core, request, transaction_conf, transport, ip = nil, ip_type = nil, port = nil) ⇒ NonInviteClientTransaction

Returns a new instance of NonInviteClientTransaction.



386
387
388
389
390
391
392
# File 'lib/oversip/sip/client_transaction.rb', line 386

def initialize core, request, transaction_conf, transport, ip=nil, ip_type=nil, port=nil
  super
  @log_id = "NICT #{@transaction_id}"

  # Can be :trying, :proceeding, :completed or :terminated.
  @state = :trying
end

Instance Method Details

#connection_failedObject



540
541
542
543
544
545
546
# File 'lib/oversip/sip/client_transaction.rb', line 540

def connection_failed
  @timer_F.cancel
  @timer_E.cancel  if @timer_E
  terminate_transaction

  @core.connection_failed
end

#receive_response(response) ⇒ Object



496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
# File 'lib/oversip/sip/client_transaction.rb', line 496

def receive_response response
  # Set the request attribute to the response so we can access the related outgoing request.
  response.request = @request

  # Set server transaction variables to the response.
  response.tvars = @request.tvars

  # Provisional response
  if response.status_code < 200
    case @state
    when :trying
      @state = :proceeding
      @core.receive_response(response) unless response.status_code == 100
      return true
    when :proceeding
      @core.receive_response(response) unless response.status_code == 100
      return true
    else
      log_system_notice "received a provisional response #{response.status_code} while in #{@state} state"
      return false
    end

  # [23456]XX final response.
  elsif response.status_code >= 200
    case @state
    when :trying, :proceeding
      @state = :completed
      @timer_F.cancel
      @timer_E.cancel  if @timer_E
      if @transport == :udp
        start_timer_K
      else
        terminate_transaction
      end
      @core.receive_response(response)
      return true
    else
      log_system_notice "received a final response #{response.status_code} while in #{@state} state"
      return false
    end

  end
end

#retransmit_requestObject



492
493
494
# File 'lib/oversip/sip/client_transaction.rb', line 492

def retransmit_request
  @connection.send_sip_msg @outgoing_request_str, @ip, @port
end

#send_requestObject



394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# File 'lib/oversip/sip/client_transaction.rb', line 394

def send_request
  @client_transactions = @server_klass.non_invite_client_transactions
  # Store the new client transaction.
  @client_transactions[@transaction_id] = self

  @top_via = "#{@server_klass.via_core};branch=z9hG4bK#{@transaction_id};rport"
  @request.insert_header "Via", @top_via

  case @request.in_rr
  # Add a second Record-Route just in case there is transport change.
  when :rr
    unless @request.connection.is_a?(@server_klass)
      @out_rr = :rr
      @request.insert_header "Record-Route", @server_klass.record_route
    end
  # When there is outgoing Outbound always add a second Record-Route header.
  when :outgoing_outbound_rr
    @out_rr = :rr
    @request.insert_header "Record-Route", @server_klass.record_route
  # When there is incoming Outbound always add a second Record-Route header containing the flow token.
  when :incoming_outbound_rr
    @out_rr = :rr
    @request.insert_header "Record-Route", "<sip:" << @request.route_outbound_flow_token << @server_klass.outbound_record_route_fragment
  # When there is both outgoing/incoming Outbound always add a second Record-Route header containing the flow token.
  when :both_outbound_rr
    @out_rr = :rr
    @request.insert_header "Record-Route", "<sip:" << @request.route_outbound_flow_token << @server_klass.outbound_record_route_fragment
  # Add a second Path just in case there is transport change.
  when :path
    unless @request.connection.is_a?(@server_klass)
      @out_rr = :path
      @request.insert_header "Path", @server_klass.record_route
    end
  # When there is outgoing Outbound always add a second Path header.
  when :outgoing_outbound_path
    @out_rr = :path
    @request.insert_header "Path", @server_klass.record_route
  # When there is incoming Outbound always add a second Path header containing the flow token.
  when :incoming_outbound_path
    @out_rr = :path
    @request.insert_header "Path", "<sip:" << @request.route_outbound_flow_token << @server_klass.outbound_path_fragment
  # When there is both outgoing/incoming Outbound always add a second Path header containing the flow token.
  when :both_outbound_path
    @out_rr = :rr
    @request.insert_header "Path", "<sip:" << @request.route_outbound_flow_token << @server_klass.outbound_path_fragment
  end  if @core.is_a? ::OverSIP::SIP::Proxy

  @outgoing_request_str = @request.to_s

  @request.delete_header_top "Via"
  case @out_rr
  when :rr
    @request.delete_header_top "Record-Route"
  when :path
    @request.delete_header_top "Path"
  end

  @connection.send_sip_msg @outgoing_request_str, @ip, @port

  start_timer_E  if @transport == :udp
  start_timer_F
end

#start_timer_EObject



457
458
459
460
461
462
463
464
465
466
467
468
# File 'lib/oversip/sip/client_transaction.rb', line 457

def start_timer_E
  @timer_E_interval = TIMER_E
  @timer_E = ::EM::PeriodicTimer.new(@timer_E_interval) do
    log_system_debug "timer E expires, retransmitting request"  if $oversip_debug
    retransmit_request
    if @state == :trying
      @timer_E_interval = @timer_E.interval = [2*@timer_E_interval, T2].min
    else
      @timer_E_interval = @timer_E.interval = T2
    end
  end
end

#start_timer_FObject



470
471
472
473
474
475
476
477
# File 'lib/oversip/sip/client_transaction.rb', line 470

def start_timer_F
  @timer_F = ::EM::Timer.new(@transaction_conf[:timer_F] || TIMER_F) do
    log_system_debug "timer F expires, transaction timeout"  if $oversip_debug
    @timer_E.cancel  if @timer_E
    terminate_transaction
    @core.client_timeout
  end
end

#start_timer_KObject



479
480
481
482
483
484
# File 'lib/oversip/sip/client_transaction.rb', line 479

def start_timer_K
  ::EM.add_timer(TIMER_K_UDP) do
    log_system_debug "timer K expires, transaction terminated"  if $oversip_debug
    terminate_transaction
  end
end

#terminate_transactionObject

Terminate current transaction and delete from the list of transactions.



487
488
489
490
# File 'lib/oversip/sip/client_transaction.rb', line 487

def terminate_transaction
  @state = :terminated
  @client_transactions.delete(@transaction_id)
end

#tls_validation_failedObject



548
549
550
551
552
553
554
# File 'lib/oversip/sip/client_transaction.rb', line 548

def tls_validation_failed
  @timer_F.cancel
  @timer_E.cancel  if @timer_E
  terminate_transaction

  @core.tls_validation_failed
end