Class: TinyDTLS::Context

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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
# File 'lib/tinydtls/context.rb', line 18

def initialize(sendfn, queue, secconf)
  @sendfn  = sendfn
  @queue   = queue
  @secconf = secconf
end

Instance Attribute Details

#queueObject (readonly)

The queue used for communication with the receive thread.



9
10
11
# File 'lib/tinydtls/context.rb', line 9

def queue
  @queue
end

#secconfObject (readonly)

An instance of the security configuration class.



12
13
14
# File 'lib/tinydtls/context.rb', line 12

def secconf
  @secconf
end

#sendfnObject (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

Create a new instance of this class from 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.



30
31
32
33
# File 'lib/tinydtls/context.rb', line 30

def self.from_ptr(ptr)
  obj = Wrapper::DTLSContextStruct.new(ptr)
  return CONTEXT_MAP[Wrapper::dtls_get_app_data(obj).to_i]
end