Class: Peer
- Inherits:
-
Object
- Object
- Peer
- Defined in:
- lib/diameter/stack.rb
Overview
A Diameter peer entry in the peer table.
Instance Attribute Summary (collapse)
-
- (Object) cxn
- Socket
-
The underlying network connection to this peer.
-
- (Object) expiry_time
- Time
-
For a dynamically discovered peer, the time when it stops being valid and dynamic discovery must happen again.
-
- (Object) identity
- String
-
The DiameterIdentity of this peer.
-
- (Object) last_message_seen
- Time
-
The last time traffic was received from this peer.
-
- (Object) realm
- String
-
The Diameter realm of this peer.
-
- (Object) state
- Keyword
-
The current state of this peer - :UP, :WATING or :CLOSED.
-
- (Object) static
- true, false
-
Whether this peer was dynamically discovered (and so might expire) or statically configured.
Instance Method Summary (collapse)
-
- (Peer) initialize(identity)
constructor
A new instance of Peer.
-
- (Object) reset_timer
Resets the last message seen time.
-
- (Object) wait_for_state_change(state)
Blocks until the state of this peer changes to the desired value.
Constructor Details
- (Peer) initialize(identity)
Returns a new instance of Peer
32 33 34 35 36 |
# File 'lib/diameter/stack.rb', line 32 def initialize(identity) @identity = identity @state = :CLOSED @state_change_q = Queue.new end |
Instance Attribute Details
- (Object) cxn
- Socket
-
The underlying network connection to this peer.
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 59 60 61 62 63 |
# File 'lib/diameter/stack.rb', line 28 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 |
- (Object) expiry_time
- Time
-
For a dynamically discovered peer, the time when it stops
being valid and dynamic discovery must happen again.
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 59 60 61 62 63 |
# File 'lib/diameter/stack.rb', line 28 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 |
- (Object) identity
- String
-
The DiameterIdentity of this peer
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 59 60 61 62 63 |
# File 'lib/diameter/stack.rb', line 28 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 |
- (Object) last_message_seen
- Time
-
The last time traffic was received from this peer. Used for
determining when to send watchdog messages, or for triggering failover.
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 59 60 61 62 63 |
# File 'lib/diameter/stack.rb', line 28 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 |
- (Object) realm
- String
-
The Diameter realm of this peer
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 59 60 61 62 63 |
# File 'lib/diameter/stack.rb', line 28 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 |
- (Object) state
- Keyword
-
The current state of this peer - :UP, :WATING or :CLOSED.
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 59 60 61 62 63 |
# File 'lib/diameter/stack.rb', line 28 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 |
- (Object) static
- true, false
-
Whether this peer was dynamically discovered (and so
might expire) or statically configured.
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 59 60 61 62 63 |
# File 'lib/diameter/stack.rb', line 28 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
- (Object) reset_timer
Resets the last message seen time. Should be called when a message is received from this peer.
59 60 61 |
# File 'lib/diameter/stack.rb', line 59 def reset_timer self. = Time.now end |
- (Object) wait_for_state_change(state)
Blocks until the state of this peer changes to the desired value.
41 42 43 44 45 46 |
# File 'lib/diameter/stack.rb', line 41 def wait_for_state_change(state) cur_state = @state while (cur_state != state) cur_state = @state_change_q.pop end end |