Class: Arachni::Reactor::Connection
- Inherits:
-
Object
- Object
- Arachni::Reactor::Connection
- Includes:
- Callbacks
- Defined in:
- lib/arachni/reactor/connection.rb,
lib/arachni/reactor/connection/tls.rb,
lib/arachni/reactor/connection/error.rb,
lib/arachni/reactor/connection/callbacks.rb,
lib/arachni/reactor/connection/peer_info.rb
Overview
Defined Under Namespace
Modules: Callbacks, PeerInfo, TLS Classes: Error
Constant Summary collapse
- BLOCK_SIZE =
Maximum amount of data to be written or read at a time.
We set this to the same max block size as the OpenSSL buffers because more than this tends to cause SSL errors and broken #select behavior -- 1024 * 16 at the time of writing.
OpenSSL::Buffering::BLOCK_SIZE
Instance Attribute Summary collapse
-
#reactor ⇒ Reactor
Reactor associated with this connection.
-
#role ⇒ Symbol
readonly
:client
or:server
. -
#socket ⇒ Socket
readonly
Ruby
Socket
associated with this connection.
Instance Method Summary collapse
-
#attach(reactor) ⇒ Bool
true
if the connection was attached,nil
if the connection was already attached. -
#attached? ⇒ Bool
true
if the connection is #attached? to a #reactor,false
otherwise. -
#close(reason = nil) ⇒ Object
Closes the connection and detaches it from the Arachni::Reactor.
-
#close_without_callback ⇒ Object
Closes the connection and detaches it from the Arachni::Reactor.
-
#closed? ⇒ Bool
true
if the connection has been closed,false
otherwise. - #connected? ⇒ Boolean
- #detach ⇒ Bool
-
#detached? ⇒ Bool
true
if the connection is not #attached? to a #reactor,false
otherwise. -
#has_outgoing_data? ⇒ Bool
true
if the connection has outgoing data that have not yet been written,false
otherwise. -
#inet? ⇒ Bool
true
when using an Internet socket,nil
if no #socket is available,false
otherwise. -
#listener? ⇒ Bool
true
if the connection is a server listener. -
#to_io ⇒ IO?
IO stream or
nil
if no #socket is available. -
#unix? ⇒ Bool?
true
when using a UNIX-domain socket,nil
if no #socket is available,false
otherwise. - #write(data) ⇒ Object
Methods included from Callbacks
#on_attach, #on_close, #on_connect, #on_detach, #on_flush, #on_read, #on_write
Instance Attribute Details
#reactor ⇒ Reactor
Returns Reactor associated with this connection.
34 35 36 |
# File 'lib/arachni/reactor/connection.rb', line 34 def reactor @reactor end |
#role ⇒ Symbol (readonly)
Returns :client
or :server
.
38 39 40 |
# File 'lib/arachni/reactor/connection.rb', line 38 def role @role end |
#socket ⇒ Socket (readonly)
Returns Ruby Socket
associated with this connection.
30 31 32 |
# File 'lib/arachni/reactor/connection.rb', line 30 def socket @socket end |
Instance Method Details
#attach(reactor) ⇒ Bool
Will first detach if already #attached?.
Sets #reactor.
Returns true
if the connection was attached, nil
if the connection was
already attached.
111 112 113 114 115 116 117 118 |
# File 'lib/arachni/reactor/connection.rb', line 111 def attach( reactor ) return if reactor.attached?( self ) detach if attached? reactor.attach self true end |
#attached? ⇒ Bool
Returns true
if the connection is Arachni::Reactor#attached? to a #reactor,
false
otherwise.
90 91 92 |
# File 'lib/arachni/reactor/connection.rb', line 90 def attached? @reactor && @reactor.attached?( self ) end |
#close(reason = nil) ⇒ Object
Will call Arachni::Reactor::Connection::Callbacks#on_close right before closing the socket and detaching from the Reactor.
Closes the connection and detaches it from the Arachni::Reactor.
176 177 178 179 180 181 182 |
# File 'lib/arachni/reactor/connection.rb', line 176 def close( reason = nil ) return if closed? on_close reason close_without_callback nil end |
#close_without_callback ⇒ Object
Will not call Arachni::Reactor::Connection::Callbacks#on_close.
Closes the connection and detaches it from the Arachni::Reactor.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/arachni/reactor/connection.rb', line 139 def close_without_callback return if closed? @closed = true if listener? && unix? && (path = to_io.path) && File.exist?( path ) File.delete( path ) end if @socket @socket.close rescue nil end detach nil end |
#closed? ⇒ Bool
Returns true
if the connection has been closed, false
otherwise.
158 159 160 |
# File 'lib/arachni/reactor/connection.rb', line 158 def closed? !!@closed end |
#connected? ⇒ Boolean
224 225 226 |
# File 'lib/arachni/reactor/connection.rb', line 224 def connected? !!@connected end |
#detach ⇒ Bool
Removes #reactor.
128 129 130 131 132 133 134 |
# File 'lib/arachni/reactor/connection.rb', line 128 def detach return if detached? @reactor.detach self true end |
#detached? ⇒ Bool
Returns true
if the connection is not Arachni::Reactor#attached? to a #reactor,
false
otherwise.
97 98 99 |
# File 'lib/arachni/reactor/connection.rb', line 97 def detached? !attached? end |
#has_outgoing_data? ⇒ Bool
Returns true
if the connection has outgoing data that have not
yet been written, false
otherwise.
165 166 167 |
# File 'lib/arachni/reactor/connection.rb', line 165 def has_outgoing_data? !write_buffer.empty? end |
#inet? ⇒ Bool
Returns true
when using an Internet socket, nil
if no #socket is
available, false
otherwise.
54 55 56 57 58 59 |
# File 'lib/arachni/reactor/connection.rb', line 54 def inet? return @is_inet if !@is_inet.nil? return if !to_io @is_inet = to_io.is_a?( TCPServer ) || to_io.is_a?( TCPSocket ) || to_io.is_a?( Socket ) end |
#listener? ⇒ Bool
Returns true
if the connection is a server listener.
70 71 72 73 74 75 |
# File 'lib/arachni/reactor/connection.rb', line 70 def listener? return @is_listener if !@is_listener.nil? return if !to_io @is_listener = to_io.is_a?( TCPServer ) || (unix? && to_io.is_a?( UNIXServer )) end |
#to_io ⇒ IO?
Returns IO stream or nil
if no #socket is available.
63 64 65 66 |
# File 'lib/arachni/reactor/connection.rb', line 63 def to_io return if !@socket @socket.to_io end |
#unix? ⇒ Bool?
Returns true
when using a UNIX-domain socket, nil
if no #socket is
available, false
otherwise.
43 44 45 46 47 48 49 |
# File 'lib/arachni/reactor/connection.rb', line 43 def unix? return @is_unix if !@is_unix.nil? return if !to_io return false if !Arachni::Reactor.supports_unix_sockets? @is_unix = to_io.is_a?( UNIXServer ) || to_io.is_a?( UNIXSocket ) end |
#write(data) ⇒ Object
The data will be buffered and sent in future Arachni::Reactor ticks.
81 82 83 84 85 |
# File 'lib/arachni/reactor/connection.rb', line 81 def write( data ) @reactor.schedule do write_buffer << data end end |