Class: Diameter::Peer

Inherits:
Object
  • Object
show all
Defined in:
lib/diameter/peer.rb

Overview

A Diameter peer entry in the peer table.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identity) ⇒ Peer

Returns a new instance of Peer.



28
29
30
31
32
# File 'lib/diameter/peer.rb', line 28

def initialize(identity)
  @identity = identity
  @state = :CLOSED
  @state_change_q = Queue.new
end

Instance Attribute Details

#cxnObject

Socket

The underlying network connection to this peer.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/diameter/peer.rb', line 24

class Peer
  attr_accessor :identity, :static, :cxn, :realm, :expiry_time, :last_message_seen
  attr_reader :state

  def initialize(identity)
    @identity = identity
    @state = :CLOSED
    @state_change_q = Queue.new
  end

  # Blocks until the state of this peer changes to the desired value.
  #
  # @param state [Keyword] The state to change to.
  def wait_for_state_change(state)
    cur_state = @state
    while (cur_state != state)
      cur_state = @state_change_q.pop
    end
  end

  # @todo Add further checking, making sure that the transition to
  # new_state is valid according to the RFC 6733 state machine. Maybe
  # use the micromachine gem?
  def state=(new_state)
    Diameter.logger.log(Logger::DEBUG, "State of peer #{identity} changed from #{@state} to #{new_state}")
    @state = new_state
    @state_change_q.push new_state
  end

  # Resets the last message seen time. Should be called when a message
  # is received from this peer.
  def reset_timer
    self.last_message_seen = Time.now
  end
end

#expiry_timeObject

Time

For a dynamically discovered peer, the time when it stops

being valid and dynamic discovery must happen again.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/diameter/peer.rb', line 24

class Peer
  attr_accessor :identity, :static, :cxn, :realm, :expiry_time, :last_message_seen
  attr_reader :state

  def initialize(identity)
    @identity = identity
    @state = :CLOSED
    @state_change_q = Queue.new
  end

  # Blocks until the state of this peer changes to the desired value.
  #
  # @param state [Keyword] The state to change to.
  def wait_for_state_change(state)
    cur_state = @state
    while (cur_state != state)
      cur_state = @state_change_q.pop
    end
  end

  # @todo Add further checking, making sure that the transition to
  # new_state is valid according to the RFC 6733 state machine. Maybe
  # use the micromachine gem?
  def state=(new_state)
    Diameter.logger.log(Logger::DEBUG, "State of peer #{identity} changed from #{@state} to #{new_state}")
    @state = new_state
    @state_change_q.push new_state
  end

  # Resets the last message seen time. Should be called when a message
  # is received from this peer.
  def reset_timer
    self.last_message_seen = Time.now
  end
end

#identityObject

String

The DiameterIdentity of this peer



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/diameter/peer.rb', line 24

class Peer
  attr_accessor :identity, :static, :cxn, :realm, :expiry_time, :last_message_seen
  attr_reader :state

  def initialize(identity)
    @identity = identity
    @state = :CLOSED
    @state_change_q = Queue.new
  end

  # Blocks until the state of this peer changes to the desired value.
  #
  # @param state [Keyword] The state to change to.
  def wait_for_state_change(state)
    cur_state = @state
    while (cur_state != state)
      cur_state = @state_change_q.pop
    end
  end

  # @todo Add further checking, making sure that the transition to
  # new_state is valid according to the RFC 6733 state machine. Maybe
  # use the micromachine gem?
  def state=(new_state)
    Diameter.logger.log(Logger::DEBUG, "State of peer #{identity} changed from #{@state} to #{new_state}")
    @state = new_state
    @state_change_q.push new_state
  end

  # Resets the last message seen time. Should be called when a message
  # is received from this peer.
  def reset_timer
    self.last_message_seen = Time.now
  end
end

#last_message_seenObject

Time

The last time traffic was received from this peer. Used for

determining when to send watchdog messages, or for triggering failover.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/diameter/peer.rb', line 24

class Peer
  attr_accessor :identity, :static, :cxn, :realm, :expiry_time, :last_message_seen
  attr_reader :state

  def initialize(identity)
    @identity = identity
    @state = :CLOSED
    @state_change_q = Queue.new
  end

  # Blocks until the state of this peer changes to the desired value.
  #
  # @param state [Keyword] The state to change to.
  def wait_for_state_change(state)
    cur_state = @state
    while (cur_state != state)
      cur_state = @state_change_q.pop
    end
  end

  # @todo Add further checking, making sure that the transition to
  # new_state is valid according to the RFC 6733 state machine. Maybe
  # use the micromachine gem?
  def state=(new_state)
    Diameter.logger.log(Logger::DEBUG, "State of peer #{identity} changed from #{@state} to #{new_state}")
    @state = new_state
    @state_change_q.push new_state
  end

  # Resets the last message seen time. Should be called when a message
  # is received from this peer.
  def reset_timer
    self.last_message_seen = Time.now
  end
