iodine 0.4.19 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of iodine might be problematic. Click here for more details.

Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -2
  3. data/CHANGELOG.md +22 -0
  4. data/LIMITS.md +19 -9
  5. data/README.md +92 -77
  6. data/SPEC-PubSub-Draft.md +113 -0
  7. data/SPEC-Websocket-Draft.md +127 -143
  8. data/bin/http-hello +0 -1
  9. data/bin/raw-rbhttp +1 -1
  10. data/bin/raw_broadcast +8 -10
  11. data/bin/updated api +2 -2
  12. data/bin/ws-broadcast +2 -4
  13. data/bin/ws-echo +2 -2
  14. data/examples/config.ru +13 -13
  15. data/examples/echo.ru +5 -6
  16. data/examples/hello.ru +2 -3
  17. data/examples/info.md +316 -0
  18. data/examples/pubsub_engine.ru +81 -0
  19. data/examples/redis.ru +9 -9
  20. data/examples/shootout.ru +45 -11
  21. data/ext/iodine/defer.c +194 -297
  22. data/ext/iodine/defer.h +61 -53
  23. data/ext/iodine/evio.c +0 -260
  24. data/ext/iodine/evio.h +50 -22
  25. data/ext/iodine/evio_callbacks.c +26 -0
  26. data/ext/iodine/evio_epoll.c +251 -0
  27. data/ext/iodine/evio_kqueue.c +193 -0
  28. data/ext/iodine/extconf.rb +1 -1
  29. data/ext/iodine/facil.c +1420 -542
  30. data/ext/iodine/facil.h +151 -64
  31. data/ext/iodine/fio_ary.h +418 -0
  32. data/ext/iodine/{base64.c → fio_base64.c} +33 -24
  33. data/ext/iodine/{base64.h → fio_base64.h} +6 -7
  34. data/ext/iodine/{fio_cli_helper.c → fio_cli.c} +77 -58
  35. data/ext/iodine/{fio_cli_helper.h → fio_cli.h} +9 -4
  36. data/ext/iodine/fio_hashmap.h +759 -0
  37. data/ext/iodine/fio_json_parser.h +651 -0
  38. data/ext/iodine/fio_llist.h +257 -0
  39. data/ext/iodine/fio_mem.c +672 -0
  40. data/ext/iodine/fio_mem.h +140 -0
  41. data/ext/iodine/fio_random.c +248 -0
  42. data/ext/iodine/{random.h → fio_random.h} +11 -14
  43. data/ext/iodine/{sha1.c → fio_sha1.c} +28 -24
  44. data/ext/iodine/{sha1.h → fio_sha1.h} +38 -16
  45. data/ext/iodine/{sha2.c → fio_sha2.c} +66 -49
  46. data/ext/iodine/{sha2.h → fio_sha2.h} +57 -26
  47. data/ext/iodine/{fiobj_internal.c → fio_siphash.c} +9 -90
  48. data/ext/iodine/fio_siphash.h +18 -0
  49. data/ext/iodine/fio_tmpfile.h +38 -0
  50. data/ext/iodine/fiobj.h +24 -7
  51. data/ext/iodine/fiobj4sock.h +23 -0
  52. data/ext/iodine/fiobj_ary.c +143 -226
  53. data/ext/iodine/fiobj_ary.h +17 -16
  54. data/ext/iodine/fiobj_data.c +1160 -0
  55. data/ext/iodine/fiobj_data.h +164 -0
  56. data/ext/iodine/fiobj_hash.c +298 -406
  57. data/ext/iodine/fiobj_hash.h +101 -54
  58. data/ext/iodine/fiobj_json.c +478 -601
  59. data/ext/iodine/fiobj_json.h +34 -9
  60. data/ext/iodine/fiobj_numbers.c +383 -51
  61. data/ext/iodine/fiobj_numbers.h +87 -11
  62. data/ext/iodine/fiobj_str.c +423 -184
  63. data/ext/iodine/fiobj_str.h +81 -32
  64. data/ext/iodine/fiobject.c +273 -522
  65. data/ext/iodine/fiobject.h +477 -112
  66. data/ext/iodine/http.c +2243 -83
  67. data/ext/iodine/http.h +842 -121
  68. data/ext/iodine/http1.c +810 -385
  69. data/ext/iodine/http1.h +16 -39
  70. data/ext/iodine/http1_parser.c +146 -74
  71. data/ext/iodine/http1_parser.h +15 -4
  72. data/ext/iodine/http_internal.c +1258 -0
  73. data/ext/iodine/http_internal.h +226 -0
  74. data/ext/iodine/http_mime_parser.h +341 -0
  75. data/ext/iodine/iodine.c +86 -68
  76. data/ext/iodine/iodine.h +26 -11
  77. data/ext/iodine/iodine_helpers.c +8 -7
  78. data/ext/iodine/iodine_http.c +487 -324
  79. data/ext/iodine/iodine_json.c +304 -0
  80. data/ext/iodine/iodine_json.h +6 -0
  81. data/ext/iodine/iodine_protocol.c +107 -45
  82. data/ext/iodine/iodine_pubsub.c +526 -225
  83. data/ext/iodine/iodine_pubsub.h +10 -0
  84. data/ext/iodine/iodine_websockets.c +268 -510
  85. data/ext/iodine/iodine_websockets.h +2 -4
  86. data/ext/iodine/pubsub.c +726 -432
  87. data/ext/iodine/pubsub.h +85 -103
  88. data/ext/iodine/rb-call.c +4 -4
  89. data/ext/iodine/rb-defer.c +46 -22
  90. data/ext/iodine/rb-fiobj2rb.h +117 -0
  91. data/ext/iodine/rb-rack-io.c +73 -238
  92. data/ext/iodine/rb-rack-io.h +2 -2
  93. data/ext/iodine/rb-registry.c +35 -93
  94. data/ext/iodine/rb-registry.h +1 -0
  95. data/ext/iodine/redis_engine.c +742 -304
  96. data/ext/iodine/redis_engine.h +42 -39
  97. data/ext/iodine/resp_parser.h +311 -0
  98. data/ext/iodine/sock.c +627 -490
  99. data/ext/iodine/sock.h +345 -297
  100. data/ext/iodine/spnlock.inc +15 -4
  101. data/ext/iodine/websocket_parser.h +16 -20
  102. data/ext/iodine/websockets.c +188 -257
  103. data/ext/iodine/websockets.h +24 -133
  104. data/lib/iodine.rb +52 -7
  105. data/lib/iodine/cli.rb +6 -24
  106. data/lib/iodine/json.rb +40 -0
  107. data/lib/iodine/version.rb +1 -1
  108. data/lib/iodine/websocket.rb +5 -3
  109. data/lib/rack/handler/iodine.rb +58 -13
  110. metadata +38 -48
  111. data/bin/ws-shootout +0 -107
  112. data/examples/broadcast.ru +0 -56
  113. data/ext/iodine/bscrypt-common.h +0 -116
  114. data/ext/iodine/bscrypt.h +0 -49
  115. data/ext/iodine/fio2resp.c +0 -60
  116. data/ext/iodine/fio2resp.h +0 -51
  117. data/ext/iodine/fio_dict.c +0 -446
  118. data/ext/iodine/fio_dict.h +0 -99
  119. data/ext/iodine/fio_hash_table.h +0 -370
  120. data/ext/iodine/fio_list.h +0 -111
  121. data/ext/iodine/fiobj_internal.h +0 -280
  122. data/ext/iodine/fiobj_primitives.c +0 -131
  123. data/ext/iodine/fiobj_primitives.h +0 -55
  124. data/ext/iodine/fiobj_sym.c +0 -135
  125. data/ext/iodine/fiobj_sym.h +0 -60
  126. data/ext/iodine/hex.c +0 -124
  127. data/ext/iodine/hex.h +0 -70
  128. data/ext/iodine/http1_request.c +0 -81
  129. data/ext/iodine/http1_request.h +0 -58
  130. data/ext/iodine/http1_response.c +0 -417
  131. data/ext/iodine/http1_response.h +0 -95
  132. data/ext/iodine/http_request.c +0 -111
  133. data/ext/iodine/http_request.h +0 -102
  134. data/ext/iodine/http_response.c +0 -1703
  135. data/ext/iodine/http_response.h +0 -250
  136. data/ext/iodine/misc.c +0 -182
  137. data/ext/iodine/misc.h +0 -74
  138. data/ext/iodine/random.c +0 -208
  139. data/ext/iodine/redis_connection.c +0 -278
  140. data/ext/iodine/redis_connection.h +0 -86
  141. data/ext/iodine/resp.c +0 -842
  142. data/ext/iodine/resp.h +0 -261
  143. data/ext/iodine/siphash.c +0 -154
  144. data/ext/iodine/siphash.h +0 -22
  145. data/ext/iodine/xor-crypt.c +0 -193
  146. data/ext/iodine/xor-crypt.h +0 -107
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iodine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.19
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boaz Segev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-16 00:00:00.000000000 Z
11
+ date: 2018-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -129,6 +129,7 @@ files:
129
129
  - LIMITS.md
