ruby-libstorj 0.0.0

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.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.gitmodules +3 -0
  4. data/.rspec +1 -0
  5. data/Gemfile +23 -0
  6. data/Gemfile.lock +111 -0
  7. data/Guardfile +21 -0
  8. data/LICENSE +502 -0
  9. data/README.md +262 -0
  10. data/Rakefile +76 -0
  11. data/ext/libstorj/.gitignore +47 -0
  12. data/ext/libstorj/.travis.yml +27 -0
  13. data/ext/libstorj/Doxyfile +2427 -0
  14. data/ext/libstorj/LICENSE +502 -0
  15. data/ext/libstorj/Makefile.am +6 -0
  16. data/ext/libstorj/README.md +198 -0
  17. data/ext/libstorj/autogen.sh +3 -0
  18. data/ext/libstorj/configure.ac +64 -0
  19. data/ext/libstorj/depends/Makefile +153 -0
  20. data/ext/libstorj/depends/config.guess +1462 -0
  21. data/ext/libstorj/depends/config.sub +1823 -0
  22. data/ext/libstorj/depends/extract-osx-sdk.sh +33 -0
  23. data/ext/libstorj/depends/packages/cctools.mk +7 -0
  24. data/ext/libstorj/depends/packages/clang.mk +7 -0
  25. data/ext/libstorj/depends/packages/gmp.mk +23 -0
  26. data/ext/libstorj/depends/packages/gnutls.mk +25 -0
  27. data/ext/libstorj/depends/packages/json-c.mk +7 -0
  28. data/ext/libstorj/depends/packages/libcurl.mk +39 -0
  29. data/ext/libstorj/depends/packages/libmicrohttpd.mk +7 -0
  30. data/ext/libstorj/depends/packages/libuv.mk +7 -0
  31. data/ext/libstorj/depends/packages/nettle.mk +30 -0
  32. data/ext/libstorj/libstorj.pc.in +11 -0
  33. data/ext/libstorj/src/Makefile.am +23 -0
  34. data/ext/libstorj/src/bip39.c +233 -0
  35. data/ext/libstorj/src/bip39.h +64 -0
  36. data/ext/libstorj/src/bip39_english.h +2074 -0
  37. data/ext/libstorj/src/cli.c +1494 -0
  38. data/ext/libstorj/src/crypto.c +525 -0
  39. data/ext/libstorj/src/crypto.h +178 -0
  40. data/ext/libstorj/src/downloader.c +1923 -0
  41. data/ext/libstorj/src/downloader.h +163 -0
  42. data/ext/libstorj/src/http.c +688 -0
  43. data/ext/libstorj/src/http.h +175 -0
  44. data/ext/libstorj/src/rs.c +962 -0
  45. data/ext/libstorj/src/rs.h +99 -0
  46. data/ext/libstorj/src/storj.c +1523 -0
  47. data/ext/libstorj/src/storj.h +1014 -0
  48. data/ext/libstorj/src/uploader.c +2736 -0
  49. data/ext/libstorj/src/uploader.h +181 -0
  50. data/ext/libstorj/src/utils.c +336 -0
  51. data/ext/libstorj/src/utils.h +65 -0
  52. data/ext/libstorj/test/Makefile.am +27 -0
  53. data/ext/libstorj/test/mockbridge.c +260 -0
  54. data/ext/libstorj/test/mockbridge.json +687 -0
  55. data/ext/libstorj/test/mockbridgeinfo.json +1836 -0
  56. data/ext/libstorj/test/mockfarmer.c +358 -0
  57. data/ext/libstorj/test/storjtests.h +41 -0
  58. data/ext/libstorj/test/tests.c +1617 -0
  59. data/ext/libstorj/test/tests_rs.c +869 -0
  60. data/ext/ruby-libstorj/extconf.rb +8 -0
  61. data/ext/ruby-libstorj/ruby-libstorj.cc +17 -0
  62. data/lib/ruby-libstorj.rb +1 -0
  63. data/lib/ruby-libstorj/arg_forwarding_task.rb +58 -0
  64. data/lib/ruby-libstorj/env.rb +178 -0
  65. data/lib/ruby-libstorj/ext/bucket.rb +71 -0
  66. data/lib/ruby-libstorj/ext/create_bucket_request.rb +53 -0
  67. data/lib/ruby-libstorj/ext/curl_code.rb +139 -0
  68. data/lib/ruby-libstorj/ext/ext.rb +71 -0
  69. data/lib/ruby-libstorj/ext/file.rb +84 -0
  70. data/lib/ruby-libstorj/ext/get_bucket_request.rb +45 -0
  71. data/lib/ruby-libstorj/ext/json_request.rb +51 -0
  72. data/lib/ruby-libstorj/ext/list_files_request.rb +63 -0
  73. data/lib/ruby-libstorj/ext/types.rb +226 -0
  74. data/lib/ruby-libstorj/ext/upload_options.rb +38 -0
  75. data/lib/ruby-libstorj/libstorj.rb +22 -0
  76. data/lib/ruby-libstorj/mixins/storj.rb +27 -0
  77. data/lib/ruby-libstorj/struct.rb +42 -0
  78. data/ruby-libstorj.gemspec +57 -0
  79. data/spec/helpers/options.yml.example +22 -0
  80. data/spec/helpers/shared_rake_examples.rb +132 -0
  81. data/spec/helpers/storj_options.rb +96 -0
  82. data/spec/helpers/upload.data +3 -0
  83. data/spec/helpers/upload.data.sha256 +1 -0
  84. data/spec/libstorj_spec.rb +0 -0
  85. data/spec/ruby-libstorj/arg_forwarding_task_spec.rb +311 -0
  86. data/spec/ruby-libstorj/env_spec.rb +353 -0
  87. data/spec/ruby-libstorj/ext_spec.rb +75 -0
  88. data/spec/ruby-libstorj/json_request_spec.rb +13 -0
  89. data/spec/ruby-libstorj/libstorj_spec.rb +81 -0
  90. data/spec/ruby-libstorj/struct_spec.rb +64 -0
  91. data/spec/spec_helper.rb +113 -0
  92. metadata +136 -0
