tanker-core 2.6.2.alpha.2 → 2.6.2.alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c31a7dd72c30de5e9663ed4a673336087ea1b4643b8e0ee5286acbb3305c0384
4
- data.tar.gz: 0b834e4736b7bdc08ed4514b0b6e9ee4e701bac3a1b5463459bec0ba72795aa1
3
+ metadata.gz: 638dddc98b2aba670d089303d2601a309a1f5cced6683148137e61de666c5edb
4
+ data.tar.gz: b86a802db223abadd7d90cd09d3584e073bc3e760703e4dcceb2345503908287
5
5
  SHA512:
6
- metadata.gz: 11e72970a98eade34813b02f4f74db67548a4f869bba886591a4b9d864a6f3eebd8dde9727ba53abd6637724a46a48688143d696d2e8a1496eb5dc46f7f06588
7
- data.tar.gz: 34b1e95c6aef86da9d8adb782523128486f60b67c5332036780fdda9f6a327671db29ef8bcb1038769c089c69663b0456a83a9fce378128376ecdc4ae9e6e198
6
+ metadata.gz: 8af8b985ed3b691a03fbc1af01f5796e673946474f83e543d08ae21b36aa18159c389a94bd43885fa685a5d6b5363c9642717a43573f3536d6cc9f16c2c91365
7
+ data.tar.gz: 4e7cf105a49f723739866e30c7b0807c5d78cc900729cb286d39e4fdda7b513960bdd239f082caa0df4cd99461a380bfd62cd73e686ea19ed596fedf0357bb85
@@ -1,15 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'ffi/platform'
4
+
3
5
  module Tanker::CTanker
4
6
  def self.get_path(name)
5
- if /darwin/ =~ RUBY_PLATFORM
6
- ext = '.dylib'
7
- subdir = 'mac64'
8
- else
9
- ext = '.so'
10
- subdir = 'linux64'
11
- end
12
-
13
- File.expand_path "../../../vendor/libctanker/#{subdir}/tanker/lib/lib#{name}#{ext}", __dir__
7
+ File.expand_path "../../../vendor/tanker/#{FFI::Platform::OS}-#{FFI::Platform::ARCH}/"\
8
+ "#{FFI::Platform::LIBPREFIX}#{name}.#{FFI::Platform::LIBSUFFIX}", __dir__
14
9
  end
15
10
  end
@@ -3,22 +3,34 @@
3
3
  module Tanker
4
4
  # Main entry point for the Tanker SDK. Can open a Tanker session.
5
5
  class Core
6
+ @log_handler_lock = Mutex.new
7
+ @log_handler_set = 0
8
+
9
+ def self.test_and_set_log_handler
10
+ @log_handler_lock.synchronize do
11
+ is_set = @log_handler_set
12
+ @log_handler_set = 1
13
+ return is_set
14
+ end
15
+ end
16
+
6
17
  def self.set_log_handler(&block) # rubocop:disable Naming/AccessorMethodName
18
+ @log_handler_set = 1
7
19
  @log_handler = lambda do |clog|
8
20
  block.call LogRecord.new clog[:category], clog[:level], clog[:file], clog[:line], clog[:message]
9
21
  end
10
22
  CTanker.tanker_set_log_handler @log_handler
11
23
  end
12
24
 
13
- # Do not spam the console of our users. This must be done first to be effective.
14
- set_log_handler { |_| }
15
-
16
25
  def initialize(options)
17
26
  # tanker_init is not called globally to avoid potential logs at global scope
18
27
  # some frameworks like to pre-execute statements at global scope and then fork, this fork can
19
28
  # interact badly with the threads used in the log handler, so never call Tanker at global scope
20
29
  CTanker.tanker_init
21
30
 
31
+ # Do not spam the console of our users.
32
+ self.class.set_log_handler { |_| } unless self.class.test_and_set_log_handler == 1
33
+
22
34
  @revoke_event_handlers = Set.new
23
35
  @ctanker = CTanker.tanker_create(options).get
24
36
  @freed = false
@@ -3,6 +3,29 @@
3
3
  require 'English'
4
4
  require 'tanker/c_tanker'
5
5
 
6
+ # Because Ruby only has synchronous streams, we can't read them on Tanker's
7
+ # thread (in the read callback). To work around that, we start a new Thread for
8
+ # each read operation. This is not that bad because Ruby uses a thread pool
9
+ # behind the scenes and creating a Thread is usually just a work pushed on a
10
+ # queue.
11
+ #
12
+ # Also, there doesn't seem to easily create an IO object. The simplest way is to
13
+ # create a pipe. A pipe is a stream where you read everything you write into it.
14
+ # Tanker streams however are pull streams, so there must be something that pulls
15
+ # from the Tanker stream and pushes onto the IO stream. We start a long-running
16
+ # thread for that which just loops.
17
+ #
18
+ # Because so much is happening in parallel, synchronization is not trivial.
19
+ # There's one mutex per stream, and we lock that same mutex for every critical
20
+ # section. Here are some important constraints that must be held:
21
+ # - Do not copy data to the Tanker buffer if tanker_stream_close has been
22
+ # called
23
+ # - Do not call tanker_stream_read_operation_finish if tanker_stream_close has
24
+ # been called
25
+ # - On the output stream, do not call tanker_stream_read on a closed/closing
26
+ # stream. Though it is ok to close the stream after the call, but before the
27
+ # future is resolved.
28
+
6
29
  module Tanker
7
30
  class Core
8
31
  def encrypt_stream(stream, encryption_options = nil)
@@ -95,21 +118,6 @@ module Tanker
95
118
  end
96
119
  end
97
120
 
98
- # IMPORTANT: about synchronization
99
- # Because of a design flaw in the Tanker C streaming API, it is difficult to
100
- # handle cancelation. When canceling a read (closing the stream), Tanker
101
- # doesn't forward the cancelation request to the input stream (there's no
102
- # callback for that), which means that the callback maybe writing to a buffer
103
- # that's being freed. We worked around that by adding a mutex and locking it
104
- # in both the output stream and the input stream.
105
- # Things to be careful about:
106
- # - Do not copy data to the Tanker buffer if tanker_stream_close has been
107
- # called
108
- # - Do not call tanker_stream_read_operation_finish if tanker_stream_close has
109
- # been called
110
- # - On the output stream, do not call tanker_stream_read on a closed/closing
111
- # stream. Though it is ok to close the stream after the call, but before the
112
- # future is resolved.
113
121
  class IoToTankerStreamWrapper
114
122
  attr_reader :error
115
123
  attr_reader :read_method
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Tanker
4
4
  class Core
5
- VERSION = '2.6.2.alpha.2'
5
+ VERSION = '2.6.2.alpha.3'
6
6
 
7
7
  def self.native_version
8
8
  CTanker.tanker_version_string
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tanker-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.2.alpha.2
4
+ version: 2.6.2.alpha.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tanker team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-20 00:00:00.000000000 Z
11
+ date: 2020-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -165,8 +165,7 @@ files:
165
165
  - lib/tanker/encryption_options.rb
166
166
  - lib/tanker/error.rb
167
167
  - lib/tanker/sharing_options.rb
168
- - vendor/libctanker/linux64/tanker/lib/libctanker.so
169
- - vendor/libctanker/mac64/tanker/lib/libctanker.dylib
168
+ - vendor/tanker/linux-x86_64/libctanker.so
170
169
  homepage: https://tanker.io
171
170
  licenses:
172
171
  - Apache-2.0