Class: OverSIP::SIP::NonInviteClientTransaction

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

Constant Summary

Constants included from Logger

Logger::SYSLOG_POSIXMQ_MAPPING

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, #fatal, 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.



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

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



543
544
545
546
547
548
549
# File 'lib/oversip/sip/client_transaction.rb', line 543

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

  @core.connection_failed
end

#receive_response(response) ⇒ Object



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
539
540
541
# File 'lib/oversip/sip/client_transaction.rb', line 499

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



495
496
497
# File 'lib/oversip/sip/client_transaction.rb', line 495

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

#send_requestObject



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
456
457
458
# File 'lib/oversip/sip/client_transaction.rb', line 395

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

  @request_leg_b = @request.to_s

  @connection.send_sip_msg @request_leg_b, @ip, @port

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

  start_timer_E  if @transport == :udp
  start_timer_F

  true
end

#start_timer_EObject



460
461
462
463
464
465
466
467
468
469
470
471
# File 'lib/oversip/sip/client_transaction.rb', line 460

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



473
474
475
476
477
478
479
480
# File 'lib/oversip/sip/client_transaction.rb', line 473

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



482
483
484
485
486
487
# File 'lib/oversip/sip/client_transaction.rb', line 482

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.



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

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

#tls_validation_failedObject



551
552
553
554
555
556
557
# File 'lib/oversip/sip/client_transaction.rb', line 551

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

  @core.tls_validation_failed
end