@@ -0,0 +1,71 @@
1
+ module LibStorj
2
+ module Ext
3
+ module LibC
4
+ extend FFI::Library
5
+ ffi_lib('c')
6
+
7
+ attach_function('fopen', [:string, :string], :pointer)
8
+ attach_function('fclose', [:pointer], :int)
9
+ end
10
+
11
+ module Curl
12
+ extend FFI::Library
13
+ ffi_lib('curl')
14
+
15
+ attach_function('easy_stderr', 'curl_easy_strerror', [:curl_code], :string)
16
+
17
+ def self.curl_code_to_string(error_code)
18
+ return nil if error_code.nil?
19
+
20
+ curl_error = ::LibStorj::Ext::Curl.easy_stderr(error_code)
21
+ error_code > 0 ? curl_error : ''
22
+ end
23
+ end
24
+
25
+ module JsonC
26
+ extend FFI::Library
27
+ ffi_lib('json-c')
28
+
29
+ attach_function('stringify', 'json_object_to_json_string', [:pointer], :string)
30
+ attach_function('parse', 'json_tokener_parse', [:string], :pointer)
31
+ end
32
+
33
+ module Storj
34
+ extend FFI::Library
35
+ ffi_lib('storj')
36
+
37
+ JSON_LOGGER = FFI::Function.new :void, [:string, :int, :pointer] do |message, level, handle|
38
+ puts JSON.dump message: message,
39
+ level: level,
40
+ timestamp: ::LibStorj.util_timestamp
41
+ end
42
+
43
+ attach_function('util_timestamp', 'storj_util_timestamp', [], :uint64)
44
+ attach_function('mnemonic_check', 'storj_mnemonic_check', [:string], :bool)
45
+ attach_function('mnemonic_generate', 'storj_mnemonic_generate', [:int, :pointer], :int)
46
+
47
+ attach_function('get_info', 'storj_bridge_get_info', [
48
+ Env.by_ref,
49
+ ::LibStorj::Ext::Storj::JsonRequest::CALLBACK,
50
+ :pointer # uv_after_work_cb*
51
+ # ::LibStorj::UV::
52
+ ], :int)
53
+
54
+ attach_function('destroy_env', 'storj_destroy_env', [
55
+ Env.by_ref
56
+ ], :int)
57
+
58
+ attach_function('init_env', 'storj_init_env', [
59
+ BridgeOptions.by_ref,
60
+ EncryptOptions.by_ref,
61
+ HttpOptions.by_ref,
62
+ LogOptions.by_ref
63
+ ], Env.by_ref)
64
+ end
65
+
66
+ module UV
67
+ extend FFI::Library
68
+ ffi_lib('uv')
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,84 @@
1
+ module LibStorj
2
+ module Ext
3
+ module Storj
4
+ class File < FFI::Struct
5
+ extend FFI::Library
6
+ ffi_lib('storj')
7
+
8
+ attr_reader :name, :id, :size
9
+
10
+ # typedef void (*storj_progress_cb)(double progress
11
+ # uint64_t bytes,
12
+ # uint64_t total_bytes,
13
+ # void *handle);
14
+ PROGRESS_CALLBACK = callback %i[double uint64 uint64 pointer], :void
15
+
16
+ # typedef void (*storj_finished_download_cb)(int status, FILE *fd, void *handle);
17
+ FINISHED_DOWNLOAD_CALLBACK = callback %i[int pointer pointer], :void
18
+
19
+ # typedef void (*storj_finished_upload_cb)(int error_status, char *file_id, void *handle);
20
+ FINISHED_UPLOAD_CALLBACK = callback %i[int string pointer], :void
21
+
22
+ def initialize(*args)
23
+ super(*args)
24
+
25
+ @name, @id, @size = self.values_at %i[filename id size]
26
+ end
27
+
28
+ def self.pointer_to_array(pointer, array_length)
29
+ if pointer.nil? || pointer == FFI::MemoryPointer::NULL || array_length < 1
30
+ return nil
31
+ end
32
+
33
+ ### #=> [#<LibStorj::Ext::Storj::Bucket ...>, ...]
34
+ (0..(array_length - 1)).map do |i|
35
+ File.new pointer[i * size]
36
+ end
37
+ end
38
+
39
+ attach_function('all', 'storj_bridge_list_files', [
40
+ Env.by_ref,
41
+ :string,
42
+ ::LibStorj::Ext::Storj::JsonRequest::CALLBACK,
43
+ :pointer # uv_after_work_cb*
44
+ ], :int)
45
+
46
+ private :all
47
+
48
+ attach_function('delete', 'storj_bridge_delete_file', [
49
+ Env.by_ref,
50
+ :string,
51
+ :string,
52
+ ::LibStorj::Ext::Storj::JsonRequest::CALLBACK,
53
+ :pointer, # after_work_cb
54
+ ], :int)
55
+
56
+ attach_function('resolve', 'storj_bridge_resolve_file', [
57
+ Env.by_ref,
58
+ :string,
59
+ :string,
60
+ :pointer, # FILE* destination
61
+ :pointer, # handle
62
+ PROGRESS_CALLBACK, # progress_cb
63
+ FINISHED_DOWNLOAD_CALLBACK, # finished_cb
64
+ ], ::LibStorj::Ext::Storj::DownloadState.by_ref)
65
+
66
+ attach_function('store', 'storj_bridge_store_file', [
67
+ Env.by_ref,
68
+ ::LibStorj::Ext::Storj::UploadOptions.by_ref,
69
+ :pointer, # handle
70
+ PROGRESS_CALLBACK, # progress_cb
71
+ FINISHED_DOWNLOAD_CALLBACK, # finished_cb
72
+ ], ::LibStorj::Ext::Storj::UploadState.by_ref)
73
+
74
+ attach_function('store_cancel', 'storj_bridge_store_file_cancel', [
75
+ ::LibStorj::Ext::Storj::UploadState.by_ref
76
+ ], :int)
77
+
78
+ attach_function('resolve_cancel', 'storj_bridge_resolve_file_cancel', [
79
+ ::LibStorj::Ext::Storj::DownloadState.by_ref
80
+ ], :int)
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,45 @@
1
+ module LibStorj
2
+ module Ext
3
+ module Storj
4
+ class GetBucketRequest < FFI::Struct
5
+ layout :http_options, HttpOptions.by_ref,
6
+ :encrypt_options, EncryptOptions.by_ref,
7
+ :options, BridgeOptions.by_ref,
8
+ :method, :string,
9
+ :path, :string,
10
+ :auth, :bool,
11
+ :body, :pointer, # struct json_object *body;
12
+ :response, :pointer, # struct json_object *body;
13
+ :buckets, :pointer,
14
+ :total_buckets, :uint32,
15
+ :error_code, :int,
16
+ :status_code, :int,
17
+ :handle, :pointer # void*
18
+
19
+ def self.after_work_cb
20
+ args = [::LibStorj::Ext::UV::Work.by_ref, :int]
21
+
22
+ FFI::Function.new :void, args do |work_req_ptr|
23
+ req = self.new work_req_ptr[:data]
24
+ buckets,total_buckets = req.values_at %i[buckets total_buckets]
25
+ error = ::LibStorj::Ext::Curl.curl_code_to_string req[:error_code]
26
+ c_handle = FFI::Function.new :void, %i[string pointer int], req[:handle]
27
+
28
+ c_handle.call error, buckets, total_buckets
29
+ end
30
+ end
31
+
32
+ def self.ruby_handle
33
+ FFI::Function.new :void, %i[string pointer int] do
34
+ |error, buckets_pointer, bucket_count|
35
+ buckets = ::LibStorj::Ext::Storj::Bucket
36
+ .pointer_to_array buckets_pointer,
37
+ bucket_count
38
+
39
+ yield error, buckets
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,51 @@
1
+ module LibStorj
2
+ module Ext
3
+ module Storj
4
+ class JsonRequest < FFI::Struct
5
+ CALLBACK = callback [:string, :string], :void
6
+
7
+ layout :http_options, HttpOptions.by_ref,
8
+ :options, BridgeOptions.by_ref,
9
+ :method, :string,
10
+ :path, :string,
11
+ :auth, :bool,
12
+ :body, :pointer, # struct json_object *body;
13
+ :response, :pointer, # struct json_object *response;
14
+ :error_code, :int,
15
+ :status_code, :int,
16
+ :handle, :pointer # void*
17
+
18
+ def self.after_work_cb
19
+ args = [::LibStorj::Ext::UV::Work.by_ref, :int]
20
+
21
+ FFI::Function.new :void, args do |work_req_ptr|
22
+ req = self.new work_req_ptr[:data]
23
+ response = ::LibStorj::Ext::JsonC.stringify req[:response]
24
+ error = ::LibStorj::Ext::Curl.curl_code_to_string req[:error_code]
25
+ c_handle = FFI::Function.new :void, %i[string pointer], req[:handle]
26
+
27
+ c_handle.call(error, response)
28
+ end
29
+ end
30
+
31
+ def self.ruby_handle(&block)
32
+ FFI::Function.new :void, %i[string string] do |error, response|
33
+ begin
34
+ response = JSON.parse response
35
+ rescue JSON::ParserError => err
36
+ error = err
37
+ response = nil
38
+ end
39
+
40
+ if error.respond_to?(:empty?) && error.empty?
41
+ response_error = response.nil? ? nil : response['error']
42
+ error = response_error.nil? ? nil : response_error
43
+ end
44
+
45
+ yield error, response if block_given?
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,63 @@
1
+ module LibStorj
2
+ module Ext
3
+ module Storj
4
+ class ListFilesRequest < FFI::Struct
5
+ layout :http_options, HttpOptions.by_ref,
6
+ :encrypt_options, EncryptOptions.by_ref,
7
+ :options, BridgeOptions.by_ref,
8
+ :bucket_id, :string,
9
+ :method, :string,
10
+ :path, :string,
11
+ :auth, :bool,
12
+ :body, :pointer, # struct json_object *body;
13
+ :response, :pointer, # struct json_object *response;
14
+ :files, :pointer,
15
+ :total_files, :uint32,
16
+ :error_code, :int,
17
+ :status_code, :int,
18
+ :handle, :pointer # void*
19
+
20
+ def self.after_work_cb
21
+ args = [::LibStorj::Ext::UV::Work.by_ref, :int]
22
+
23
+ FFI::Function.new :void, args do |work_req_ptr|
24
+ req = self.new work_req_ptr[:data]
25
+ files, total_files, response = req.values_at %i[files total_files response]
26
+ error = ::LibStorj::Ext::Curl.curl_code_to_string req[:error_code]
27
+ c_handle = FFI::Function.new :void, %i[string pointer int], req[:handle]
28
+
29
+ catch :no_response_error do
30
+ begin
31
+ response_string = ::LibStorj::Ext::JsonC.stringify(response)
32
+ response_hash = JSON.parse(response_string)
33
+
34
+ unless response_hash.is_a?(Hash) && !response_hash['error'].nil?
35
+ throw :no_response_error
36
+ end
37
+
38
+ error = response_error if response_error && error.empty?
39
+ rescue JSON::ParserError => err
40
+ # response didn't contain valid JSON;
41
+ # therefore, it probably doesn't contain an error message
42
+ end
43
+ end
44
+
45
+ c_handle.call error, files, total_files
46
+ end
47
+ end
48
+
49
+ def self.ruby_handle(&block)
50
+ FFI::Function.new :void, %i[string pointer int] do
51
+ |error, files_pointer, file_count|
52
+ files = ::LibStorj::Ext::Storj::File.pointer_to_array files_pointer,
53
+ file_count
54
+
55
+ error = nil if error.empty?
56
+
57
+ yield error, files
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,226 @@
1
+ module LibStorj
2
+ module Ext
3
+ # NB: Ruby's ffi doesn't allow assigning to :string' pointer
4
+ # types.
5
+ #
6
+ # You can use `FFI::MemoryPointer.from_string` to create a
7
+ # string pointer from a ruby string. Or use the
8
+ # `FFI::Pointer#write_string` method to update an existing
9
+ # string (or generic) pointer; see below
10
+ #
11
+ # NB: All pointer types use have
12
+ # `read_<type> (FFI::Pointer#read_<type>)`
13
+ # and
14
+ # `write_<type> (FFI::Pointer#write_<type>)`
15
+ # methods to read and write respectively
16
+
17
+ module Curl
18
+ extend FFI::Library
19
+ require 'ruby-libstorj/ext/curl_code'
20
+
21
+ enum(:curl_code, CURL_CODES)
22
+ end
23
+
24
+ module Storj
25
+ extend FFI::Library
26
+
27
+ class BridgeOptions < FFI::Struct
28
+ layout :proto, :pointer,
29
+ :host, :pointer,
30
+ :port, :int,
31
+ :user, :pointer,
32
+ :pass, :pointer
33
+ end
34
+
35
+ class Bucket < FFI::Struct
36
+ layout :created, :string,
37
+ :name, :string,
38
+ :id, :string,
39
+ :decrypted, :bool
40
+ end
41
+
42
+ class File < FFI::Struct
43
+ layout :created, :string,
44
+ :filename, :string,
45
+ :mimetype, :string,
46
+ :erasure, :string,
47
+ :size, :uint64,
48
+ :hmac, :string,
49
+ :id, :string,
50
+ :decrypted, :bool,
51
+ :index, :string
52
+ end
53
+
54
+ class UploadState < FFI::Struct
55
+ layout :env, :pointer,
56
+ :shard_concurrency, :uint32,
57
+ :index, :string,
58
+ :file_name, :string,
59
+ :file_id, :string,
60
+ :encrypted_file_name, :string,
61
+ :original_file, :pointer, # FILE
62
+ :file_size, :uint64,
63
+ :bucket_id, :string,
64
+ :bucket_key, :string,
65
+ :completed_shards, :uint32,
66
+ :total_shards, :uint32,
67
+ :total_data_shards, :uint32,
68
+ :total_parity_shards, :uint32,
69
+ :shard_size, :uint64,
70
+ :total_bytes, :uint64,
71
+ :uploaded_bytes, :uint64,
72
+ :exclude, :string,
73
+ :frame_id, :string,
74
+ :hmac_id, :string,
75
+ :encryption_key, :uint8,
76
+ :encryption_ctr, :uint8,
77
+ :rs, :bool,
78
+ :awaiting_parity_shards, :bool,
79
+ :parity_file_path, :string,
80
+ :parity_file, :pointer, # FILE
81
+ :encrypted_file_path, :string,
82
+ :encrypted_file, :pointer, # FILE
83
+ :creating_encrypted_file, :bool,
84
+ :requesting_frame, :bool,
85
+ :completed_upload, :bool,
86
+ :creating_bucket_entry, :bool,
87
+ :received_all_pointers, :bool,
88
+ :final_callback_called, :bool,
89
+ :canceled, :bool,
90
+ :bucket_verified, :bool,
91
+ :file_verified, :bool,
92
+ :progress_finished, :bool,
93
+ :push_shard_limit, :int,
94
+ :push_frame_limit, :int,
95
+ :prepare_frame_limit, :int,
96
+ :frame_request_count, :int,
97
+ :add_bucket_entry_count, :int,
98
+ :bucket_verify_count, :int,
99
+ :file_verify_count, :int,
100
+ :create_encrypted_file_count, :int,
101
+ :progress_cb, :pointer, # storj_progress_cb
102
+ :finished_cb, :pointer, # storj_finished_upload_cb
103
+ :error_status, :int,
104
+ :log, :pointer, # storj_log_levels_t
105
+ :handle, :pointer,
106
+ :shard, :pointer, # shard_tracker_t
107
+ :pending_work_count, :int,
108
+ #NB: workaround; `libstorj` segfaults without this when calling `storj_bridge_store_file`
109
+ :fake_member, :pointer
110
+
111
+ def cancel
112
+ ::LibStorj::Ext::Storj::File.store_cancel self
113
+ end
114
+ end
115
+
116
+ class DownloadState < FFI::Struct
117
+ layout :total_bytes, :uint64,
118
+ :requesting_info, :bool,
119
+ :info_fail_count, :uint32,
120
+ :env, :pointer,
121
+ :file_id, :string,
122
+ :bucket_id, :string,
123
+ :destination, :pointer, # FILE
124
+ :progress_cb, :pointer, # storj_progress_cb
125
+ :finished_cb, :pointer, # storj_finished_download_cb
126
+ :finished, :bool,
127
+ :canceled, :bool,
128
+ :shard_size, :uint64,
129
+ :total_shards, :uint32,
130
+ :download_max_concurrency, :int,
131
+ :completed_shards, :uint32,
132
+ :resolving_shards, :uint32,
133
+ :pointers, :pointer, # storj_pointer_t
134
+ :excluded_farmer_ids, :string,
135
+ :total_pointers, :uint32,
136
+ :total_parity_pointers, :uint32,
137
+ :rs, :bool,
138
+ :recovering_shards, :bool,
139
+ :truncated, :bool,
140
+ :pointers_completed, :bool,
141
+ :pointer_fail_count, :uint32,
142
+ :requesting_pointers, :bool,
143
+ :error_status, :int,
144
+ :writing, :bool,
145
+ :decrypt_key, :uint8,
146
+ :decrypt_ctr, :uint8,
147
+ :hmac, :string,
148
+ :pending_work_count, :uint32,
149
+ :log, :pointer, # storj_log_levels_t
150
+ :handle, :pointer,
151
+ #NB: workaround; `libstorj` segfaults without this when calling `storj_bridge_resolve_file`
152
+ :fake_member, :pointer
153
+
154
+ def cancel
155
+ ::LibStorj::Ext::Storj::File.resolve_cancel self
156
+ end
157
+ end
158
+
159
+ class EncryptOptions < FFI::Struct
160
+ layout :mnemonic, :pointer
161
+ end
162
+
163
+ class HttpOptions < FFI::Struct
164
+ layout :user_agent, :pointer,
165
+ :proxy_url, :pointer,
166
+ :cainfo_path, :pointer,
167
+ :low_speed_limit, :long,
168
+ :low_speed_time, :long,
169
+ :timeout, :long
170
+ end
171
+
172
+ class LogOptions < FFI::Struct
173
+ layout :logger, :pointer,
174
+ :level, :int
175
+ end
176
+
177
+ class Env < FFI::Struct
178
+ layout :bridge_options, BridgeOptions.by_ref,
179
+ :encrypt_options, EncryptOptions.by_ref,
180
+ :http_options, HttpOptions.by_ref,
181
+ :log_options, LogOptions.by_ref,
182
+ :tmp_path, :pointer,
183
+ :loop, :pointer, # uv_loop_t*
184
+ :log, :pointer # storj_log_levels_t*
185
+ end
186
+ end
187
+
188
+ module UV
189
+ extend FFI::Library
190
+
191
+ enum :uv_work_req, [
192
+ :UV_UNKNOWN_REQ, 0,
193
+ :UV_REQ,
194
+ :UV_CONNECT,
195
+ :UV_WRITE,
196
+ :UV_SHUTDOWN,
197
+ :UV_UDP_SEND,
198
+ :UV_FS,
199
+ :UV_WORK,
200
+ :UV_GETADDRINFO,
201
+ :UV_GETNAMEINFO,
202
+ :UV_REQ_TYPE_PRIVATE,
203
+ :UV_REQ_TYPE_MAX
204
+ ]
205
+
206
+ class Work < FFI::Struct
207
+ layout :data, :pointer, # void*
208
+ # read-only
209
+ :type, :uv_work_req,
210
+ # private
211
+ :active_queue, :pointer,
212
+ :reserved, :pointer,
213
+ :loop, :pointer,
214
+ :work_cb, :pointer,
215
+ :after_work_cb, :pointer
216
+
217
+ # void* active_queue[2];
218
+ # void* reserved[4];
219
+ # ...
220
+ # UV_WORK_PRIVATE_FIELDS
221
+ # };
222
+ end
223
+ end
224
+
225
+ end
226
+ end