Class: OverSIP::SIP::NonInviteServerTransaction

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) ⇒ NonInviteServerTransaction

Returns a new instance of NonInviteServerTransaction.



193
194
195
196
197
198
199
200
201
202
# File 'lib/oversip/sip/server_transaction.rb', line 193

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

  @log_id = "NIST #{@transaction_id}"
  # Can be :trying, :proceeding, :completed or :terminated.
  @state = :trying

  start_timer_INT1
end

Instance Method Details

#receive_response(status_code) ⇒ Object



236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/oversip/sip/server_transaction.rb', line 236

def receive_response(status_code)
  # Provisional response
  if status_code < 200
    case @state
    when :trying
      @state = :proceeding
      return true
    when :proceeding
      return true
    when :completed, :terminated
      log_system_notice "attempt to send a provisional response while in #{@state} state"
      return false
    end

  # Final response.
  else
    case @state
    when :trying, :proceeding
      @timer_INT1.cancel
      @timer_INT2.cancel  if @timer_INT2
      @state = :completed
      if @request.transport == :udp
        start_timer_J
      else
        terminate_transaction
      end
      return true
    when :completed, :terminated
      log_system_notice "attempt to send a final response while in #{@state} state"
      return false
    end
  end
end

#start_timer_INT1Object

RFC 4320 - Section 4.1.



205
206
207
208
209
210
211
212
213
# File 'lib/oversip/sip/server_transaction.rb', line 205

def start_timer_INT1
  @timer_INT1 = ::EM::Timer.new(INT1) do
    unless @last_response
      log_system_debug "no final response within #{INT1} seconds => 100"  if $oversip_debug
      @request.reply 100, "I'm alive"
    end
    start_timer_INT2
  end
end

#start_timer_INT2Object

RFC 4320 - Section 4.2.



216
217
218
219
220
221
# File 'lib/oversip/sip/server_transaction.rb', line 216

def start_timer_INT2
  @timer_INT2 = ::EM::Timer.new(INT2) do
    log_system_debug "no final response within #{INT1+INT2} seconds, transaction terminated"  if $oversip_debug
    terminate_transaction
  end
end

#start_timer_JObject



223
224
225
226
227
228
# File 'lib/oversip/sip/server_transaction.rb', line 223

def start_timer_J
  ::EM.add_timer(TIMER_J_UDP) do
    log_system_debug "timer J expires, transaction terminated"  if $oversip_debug
    terminate_transaction
  end
end

#terminate_transactionObject

Terminate current transaction and delete from the list of transactions.



231
232
233
234
# File 'lib/oversip/sip/server_transaction.rb', line 231

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

#valid_response?(status_code) ⇒ Boolean

Returns:

  • (Boolean)


270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/oversip/sip/server_transaction.rb', line 270

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

  # Final response.
  else
    case @state
    when :trying, :proceeding
      return true
    when :completed, :terminated
      return false
    end
  end
end