end

#realmObject

String

The Diameter realm of this peer



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/diameter/peer.rb', line 24

class Peer
  attr_accessor :identity, :static, :cxn, :realm, :expiry_time, :last_message_seen
  attr_reader :state

  def initialize(identity)
    @identity = identity
    @state = :CLOSED
    @state_change_q = Queue.new
  end

  # Blocks until the state of this peer changes to the desired value.
  #
  # @param state [Keyword] The state to change to.
  def wait_for_state_change(state)
    cur_state = @state
    while (cur_state != state)
      cur_state = @state_change_q.pop
    end
  end

  # @todo Add further checking, making sure that the transition to
  # new_state is valid according to the RFC 6733 state machine. Maybe
  # use the micromachine gem?
  def state=(new_state)
    Diameter.logger.log(Logger::DEBUG, "State of peer #{identity} changed from #{@state} to #{new_state}")
    @state = new_state
    @state_change_q.push new_state
  end

  # Resets the last message seen time. Should be called when a message
  # is received from this peer.
  def reset_timer
    self.last_message_seen = Time.now
  end
end

#stateObject

Keyword

The current state of this peer - :UP, :WATING or :CLOSED.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/diameter/peer.rb', line 24

class Peer
  attr_accessor :identity, :static, :cxn, :realm, :expiry_time, :last_message_seen
  attr_reader :state

  def initialize(identity)
    @identity = identity
    @state = :CLOSED
    @state_change_q = Queue.new
  end

  # Blocks until the state of this peer changes to the desired value.
  #
  # @param state [Keyword] The state to change to.
  def wait_for_state_change(state)
    cur_state = @state
    while (cur_state != state)
      cur_state = @state_change_q.pop
    end
  end

  # @todo Add further checking, making sure that the transition to
  # new_state is valid according to the RFC 6733 state machine. Maybe
  # use the micromachine gem?
  def state=(new_state)
    Diameter.logger.log(Logger::DEBUG, "State of peer #{identity} changed from #{@state} to #{new_state}")
    @state = new_state
    @state_change_q.push new_state
  end

  # Resets the last message seen time. Should be called when a message
  # is received from this peer.
  def reset_timer
    self.last_message_seen = Time.now
  end
end

#staticObject

true, false

Whether this peer was dynamically discovered (and so

might expire) or statically configured.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/diameter/peer.rb', line 24

class Peer
  attr_accessor :identity, :static, :cxn, :realm, :expiry_time, :last_message_seen
  attr_reader :state

  def initialize(identity)
    @identity = identity
    @state = :CLOSED
    @state_change_q = Queue.new
  end

  # Blocks until the state of this peer changes to the desired value.
  #
  # @param state [Keyword] The state to change to.
  def wait_for_state_change(state)
    cur_state = @state
    while (cur_state != state)
      cur_state = @state_change_q.pop
    end
  end

  # @todo Add further checking, making sure that the transition to
  # new_state is valid according to the RFC 6733 state machine. Maybe
  # use the micromachine gem?
  def state=(new_state)
    Diameter.logger.log(Logger::DEBUG, "State of peer #{identity} changed from #{@state} to #{new_state}")
    @state = new_state
    @state_change_q.push new_state
  end

  # Resets the last message seen time. Should be called when a message
  # is received from this peer.
  def reset_timer
    self.last_message_seen = Time.now
  end
end

Instance Method Details

#reset_timerObject

Resets the last message seen time. Should be called when a message is received from this peer.



55
56
57
# File 'lib/diameter/peer.rb', line 55

def reset_timer
  self.last_message_seen = Time.now
end

#wait_for_state_change(state) ⇒ Object

Blocks until the state of this peer changes to the desired value.

Parameters:

  • state (Keyword)

    The state to change to.



37
38
39
40
41
42
# File 'lib/diameter/peer.rb', line 37

def wait_for_state_change(state)
  cur_state = @state
  while (cur_state != state)
    cur_state = @state_change_q.pop
  end
end