130
130
  - README.md
131
131
  - Rakefile
132
+ - SPEC-PubSub-Draft.md
132
133
  - SPEC-Websocket-Draft.md
133
134
  - bin/config.ru
134
135
  - bin/console
@@ -149,116 +150,105 @@ files:
149
150
  - bin/updated api
150
151
  - bin/ws-broadcast
151
152
  - bin/ws-echo
152
- - bin/ws-shootout
153
- - examples/broadcast.ru
154
153
  - examples/config.ru
155
154
  - examples/echo.ru
156
155
  - examples/hello.ru
156
+ - examples/info.md
157
+ - examples/pubsub_engine.ru
157
158
  - examples/redis.ru
158
159
  - examples/shootout.ru
159
160
  - exe/iodine
160
- - ext/iodine/base64.c
161
- - ext/iodine/base64.h
162
- - ext/iodine/bscrypt-common.h
163
- - ext/iodine/bscrypt.h
164
161
  - ext/iodine/defer.c
165
162
  - ext/iodine/defer.h
166
163
  - ext/iodine/evio.c
167
164
  - ext/iodine/evio.h
165
+ - ext/iodine/evio_callbacks.c
166
+ - ext/iodine/evio_epoll.c
167
+ - ext/iodine/evio_kqueue.c
168
168
  - ext/iodine/extconf.rb
