tanker-core 2.6.2.beta.2 → 2.6.3.beta.1

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: 69f962904a2700e1eff1d3f7d44a5a7f29be26c0048a89ffffc3ad5e5a856f82
4
- data.tar.gz: 040e523c8912592aadec416c027cb925d0c6e2936e0d1364c6e6cd75cae9164c
3
+ metadata.gz: b340cd6c68ae50a570cb9b2fe022cef3e58d977ea496f6a9a9188805dbcefc8f
4
+ data.tar.gz: '08ed2f6c92839b80f1ad99298affcc5346baa1dd54cec35140a49dcbf1ea53af'
5
5
  SHA512:
6
- metadata.gz: e515de3523845ec392141a9ed06baf9c936a863cb0d905384398232c705cf182377c97cf12efedebf83055b09df8ea6d8d02dabe6620b251489790cc22a54520
7
- data.tar.gz: a60601421d1c3402ebf73d4e35cdc6127c367769523697b7495635ae0a56d2d84c8acba65e5e126f4de4164f2fddb0eede58a88acc45646b7fdcaa28baeb2f10
6
+ metadata.gz: db46bd49eef92e19a889758223a1ca7e187fefd2db5a47fbefd44f990a61a34ca57133bb01683130293c6830805e53b92ca7362538ca00aee4babc08600a7d50
7
+ data.tar.gz: 841f15d5be8536cca1426ce9e56696c8f053a3684d93ecefdb9f944caf6fc5411aaed74a416c3822495bf26cee104389918df00dda706e955430fe213e6deafd
@@ -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,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
@@ -174,14 +182,15 @@ module Tanker
174
182
  def initialize(tanker_stream, substream)
175
183
  @tanker_stream = tanker_stream
176
184
  @substream = substream
185
+ end
186
+
187
+ def init_io
188
+ read, @write = IO.pipe
177
189
 
178
190
  # The user will only read on the pipe, so we need something that reads
179
191
  # from Tanker and writes to the pipe, it's this thread.
180
192
  Thread.new { read_thread }
181
- end
182
193
 
183
- def init_io
184
- read, @write = IO.pipe
185
194
  read
186
195
  end
187
196
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Tanker
4
4
  class Core
5
- VERSION = '2.6.2.beta.2'
5
+ VERSION = '2.6.3.beta.1'
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.beta.2
4
+ version: 2.6.3.beta.1
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-21 00:00:00.000000000 Z
11
+ date: 2020-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -165,8 +165,8 @@ 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/darwin-x86_64/libctanker.dylib
169
+ - vendor/tanker/linux-x86_64/libctanker.so
170
170
  homepage: https://tanker.io
171
171
  licenses:
172
172
  - Apache-2.0