Class: Diameter::Peer
- Inherits:
-
Object
- Object
- Diameter::Peer
- Defined in:
- lib/diameter/peer.rb
Overview
A Diameter peer entry in the peer table.
Instance Attribute Summary collapse
-
#cxn ⇒ Object
- Socket
-
The underlying network connection to this peer.
-
#expiry_time ⇒ Object
- Time
-
For a dynamically discovered peer, the time when it stops being valid and dynamic discovery must happen again.
-
#identity ⇒ Object
- String
-
The DiameterIdentity of this peer.
-
#last_message_seen ⇒ Object
- Time
-
The last time traffic was received from this peer.
-
#realm ⇒ Object
- String
-
The Diameter realm of this peer.
-
#state ⇒ Object
- Keyword
-
The current state of this peer - :UP, :WATING or :CLOSED.
-
#static ⇒ Object
- true, false
-
Whether this peer was dynamically discovered (and so might expire) or statically configured.
Instance Method Summary collapse
-
#initialize(identity) ⇒ Peer
constructor
A new instance of Peer.
-
#reset_timer ⇒ Object
Resets the last message seen time.
-
#wait_for_state_change(state) ⇒ Object
Blocks until the state of this peer changes to the desired value.
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
#cxn ⇒ Object
- 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. = Time.now end end |
#expiry_time ⇒ Object
- 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. = Time.now end end |
#identity ⇒ Object
- 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. = Time.now end end |
#last_message_seen ⇒ Object
- 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. = Time.now end end |
#realm ⇒ Object
- 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. = Time.now end end |
#state ⇒ Object
- 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. = Time.now end end |
#static ⇒ Object
- 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. = Time.now end end |
Instance Method Details
#reset_timer ⇒ Object
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. = Time.now end |
#wait_for_state_change(state) ⇒ Object
Blocks until the state of this peer changes to the desired value.
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 |