169
169
  - ext/iodine/facil.c
170
170
  - ext/iodine/facil.h
171
- - ext/iodine/fio2resp.c
172
- - ext/iodine/fio2resp.h
173
- - ext/iodine/fio_cli_helper.c
174
- - ext/iodine/fio_cli_helper.h
175
- - ext/iodine/fio_dict.c
176
- - ext/iodine/fio_dict.h
177
- - ext/iodine/fio_hash_table.h
178
- - ext/iodine/fio_list.h
171
+ - ext/iodine/fio_ary.h
172
+ - ext/iodine/fio_base64.c
173
+ - ext/iodine/fio_base64.h
174
+ - ext/iodine/fio_cli.c
175
+ - ext/iodine/fio_cli.h
176
+ - ext/iodine/fio_hashmap.h
177
+ - ext/iodine/fio_json_parser.h
178
+ - ext/iodine/fio_llist.h
179
+ - ext/iodine/fio_mem.c
180
+ - ext/iodine/fio_mem.h
181
+ - ext/iodine/fio_random.c
182
+ - ext/iodine/fio_random.h
183
+ - ext/iodine/fio_sha1.c
184
+ - ext/iodine/fio_sha1.h
185
+ - ext/iodine/fio_sha2.c
186
+ - ext/iodine/fio_sha2.h
187
+ - ext/iodine/fio_siphash.c
188
+ - ext/iodine/fio_siphash.h
189
+ - ext/iodine/fio_tmpfile.h
179
190
  - ext/iodine/fiobj.h
