Class: TinyDTLS::Context
- Inherits:
-
Object
- Object
- TinyDTLS::Context
- Defined in:
- lib/tinydtls/context.rb
Overview
The class Context stores all per-connection information, it is exclusively used in the ‘TinyDTLS::CONTEXT_MAP`.
Instance Attribute Summary collapse
-
#queue ⇒ Object
readonly
The queue used for communication with the receive thread.
-
#secconf ⇒ Object
readonly
An instance of the security configuration class.
-
#sendfn ⇒ Object
readonly
The method used for sending data on the socket.
Class Method Summary collapse
-
.from_ptr(ptr) ⇒ Object
Retrieves an instance of this class from the TinyDTLS::CONTEXT_MAP using a pointer to a ‘struct dtls_context_t`.
Instance Method Summary collapse
-
#initialize(sendfn, queue, secconf) ⇒ Context
constructor
Create a new instance of this class with a given function to send message on the transport layer, a queue for storing received messages and a security configuration containing a key to identity mapping.
-
#key ⇒ Object
Returns a key which should be used to store this context in the global TinyDTLS::CONTEXT_MAP.
-
#to_ffi ⇒ Object
Returns an FFI::Struct for this object, representing the underlying ‘dtls_context_t`.
Constructor Details
#initialize(sendfn, queue, secconf) ⇒ Context
Create a new instance of this class with a given function to send message on the transport layer, a queue for storing received messages and a security configuration containing a key to identity mapping.
18 19 20 21 22 23 24 25 |
# File 'lib/tinydtls/context.rb', line 18 def initialize(sendfn, queue, secconf) @sendfn = sendfn @queue = queue @secconf = secconf @ffi_struct = Wrapper::DTLSContextStruct.new( Wrapper::dtls_new_context(FFI::Pointer.new(key))) end |
Instance Attribute Details
#queue ⇒ Object (readonly)
The queue used for communication with the receive thread.
9 10 11 |
# File 'lib/tinydtls/context.rb', line 9 def queue @queue end |
#secconf ⇒ Object (readonly)
An instance of the security configuration class.
12 13 14 |
# File 'lib/tinydtls/context.rb', line 12 def secconf @secconf end |
#sendfn ⇒ Object (readonly)
The method used for sending data on the socket.
6 7 8 |
# File 'lib/tinydtls/context.rb', line 6 def sendfn @sendfn end |
Class Method Details
.from_ptr(ptr) ⇒ Object
Retrieves an instance of this class from the TinyDTLS::CONTEXT_MAP using a pointer to a ‘struct dtls_context_t`. Such a pointer is, for instance, passed to the various tinydtls callback functions.
The ‘struct dtls_context_t` which the given pointer points to must have been created by TinyDTLS::UDPSocket#initialize.
33 34 35 36 |
# File 'lib/tinydtls/context.rb', line 33 def self.from_ptr(ptr) obj = Wrapper::DTLSContextStruct.new(ptr) return CONTEXT_MAP[Wrapper::dtls_get_app_data(obj).to_i] end |
Instance Method Details
#key ⇒ Object
Returns a key which should be used to store this context in the global TinyDTLS::CONTEXT_MAP.
40 41 42 |
# File 'lib/tinydtls/context.rb', line 40 def key object_id end |
#to_ffi ⇒ Object
Returns an FFI::Struct for this object, representing the underlying ‘dtls_context_t`.
46 47 48 |
# File 'lib/tinydtls/context.rb', line 46 def to_ffi @ffi_struct end |