Class: OverSIP::SIP::InviteServerTransaction

Inherits:
ServerTransaction show all
Defined in:
lib/oversip/sip/server_transaction.rb

Instance Attribute Summary

Attributes inherited from ServerTransaction

#core, #last_response, #request, #state

Instance Method Summary collapse

Methods inherited from ServerTransaction

#retransmit_last_response

Methods included from Logger

fg_system_msg2str, load_methods, #log_id

Constructor Details

#initialize(request) ⇒ InviteServerTransaction

Returns a new instance of InviteServerTransaction.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/oversip/sip/server_transaction.rb', line 26

def initialize request
  super
  @request.connection.class.invite_server_transactions[@transaction_id] = self

  @log_id = "IST #{@transaction_id}"
  # Can be :proceeding, :completed, :confirmed, :accepted or :terminated.
  @state = :proceeding

  # NOTE: This is a timer of INVITE client transactions, but we also need it here to avoid
  # that an INVITE server transaction never ends.
  start_timer_C2

  @request.reply 100
end

Instance Method Details

#receive_ackObject

This method is called by SipReactor#check_transaction upon receipt of an ACK matching an INVITE transaction (so it has been rejected with [3456]XX).



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/oversip/sip/server_transaction.rb', line 83

def receive_ack
  case @state
  when :proceeding
    log_system_debug "ACK received during proceeding state, ignoring it"  if $oversip_debug
  when :completed
    log_system_debug "ACK received during completed state, now confirmed"  if $oversip_debug
    @state = :confirmed
    @timer_G.cancel  if @timer_G
    @timer_H.cancel
    if @request.transport == :udp
      start_timer_I
    else
      terminate_transaction
    end
  else
    log_system_debug "ACK received during #{@state} state, ignoring it"  if $oversip_debug
  end
end

#receive_cancel(cancel) ⇒ Object

This method is called by SipReactor#check_transaction upon receipt of an CANCEL matching an INVITE transaction.



104
105
106
# File 'lib/oversip/sip/server_transaction.rb', line 104

def receive_cancel cancel
  @core.receive_cancel(cancel)  if @core
end

#receive_response(status_code) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/oversip/sip/server_transaction.rb', line 114

def receive_response status_code
  # Provisional response
  if status_code < 200
    case @state
    when :proceeding
      return true
    else
      log_system_notice "attempt to send a provisional response while in #{@state} state"
      return false
    end

  # 2XX final response.
  elsif status_code >= 200 and status_code < 300
    case @state
    when :proceeding
      @state = :accepted
      @timer_C2.cancel
      start_timer_L
      return true
    when :accepted
      return true
    else
      log_system_notice "attempt to send a final 2XX response while in #{@state} state"
      return false
    end

  # [3456]XX final response.
  else
    case @state
    when :proceeding
      @state = :completed
      @timer_C2.cancel
      start_timer_G if @request.transport == :udp
      start_timer_H
      return true
    else
      log_system_notice "attempt to send a final #{status_code} response while in #{@state} state"
      return false
    end
  end
end

#start_timer_C2Object

Timer to delete the transaction if final response is never sent by the TU.



74
75
76
77
78
79
# File 'lib/oversip/sip/server_transaction.rb', line 74

def start_timer_C2
  @timer_C2 = ::EM::Timer.new(TIMER_C2) do
    log_system_debug "no final response within #{TIMER_C2} seconds, transaction terminated"  if $oversip_debug
    terminate_transaction
  end
end

#start_timer_GObject



41
42
43
44
45
46
47
48
# File 'lib/oversip/sip/server_transaction.rb', line 41

def start_timer_G
  @timer_G_interval = TIMER_G
  @timer_G = ::EM::PeriodicTimer.new(@timer_G_interval) do
    log_system_debug "timer G expires, retransmitting last response"  if $oversip_debug
    retransmit_last_response
    @timer_G_interval = @timer_G.interval = [2*@timer_G_interval, T2].min
  end
end

#start_timer_HObject



50
51
52
53
54
55
56
# File 'lib/oversip/sip/server_transaction.rb', line 50

def start_timer_H
  @timer_H = ::EM::Timer.new(TIMER_H) do
    log_system_debug "timer H expires and no ACK received, transaction terminated"  if $oversip_debug
    terminate_transaction
    @timer_G.cancel  if @timer_G
  end
end

#start_timer_IObject



58
59
60
61
62
63
# File 'lib/oversip/sip/server_transaction.rb', line 58

def start_timer_I
  ::EM.add_timer(TIMER_I_UDP) do
    log_system_debug "timer I expires, transaction terminated"  if $oversip_debug
    terminate_transaction
  end
end

#start_timer_LObject

RFC 6026.



66
67
68
69
70
71
# File 'lib/oversip/sip/server_transaction.rb', line 66

def start_timer_L
  ::EM.add_timer(TIMER_L) do
    log_system_debug "timer L expires, transaction terminated"  if $oversip_debug
    terminate_transaction
  end
end

#terminate_transactionObject

Terminate current transaction and delete from the list of transactions.



109
110
111
112
# File 'lib/oversip/sip/server_transaction.rb', line 109

def terminate_transaction
  @state = :terminated
  @request.connection.class.invite_server_transactions.delete(@transaction_id)
end

#valid_response?(status_code) ⇒ Boolean

Returns:

  • (Boolean)


156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/oversip/sip/server_transaction.rb', line 156

def valid_response? status_code
  # Provisional response
  if status_code < 200
    case @state
    when :proceeding
      return true
    else
      return false
    end

  # 2XX final response.
  elsif status_code >= 200 and status_code < 300
    case @state
    when :proceeding
      return true
    when :accepted
      return true
    else
      return false
    end

    # [3456]XX final response.
  else
    case @state
    when :proceeding
      return true
    else
      return false
    end
  end
end