191
+ - ext/iodine/fiobj4sock.h
180
192
  - ext/iodine/fiobj_ary.c
181
193
  - ext/iodine/fiobj_ary.h
194
+ - ext/iodine/fiobj_data.c
195
+ - ext/iodine/fiobj_data.h
182
196
  - ext/iodine/fiobj_hash.c
183
197
  - ext/iodine/fiobj_hash.h
184
- - ext/iodine/fiobj_internal.c
185
- - ext/iodine/fiobj_internal.h
186
198
  - ext/iodine/fiobj_json.c
187
199
  - ext/iodine/fiobj_json.h
188
200
  - ext/iodine/fiobj_numbers.c
189
201
  - ext/iodine/fiobj_numbers.h
190
- - ext/iodine/fiobj_primitives.c
191
- - ext/iodine/fiobj_primitives.h
192
202
  - ext/iodine/fiobj_str.c
193
203
  - ext/iodine/fiobj_str.h
194
- - ext/iodine/fiobj_sym.c
195
- - ext/iodine/fiobj_sym.h
196
204
  - ext/iodine/fiobject.c
197
205
  - ext/iodine/fiobject.h
198
- - ext/iodine/hex.c
199
- - ext/iodine/hex.h
200
206
  - ext/iodine/http.c
201
207
  - ext/iodine/http.h
202
208
  - ext/iodine/http1.c
203
209
  - ext/iodine/http1.h
204
210
  - ext/iodine/http1_parser.c
205
211
  - ext/iodine/http1_parser.h
206
- - ext/iodine/http1_request.c
207
- - ext/iodine/http1_request.h
208
- - ext/iodine/http1_response.c
209
- - ext/iodine/http1_response.h
210
- - ext/iodine/http_request.c
211
- - ext/iodine/http_request.h
212
- - ext/iodine/http_response.c
213
- - ext/iodine/http_response.h
212
+ - ext/iodine/http_internal.c
213
+ - ext/iodine/http_internal.h
214
+ - ext/iodine/http_mime_parser.h
214
215
  - ext/iodine/iodine.c
215
216
  - ext/iodine/iodine.h
216
217
  - ext/iodine/iodine_helpers.c
217
218
  - ext/iodine/iodine_helpers.h
218
219
  - ext/iodine/iodine_http.c
219
220
  - ext/iodine/iodine_http.h
221
+ - ext/iodine/iodine_json.c
222
+ - ext/iodine/iodine_json.h
220
223
  - ext/iodine/iodine_protocol.c
221
224
  - ext/iodine/iodine_protocol.h
222
225
  - ext/iodine/iodine_pubsub.c
223
226
  - ext/iodine/iodine_pubsub.h
224
227
  - ext/iodine/iodine_websockets.c
225
228
  - ext/iodine/iodine_websockets.h
226
- - ext/iodine/misc.c
227
- - ext/iodine/misc.h
228
229
  - ext/iodine/pubsub.c
229
230
  - ext/iodine/pubsub.h
230
- - ext/iodine/random.c
231
- - ext/iodine/random.h
232
231
  - ext/iodine/rb-call.c
233
232
  - ext/iodine/rb-call.h
234
233
  - ext/iodine/rb-defer.c
234
+ - ext/iodine/rb-fiobj2rb.h
235
235
  - ext/iodine/rb-rack-io.c
236
236
  - ext/iodine/rb-rack-io.h
237
237
  - ext/iodine/rb-registry.c
238
238
  - ext/iodine/rb-registry.h
239
- - ext/iodine/redis_connection.c
240
- - ext/iodine/redis_connection.h
241
239
  - ext/iodine/redis_engine.c
242
240
  - ext/iodine/redis_engine.h
243
- - ext/iodine/resp.c
244
- - ext/iodine/resp.h
245
- - ext/iodine/sha1.c
246
- - ext/iodine/sha1.h
247
- - ext/iodine/sha2.c
248
- - ext/iodine/sha2.h
249
- - ext/iodine/siphash.c
250
- - ext/iodine/siphash.h
241
+ - ext/iodine/resp_parser.h
251
242
  - ext/iodine/sock.c
