Module: TShield::Sessions
- Defined in:
- lib/tshield/sessions.rb
Overview
Manage sessions
Start and stop session for ip
Class Method Summary collapse
- .append(ip, name) ⇒ Object
- .current(ip) ⇒ Object
- .normalize_ip(ip) ⇒ Object
- .sessions ⇒ Object
- .start(ip, name) ⇒ Object
- .stop(ip) ⇒ Object
Class Method Details
.append(ip, name) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/tshield/sessions.rb', line 33 def self.append(ip, name) TShield.logger.info("appeding session #{name} for ip #{normalize_ip(ip)}") current_session = sessions[normalize_ip(ip)] raise AppendSessionWithoutMainSessionError, "not found main session for #{ip}" unless current_session current_session[:secondary_sessions] << name current_session end |
.current(ip) ⇒ Object
28 29 30 31 |
# File 'lib/tshield/sessions.rb', line 28 def self.current(ip) TShield.logger.info("fetching session for ip #{normalize_ip(ip)}") sessions[normalize_ip(ip)] end |
.normalize_ip(ip) ⇒ Object
47 48 49 |
# File 'lib/tshield/sessions.rb', line 47 def self.normalize_ip(ip) ip == '::1' ? '127.0.0.1' : ip end |
.sessions ⇒ Object
43 44 45 |
# File 'lib/tshield/sessions.rb', line 43 def self.sessions @sessions ||= {} end |
.start(ip, name) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/tshield/sessions.rb', line 13 def self.start(ip, name) TShield.logger.info("starting session #{name} for ip #{normalize_ip(ip)}") sessions[normalize_ip(ip)] = { name: name, counter: TShield::Counter.new, grpc_counter: TShield::GrpcCounter.new, secondary_sessions: [] } end |