Class: OverSIP::SIP::TlsTunnelConnection
- Inherits:
-
TcpConnection
- Object
- EM::Connection
- Connection
- TcpConnection
- OverSIP::SIP::TlsTunnelConnection
- Defined in:
- lib/oversip/sip/listeners/tls_tunnel_connection.rb
Direct Known Subclasses
Constant Summary collapse
- HEADERS_MAX_SIZE =
Max size (bytes) of the buffered data when receiving message headers (avoid DoS attacks).
16384
Constants included from MessageProcessor
Instance Attribute Summary
Attributes inherited from Connection
Instance Method Summary collapse
Methods inherited from TcpConnection
#get_body, #parse_headers, #receive_data, #remote_ip, #remote_ip_type, #remote_port, #send_sip_msg
Methods inherited from Connection
#initialize, #open?, outbound_listener?, #receive_senderror, reliable_transport_listener?, #transport
Methods included from Logger
fg_system_msg2str, load_methods, #log_id
Constructor Details
This class inherits a constructor from OverSIP::SIP::Connection
Instance Method Details
#parse_haproxy_protocol ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/oversip/sip/listeners/tls_tunnel_connection.rb', line 52 def parse_haproxy_protocol if (haproxy_protocol_data = ::OverSIP::Utils.parse_haproxy_protocol(@buffer.to_str)) @haproxy_protocol_parsed = true # Update connection information. @remote_ip_type = haproxy_protocol_data[1] @remote_ip = haproxy_protocol_data[2] @remote_port = haproxy_protocol_data[3] # Add the connection with the client's source data. Note that we pass a TlsServer as class, but # the server instance is a TcpServer. @connection_id = case @remote_ip_type when :ipv4 ::OverSIP::SIP::TransportManager.add_connection self, ::OverSIP::SIP::IPv4TlsServer, :ipv4, @remote_ip, @remote_port when :ipv6 ::OverSIP::SIP::TransportManager.add_connection self, ::OverSIP::SIP::IPv6TlsServer, :ipv6, @remote_ip, @remote_port end # Update log information. remote_desc true # Remove the HAProxy Protocol line from the received data. @buffer.read haproxy_protocol_data[0] @state = :headers else log_system_error "HAProxy Protocol parsing error, closing connection" close_connection_after_writing @state = :ignore return false end end |
#process_received_data ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 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 |
# File 'lib/oversip/sip/listeners/tls_tunnel_connection.rb', line 9 def process_received_data @state == :ignore and return while (case @state when :init @parser.reset @parser_nbytes = 0 # If it's a TCP connection from the TLS tunnel then parse the HAProxy Protocol line # if it's not yet done. unless @haproxy_protocol_parsed @state = :haproxy_protocol else @state = :headers end when :haproxy_protocol parse_haproxy_protocol when :headers parse_headers when :body get_body when :finished if @msg.request? process_request else process_response end # Set state to :init. @state = :init # Return true to continue processing possible remaining data. true when :ignore false end) end # while end |