252
243
  - ext/iodine/sock.h
253
244
  - ext/iodine/spnlock.inc
254
245
  - ext/iodine/websocket_parser.h
255
246
  - ext/iodine/websockets.c
256
247
  - ext/iodine/websockets.h
257
- - ext/iodine/xor-crypt.c
258
- - ext/iodine/xor-crypt.h
259
248
  - iodine.gemspec
260
249
  - lib/iodine.rb
261
250
  - lib/iodine/cli.rb
251
+ - lib/iodine/json.rb
262
252
  - lib/iodine/monkeypatch.rb
263
253
  - lib/iodine/protocol.rb
264
254
  - lib/iodine/pubsub.rb
data/bin/ws-shootout DELETED
@@ -1,107 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- Dir.chdir(File.expand_path(File.join('..', '..'), __FILE__))
4
- puts `rake clean`
5
- puts `rake compile`
6
-
7
- require 'benchmark'
8
- require 'json'
9
- $LOAD_PATH.unshift File.expand_path(File.join('..', '..', 'lib'), __FILE__)
10
- require 'bundler/setup'
11
- require 'iodine'
12
- require 'rack'
13
-
14
-
15
- class ShootoutApp
16
- # the default HTTP response
17
- def self.call(env)
18
- if env['upgrade.websocket?'.freeze] # && env['HTTP_UPGRADE'.freeze] =~ /websocket/i
19
- env['upgrade.websocket'.freeze] = ShootoutApp.new
20
- return [0, {}, []]
21
- end
22
- out = "ENV:\r\n#{env.to_a.map { |h| "#{h[0]}: #{h[1]}" } .join "\n"}\n"
23
- request = Rack::Request.new(env)
24
- out += "\nRequest Path: #{request.path_info}\nParams:\r\n#{request.params.to_a.map { |h| "#{h[0]}: #{h[1]}" } .join "\n"}\n" unless request.params.empty?
25
- [200, { 'Content-Length' => out.length, 'Content-Type' => 'text/plain; charset=UTF-8;' }, [out]]
26
- end
27
- # we won't be using AutoDispatch, but directly using the `on_message` callback.
28
- def on_message data
29
- cmd, payload = JSON(data).values_at('type', 'payload')
30
- if cmd == 'echo'
31
- write({type: 'echo', payload: payload}.to_json)
32
- else
33
- msg = {type: 'broadcast', payload: payload}.to_json
34
- # Iodine::Websocket.each {|ws| ws.write msg}
35
- Iodine::Websocket.each_write(msg) # {|ws| true }
36
- # each_write(msg) # {|ws| true }
37
- # write msg
38
- write({type: "broadcastResult", payload: payload}.to_json)
39
- end
40
- end
41
- end
42
-
43
-
44
- # create the server object and setup any settings we might need.
45
- Iodine.threads ||= 4
46
- Iodine.processes ||= 1
47
- Iodine::Rack.public = nil
48
- Iodine::Rack.app = ShootoutApp
49
- Iodine.start
50
-
51
- # websocket-bench broadcast ws://127.0.0.1:3000/ --concurrent 10 --sample-size 100 --step-size 1000 --limit-percentile 95 --limit-rtt 250ms --initial-clients 1000
52
-
53
- #
54
- # server.on_http= Proc.new do |env|
55
- # # [200, {"Content-Length".freeze => "12".freeze}, ["Hello World!".freeze]];
56
- # if env["HTTP_UPGRADE".freeze] =~ /websocket/i.freeze
57
- # env['iodine.websocket'.freeze] = WSEcho.new
58
- # [0,{}, []]
59
- # else
60
- # req = Rack::Request.new env
61
- # res = Rack::Response.new
62
- # res.write "Hello World!".freeze
63
- # res.to_a
64
- # end
65
- # end
66
-
67
- # server.on_start do
68
- # server.run_every(1000) {puts "#{server.connection_count} clients connected."}
69
- # end
70
-
71
- # puts "Press enter to start (#{Process.pid})"
72
- # gets
73
-
74
- # def nag
75
- # puts `ab -n 200000 -c 2000 -k http://127.0.0.1:3000/`
76
- # sleep 2
77
- # end
78
- #
79
- # nag while true
80
- #
81
- # def nag
82
- # puts `wrk -c2000 -d10 -t4 http://localhost:3000/`
83
- # sleep 3
84
- # end
85
- #
86
- # nag while true
87
-
88
- # ab -n 100000 -c 200 -k http://127.0.0.1:3000/
89
- # ab -n 100000 -c 4000 -k http://127.0.0.1:3000/
90
- # ab -n 1000000 -c 20000 -k http://127.0.0.1:3000/
91
- # ~/ruby/wrk/wrk -c400 -d10 -t12 http://localhost:3000/
92
- # wrk -c200 -d4 -t12 http://localhost:3000/
93
- # ab -n 2000 -c 20 -H "Connection: close" http://127.0.0.1:3000/
94
- # RACK_ENV="production" rackup -p 3000 -s iodine
95
-
96
- # thor --amount 5000 ws://localhost:3000/echo
97
- # thor --amount 5000 ws://localhost:3000/broadcast
98
-
99
- # ws = new WebSocket("ws://localhost:3000"); ws.onmessage = function(e) {console.log("Got message!"); console.log(e.data);}; ws.onclose = function(e) {console.log("closed")}; ws.onopen = function(e) {ws.send("hi");};
100
- # for(i = 0; i< 256; i++) {
101
- # ws = new WebSocket("ws://localhost:3000");
102
- # ws.onmessage = function(e) {console.log("Got message!"); console.log(e.data); e.target.close(); };
103
- # ws.onclose = function(e) {console.log("closed")};
104
- # ws.onopen = function(e) {e.target.send("hi");};
105
- # };
106
-
107
- # sleep 10 while `websocket-bench broadcast ws://127.0.0.1:3000/ --concurrent 10 --sample-size 100 --step-size 1000 --limit-percentile 95 --limit-rtt 250ms --initial-clients 1000`.tap {|s| puts s; puts "zzz..."}
@@ -1,56 +0,0 @@
1
- # This is a Websocket echo application.
2
- #
3
- # Running this application from the command line is eacy with:
4
- #
5
- # iodine hello.ru
6
- #
7
- # Or, in single thread and single process:
8
- #
9
- # iodine -t 1 -w 1 hello.ru
10
- #
11
- # Benchmark with `ab` or `wrk` (a 5 seconds benchmark with 2000 concurrent clients):
12
- #
13
- # ab -c 2000 -t 5 -n 1000000 -k http://127.0.0.1:3000/
14
- # wrk -c2000 -d5 -t12 http://localhost:3000/
15
-
16
-
17
- # A simple router - Checks for Websocket Upgrade and answers HTTP.
18
- module MyHTTPRouter
19
- # This is the HTTP response object according to the Rack specification.
20
- HTTP_RESPONSE = [200, { 'Content-Type' => 'text/html',
21
- 'Content-Length' => '32' },
22
- ['Please connect using websockets.']]
23
-
24
- WS_RESPONSE = [0, {}, []].freeze
25
-
26
- # this is function will be called by the Rack server (iodine) for every request.
27
- def self.call env
28
- # check if this is an upgrade request.
29
- if(env['upgrade.websocket?'.freeze])
30
- env['upgrade.websocket'.freeze] = WebsocketBroadcast
31
- return WS_RESPONSE
32
- end
33
- # simply return the RESPONSE object, no matter what request was received.
34
- HTTP_RESPONSE
35
- end
36
- end
37
-
38
- # A simple Websocket Callback Object.
39
- class WebsocketBroadcast
40
- # seng a message to new clients.
41
- def on_open
42
- puts self
43
- write "Welcome to our echo service!"
44
- end
45
- # send a message, letting the client know the server is suggunt down.
46
- def on_shutdown
47
- write "Server shutting down. Goodbye."
48
- end
49
- # perform the echo
50
- def on_message data
51
- write data
52
- end
53
- end
54
-
55
- # this function call links our HelloWorld application with Rack
56
- run MyHTTPRouter
@@ -1,116 +0,0 @@
1
- /*
2
- Copyright: Boaz segev, 2016-2017
3
- License: MIT except for any non-public-domain algorithms (none that I'm aware
4
- of), which might be subject to their own licenses.
5
-
6
- Feel free to copy, use and enjoy in accordance with to the license(s).
7
- */
8
- #ifndef BSCRYPT_COMMON_H
9
- #define BSCRYPT_COMMON_H
10
- /* *****************************************************************************
11
- Environment - you can safely ignore this part... probably.
12
- */
13
-
14
- #include <stdint.h>
15
- #include <stdio.h>
16
- #include <stdlib.h>
17
- #include <string.h>
18
- #include <time.h>
19
-
20
- /* check for __uint128_t support */
21
- #if defined(__SIZEOF_INT128__) || defined(__SIZEOF_INT128__)
22
- #define HAS_UINT128
23
- #endif
24
-
25
- /* check for features used by lib-bscrypt using include file methology */
26
- #ifdef __has_include
27
-
28
- /* check for unix support */
29
- #if __has_include(<unistd.h>) && __has_include(<pthread.h>)
30
- #ifndef HAS_UNIX_FEATURES
31
- #define HAS_UNIX_FEATURES
32
- #endif
33
- #endif
34
-
35
- /* include intrinsics if supported */
36
- #if __has_include(<x86intrin.h>)
37
- #include <x86intrin.h>
38
- #define HAVE_X86Intrin
39
- /*
40
- see: https://software.intel.com/en-us/node/513411
41
- and: https://software.intel.com/sites/landingpage/IntrinsicsGuide/
42
- */
43
- #endif /* __has_include(<x86intrin.h>) */
44
-
45
- #elif defined(__unix__) || defined(__linux__) || defined(__APPLE__)
46
- #ifndef HAS_UNIX_FEATURES
47
- #define HAS_UNIX_FEATURES
48
- #endif
49
-
50
- #endif /* __has_include */
51
-
52
- // clang-format off
53
- #if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
54
- # if defined(__has_include)
55
- # if __has_include(<endian.h>)
56
- # include <endian.h>
57
- # elif __has_include(<sys/endian.h>)
58
- # include <sys/endian.h>
59
- # endif
60
- # endif
61
- # if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) && \
62
- __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
63
- # define __BIG_ENDIAN__
64
- # endif
65
- #endif
66
-
67
- #ifndef UNUSED_FUNC
68
- # define UNUSED_FUNC __attribute__((unused))
69
- #endif
70
- // clang-format on
71
-
72
- /* *****************************************************************************
73
- C++ extern
74
- */
75
- #if defined(__cplusplus)
76
- extern "C" {
77
- #endif
78
-
79
- /* ***************************************************************************
80
- Types commonly used by the bscrypt libraries
81
- */
82
-
83
- typedef union {
84
- #ifdef HAVE_X86Intrin
85
- __m128i mm;
86
- #endif
87
- #ifdef HAS_UINT128
88
- __uint128_t i;
89
- #endif
90
- uint8_t bytes[16];
91
- uint8_t matrix[4][4];
92
- uint32_t words_small[4];
93
- uint64_t words[2];
94
- } bits128_u;
95
-
96
- typedef union {
97
- #if defined(HAVE_X86Intrin) && defined(__AVX__)
98
- __m256i mm;
99
- #endif
100
- #ifdef HAS_UINT128
101
- __uint128_t huge[2];
102
- #endif
103
- uint8_t bytes[32];
104
- uint8_t matrix[8][4];
105
- uint32_t ints[8];
106
- uint64_t words[4];
107
- } bits256_u;
108
-
109
- /* *****************************************************************************
110
- C++ extern finish
111
- */
112
- #if defined(__cplusplus)
113
- }
114
- #endif
115
-
116
- #endif