+5
.github/ISSUE_TEMPLATE/config.yml
+5
.github/ISSUE_TEMPLATE/config.yml
+40
.github/workflows/docker.yml
+40
.github/workflows/docker.yml
···
1
+
name: Deploy Docker image
2
+
on:
3
+
push:
4
+
branches:
5
+
- master
6
+
7
+
env:
8
+
REGISTRY: ghcr.io
9
+
IMAGE_NAME: ${{ github.repository }}
10
+
11
+
jobs:
12
+
deploy:
13
+
runs-on: ubuntu-latest
14
+
permissions:
15
+
contents: read
16
+
packages: write
17
+
18
+
steps:
19
+
- name: Checkout repo
20
+
uses: actions/checkout@v3
21
+
22
+
- name: Login to GitHub container registry
23
+
uses: docker/login-action@v2
24
+
with:
25
+
registry: ${{ env.REGISTRY }}
26
+
username: ${{ github.repository_owner }}
27
+
password: ${{ secrets.GITHUB_TOKEN }}
28
+
29
+
- name: Extract metadata for Docker
30
+
id: meta
31
+
uses: docker/metadata-action@v4
32
+
with:
33
+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
34
+
35
+
- name: Build and push Docker image
36
+
uses: docker/build-push-action@v4
37
+
with:
38
+
context: .
39
+
push: true
40
+
tags: ${{ steps.meta.outputs.tags }}
+2
.github/workflows/rust.yml
+2
.github/workflows/rust.yml
+55
CHANGELOG.md
+55
CHANGELOG.md
···
1
+
# Changelog
2
+
3
+
## [Unreleased] - _TBD_
4
+
5
+
## [v0.4.0] - 2024-03-19
6
+
7
+
### Added
8
+
9
+
- Implemented the function histories command.
10
+
- Configurable time limits.
11
+
12
+
### Fixed
13
+
14
+
- RPC HelloResult will now report if deletes are enabled.
15
+
16
+
### Changes
17
+
18
+
- Applied code formatting using `cargo fmt`
19
+
20
+
## [v0.3.0] - 2023-08-22
21
+
22
+
### Added
23
+
24
+
- This changelog.
25
+
- Support for IDA 8.1+ delete command.
26
+
- Pooling for connections to database.
27
+
- Attempt to cancel immutable database queries if client leaves.
28
+
- Database migrations via Diesel ORM.
29
+
- Support for IDA 8.3+ hello response.
30
+
- Add Metrics for prometheus.
31
+
32
+
### Fixed
33
+
34
+
- 8K stack size is too small for debug builds.
35
+
36
+
## [v0.2.0] - 2022-10-12
37
+
38
+
### Added
39
+
40
+
- Protocol: support for IDA 8.1+ user authentication.
41
+
- Client connection duration limitations.
42
+
43
+
### Changed
44
+
45
+
- Tokio's thread size is reduced from 4M to 8K.
46
+
47
+
## [v0.1.0] - 2021-01-21
48
+
49
+
This is Lumen's first tagged release. It contains a few fixes and dependency updates since the initial commit (2020-12-17).
50
+
51
+
[Unreleased]: https://github.com/naim94a/lumen/compare/v0.4.0...HEAD
52
+
[v0.4.0]: https://github.com/naim94a/lumen/compare/v0.3.0...v0.4.0
53
+
[v0.3.0]: https://github.com/naim94a/lumen/compare/v0.2.0...v0.3.0
54
+
[v0.2.0]: https://github.com/naim94a/lumen/compare/v0.1.0...v0.2.0
55
+
[v0.1.0]: https://github.com/naim94a/lumen/releases/tag/v0.1.0
+938
-409
Cargo.lock
+938
-409
Cargo.lock
···
3
3
version = 3
4
4
5
5
[[package]]
6
+
name = "addr2line"
7
+
version = "0.22.0"
8
+
source = "registry+https://github.com/rust-lang/crates.io-index"
9
+
checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678"
10
+
dependencies = [
11
+
"gimli",
12
+
]
13
+
14
+
[[package]]
15
+
name = "adler"
16
+
version = "1.0.2"
17
+
source = "registry+https://github.com/rust-lang/crates.io-index"
18
+
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
19
+
20
+
[[package]]
6
21
name = "aho-corasick"
7
-
version = "0.7.19"
22
+
version = "1.1.3"
8
23
source = "registry+https://github.com/rust-lang/crates.io-index"
9
-
checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e"
24
+
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
10
25
dependencies = [
11
26
"memchr",
12
27
]
13
28
14
29
[[package]]
30
+
name = "anstream"
31
+
version = "0.6.15"
32
+
source = "registry+https://github.com/rust-lang/crates.io-index"
33
+
checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526"
34
+
dependencies = [
35
+
"anstyle",
36
+
"anstyle-parse",
37
+
"anstyle-query",
38
+
"anstyle-wincon",
39
+
"colorchoice",
40
+
"is_terminal_polyfill",
41
+
"utf8parse",
42
+
]
43
+
44
+
[[package]]
45
+
name = "anstyle"
46
+
version = "1.0.8"
47
+
source = "registry+https://github.com/rust-lang/crates.io-index"
48
+
checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1"
49
+
50
+
[[package]]
51
+
name = "anstyle-parse"
52
+
version = "0.2.5"
53
+
source = "registry+https://github.com/rust-lang/crates.io-index"
54
+
checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb"
55
+
dependencies = [
56
+
"utf8parse",
57
+
]
58
+
59
+
[[package]]
60
+
name = "anstyle-query"
61
+
version = "1.1.1"
62
+
source = "registry+https://github.com/rust-lang/crates.io-index"
63
+
checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a"
64
+
dependencies = [
65
+
"windows-sys 0.52.0",
66
+
]
67
+
68
+
[[package]]
69
+
name = "anstyle-wincon"
70
+
version = "3.0.4"
71
+
source = "registry+https://github.com/rust-lang/crates.io-index"
72
+
checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8"
73
+
dependencies = [
74
+
"anstyle",
75
+
"windows-sys 0.52.0",
76
+
]
77
+
78
+
[[package]]
79
+
name = "anyhow"
80
+
version = "1.0.86"
81
+
source = "registry+https://github.com/rust-lang/crates.io-index"
82
+
checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
83
+
84
+
[[package]]
15
85
name = "async-trait"
16
-
version = "0.1.57"
86
+
version = "0.1.81"
17
87
source = "registry+https://github.com/rust-lang/crates.io-index"
18
-
checksum = "76464446b8bc32758d7e88ee1a804d9914cd9b1cb264c029899680b0be29826f"
88
+
checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107"
19
89
dependencies = [
20
90
"proc-macro2",
21
91
"quote",
···
23
93
]
24
94
25
95
[[package]]
26
-
name = "atty"
27
-
version = "0.2.14"
96
+
name = "autocfg"
97
+
version = "1.3.0"
98
+
source = "registry+https://github.com/rust-lang/crates.io-index"
99
+
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
100
+
101
+
[[package]]
102
+
name = "backtrace"
103
+
version = "0.3.73"
28
104
source = "registry+https://github.com/rust-lang/crates.io-index"
29
-
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
105
+
checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a"
30
106
dependencies = [
31
-
"hermit-abi",
107
+
"addr2line",
108
+
"cc",
109
+
"cfg-if",
32
110
"libc",
33
-
"winapi",
111
+
"miniz_oxide",
112
+
"object",
113
+
"rustc-demangle",
34
114
]
35
115
36
116
[[package]]
37
-
name = "autocfg"
38
-
version = "1.1.0"
117
+
name = "base64"
118
+
version = "0.21.7"
39
119
source = "registry+https://github.com/rust-lang/crates.io-index"
40
-
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
120
+
checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
41
121
42
122
[[package]]
43
123
name = "base64"
44
-
version = "0.13.0"
124
+
version = "0.22.1"
45
125
source = "registry+https://github.com/rust-lang/crates.io-index"
46
-
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
126
+
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
127
+
128
+
[[package]]
129
+
name = "bb8"
130
+
version = "0.8.5"
131
+
source = "registry+https://github.com/rust-lang/crates.io-index"
132
+
checksum = "b10cf871f3ff2ce56432fddc2615ac7acc3aa22ca321f8fea800846fbb32f188"
133
+
dependencies = [
134
+
"async-trait",
135
+
"futures-util",
136
+
"parking_lot",
137
+
"tokio",
138
+
]
47
139
48
140
[[package]]
49
141
name = "binascii"
···
58
150
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
59
151
60
152
[[package]]
153
+
name = "bitflags"
154
+
version = "2.6.0"
155
+
source = "registry+https://github.com/rust-lang/crates.io-index"
156
+
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
157
+
158
+
[[package]]
61
159
name = "block-buffer"
62
-
version = "0.10.3"
160
+
version = "0.10.4"
63
161
source = "registry+https://github.com/rust-lang/crates.io-index"
64
-
checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e"
162
+
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
65
163
dependencies = [
66
164
"generic-array",
67
165
]
68
166
69
167
[[package]]
70
-
name = "buf_redux"
71
-
version = "0.8.4"
168
+
name = "bumpalo"
169
+
version = "3.16.0"
72
170
source = "registry+https://github.com/rust-lang/crates.io-index"
73
-
checksum = "b953a6887648bb07a535631f2bc00fbdb2a2216f135552cb3f534ed136b9c07f"
74
-
dependencies = [
75
-
"memchr",
76
-
"safemem",
77
-
]
171
+
checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
78
172
79
173
[[package]]
80
174
name = "byteorder"
81
-
version = "1.4.3"
175
+
version = "1.5.0"
82
176
source = "registry+https://github.com/rust-lang/crates.io-index"
83
-
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
177
+
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
84
178
85
179
[[package]]
86
180
name = "bytes"
87
-
version = "1.2.1"
181
+
version = "1.7.1"
88
182
source = "registry+https://github.com/rust-lang/crates.io-index"
89
-
checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db"
183
+
checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50"
90
184
91
185
[[package]]
92
186
name = "cc"
93
-
version = "1.0.73"
187
+
version = "1.1.10"
94
188
source = "registry+https://github.com/rust-lang/crates.io-index"
95
-
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
189
+
checksum = "e9e8aabfac534be767c909e0690571677d49f41bd8465ae876fe043d52ba5292"
96
190
97
191
[[package]]
98
192
name = "cfg-if"
···
102
196
103
197
[[package]]
104
198
name = "clap"
105
-
version = "4.0.13"
199
+
version = "4.5.15"
200
+
source = "registry+https://github.com/rust-lang/crates.io-index"
201
+
checksum = "11d8838454fda655dafd3accb2b6e2bea645b9e4078abe84a22ceb947235c5cc"
202
+
dependencies = [
203
+
"clap_builder",
204
+
]
205
+
206
+
[[package]]
207
+
name = "clap_builder"
208
+
version = "4.5.15"
106
209
source = "registry+https://github.com/rust-lang/crates.io-index"
107
-
checksum = "69d64e88428747154bd8bc378d178377ef4dace7a5735ca1f3855be72f2c2cb5"
210
+
checksum = "216aec2b177652e3846684cbfe25c9964d18ec45234f0f5da5157b207ed1aab6"
108
211
dependencies = [
109
-
"atty",
110
-
"bitflags",
212
+
"anstream",
213
+
"anstyle",
111
214
"clap_lex",
112
215
"strsim",
113
-
"termcolor",
114
216
]
115
217
116
218
[[package]]
117
219
name = "clap_lex"
118
-
version = "0.3.0"
220
+
version = "0.7.2"
221
+
source = "registry+https://github.com/rust-lang/crates.io-index"
222
+
checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97"
223
+
224
+
[[package]]
225
+
name = "colorchoice"
226
+
version = "1.0.2"
119
227
source = "registry+https://github.com/rust-lang/crates.io-index"
120
-
checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8"
121
-
dependencies = [
122
-
"os_str_bytes",
123
-
]
228
+
checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
124
229
125
230
[[package]]
126
231
name = "common"
127
232
version = "0.2.0"
128
233
dependencies = [
234
+
"anyhow",
129
235
"binascii",
236
+
"diesel",
237
+
"diesel-async",
130
238
"futures-util",
131
239
"log",
132
240
"native-tls",
133
241
"postgres-native-tls",
242
+
"prometheus-client",
134
243
"serde",
244
+
"time",
135
245
"tokio",
136
246
"tokio-postgres",
137
247
"toml",
···
140
250
141
251
[[package]]
142
252
name = "core-foundation"
143
-
version = "0.9.3"
253
+
version = "0.9.4"
144
254
source = "registry+https://github.com/rust-lang/crates.io-index"
145
-
checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146"
255
+
checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f"
146
256
dependencies = [
147
257
"core-foundation-sys",
148
258
"libc",
···
150
260
151
261
[[package]]
152
262
name = "core-foundation-sys"
153
-
version = "0.8.3"
263
+
version = "0.8.7"
154
264
source = "registry+https://github.com/rust-lang/crates.io-index"
155
-
checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
265
+
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
156
266
157
267
[[package]]
158
268
name = "cpufeatures"
159
-
version = "0.2.5"
269
+
version = "0.2.13"
160
270
source = "registry+https://github.com/rust-lang/crates.io-index"
161
-
checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320"
271
+
checksum = "51e852e6dc9a5bed1fae92dd2375037bf2b768725bf3be87811edee3249d09ad"
162
272
dependencies = [
163
273
"libc",
164
274
]
···
174
284
]
175
285
176
286
[[package]]
287
+
name = "darling"
288
+
version = "0.20.10"
289
+
source = "registry+https://github.com/rust-lang/crates.io-index"
290
+
checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989"
291
+
dependencies = [
292
+
"darling_core",
293
+
"darling_macro",
294
+
]
295
+
296
+
[[package]]
297
+
name = "darling_core"
298
+
version = "0.20.10"
299
+
source = "registry+https://github.com/rust-lang/crates.io-index"
300
+
checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5"
301
+
dependencies = [
302
+
"fnv",
303
+
"ident_case",
304
+
"proc-macro2",
305
+
"quote",
306
+
"strsim",
307
+
"syn",
308
+
]
309
+
310
+
[[package]]
311
+
name = "darling_macro"
312
+
version = "0.20.10"
313
+
source = "registry+https://github.com/rust-lang/crates.io-index"
314
+
checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806"
315
+
dependencies = [
316
+
"darling_core",
317
+
"quote",
318
+
"syn",
319
+
]
320
+
321
+
[[package]]
322
+
name = "data-encoding"
323
+
version = "2.6.0"
324
+
source = "registry+https://github.com/rust-lang/crates.io-index"
325
+
checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2"
326
+
327
+
[[package]]
328
+
name = "deranged"
329
+
version = "0.3.11"
330
+
source = "registry+https://github.com/rust-lang/crates.io-index"
331
+
checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4"
332
+
dependencies = [
333
+
"powerfmt",
334
+
]
335
+
336
+
[[package]]
337
+
name = "diesel"
338
+
version = "2.2.2"
339
+
source = "registry+https://github.com/rust-lang/crates.io-index"
340
+
checksum = "bf97ee7261bb708fa3402fa9c17a54b70e90e3cb98afb3dc8999d5512cb03f94"
341
+
dependencies = [
342
+
"bitflags 2.6.0",
343
+
"byteorder",
344
+
"diesel_derives",
345
+
"itoa",
346
+
"time",
347
+
]
348
+
349
+
[[package]]
350
+
name = "diesel-async"
351
+
version = "0.5.0"
352
+
source = "registry+https://github.com/rust-lang/crates.io-index"
353
+
checksum = "fcb799bb6f8ca6a794462125d7b8983b0c86e6c93a33a9c55934a4a5de4409d3"
354
+
dependencies = [
355
+
"async-trait",
356
+
"bb8",
357
+
"diesel",
358
+
"futures-util",
359
+
"scoped-futures",
360
+
"tokio",
361
+
"tokio-postgres",
362
+
]
363
+
364
+
[[package]]
365
+
name = "diesel_derives"
366
+
version = "2.2.2"
367
+
source = "registry+https://github.com/rust-lang/crates.io-index"
368
+
checksum = "d6ff2be1e7312c858b2ef974f5c7089833ae57b5311b334b30923af58e5718d8"
369
+
dependencies = [
370
+
"diesel_table_macro_syntax",
371
+
"dsl_auto_type",
372
+
"proc-macro2",
373
+
"quote",
374
+
"syn",
375
+
]
376
+
377
+
[[package]]
378
+
name = "diesel_table_macro_syntax"
379
+
version = "0.2.0"
380
+
source = "registry+https://github.com/rust-lang/crates.io-index"
381
+
checksum = "209c735641a413bc68c4923a9d6ad4bcb3ca306b794edaa7eb0b3228a99ffb25"
382
+
dependencies = [
383
+
"syn",
384
+
]
385
+
386
+
[[package]]
177
387
name = "digest"
178
-
version = "0.10.5"
388
+
version = "0.10.7"
179
389
source = "registry+https://github.com/rust-lang/crates.io-index"
180
-
checksum = "adfbc57365a37acbd2ebf2b64d7e69bb766e2fea813521ed536f5d0520dcf86c"
390
+
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
181
391
dependencies = [
182
392
"block-buffer",
183
393
"crypto-common",
···
185
395
]
186
396
187
397
[[package]]
398
+
name = "dsl_auto_type"
399
+
version = "0.1.2"
400
+
source = "registry+https://github.com/rust-lang/crates.io-index"
401
+
checksum = "c5d9abe6314103864cc2d8901b7ae224e0ab1a103a0a416661b4097b0779b607"
402
+
dependencies = [
403
+
"darling",
404
+
"either",
405
+
"heck",
406
+
"proc-macro2",
407
+
"quote",
408
+
"syn",
409
+
]
410
+
411
+
[[package]]
412
+
name = "dtoa"
413
+
version = "1.0.9"
414
+
source = "registry+https://github.com/rust-lang/crates.io-index"
415
+
checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653"
416
+
417
+
[[package]]
418
+
name = "either"
419
+
version = "1.13.0"
420
+
source = "registry+https://github.com/rust-lang/crates.io-index"
421
+
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
422
+
423
+
[[package]]
424
+
name = "encoding_rs"
425
+
version = "0.8.34"
426
+
source = "registry+https://github.com/rust-lang/crates.io-index"
427
+
checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59"
428
+
dependencies = [
429
+
"cfg-if",
430
+
]
431
+
432
+
[[package]]
188
433
name = "env_logger"
189
-
version = "0.7.1"
434
+
version = "0.10.2"
190
435
source = "registry+https://github.com/rust-lang/crates.io-index"
191
-
checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
436
+
checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580"
192
437
dependencies = [
193
-
"atty",
194
438
"humantime",
439
+
"is-terminal",
195
440
"log",
196
441
"regex",
197
442
"termcolor",
198
443
]
199
444
200
445
[[package]]
446
+
name = "equivalent"
447
+
version = "1.0.1"
448
+
source = "registry+https://github.com/rust-lang/crates.io-index"
449
+
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
450
+
451
+
[[package]]
452
+
name = "errno"
453
+
version = "0.3.9"
454
+
source = "registry+https://github.com/rust-lang/crates.io-index"
455
+
checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba"
456
+
dependencies = [
457
+
"libc",
458
+
"windows-sys 0.52.0",
459
+
]
460
+
461
+
[[package]]
201
462
name = "fallible-iterator"
202
463
version = "0.2.0"
203
464
source = "registry+https://github.com/rust-lang/crates.io-index"
···
205
466
206
467
[[package]]
207
468
name = "fastrand"
208
-
version = "1.8.0"
469
+
version = "2.1.0"
209
470
source = "registry+https://github.com/rust-lang/crates.io-index"
210
-
checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499"
211
-
dependencies = [
212
-
"instant",
213
-
]
471
+
checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a"
214
472
215
473
[[package]]
216
474
name = "fnv"
···
235
493
236
494
[[package]]
237
495
name = "form_urlencoded"
238
-
version = "1.1.0"
496
+
version = "1.2.1"
239
497
source = "registry+https://github.com/rust-lang/crates.io-index"
240
-
checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8"
498
+
checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456"
241
499
dependencies = [
242
500
"percent-encoding",
243
501
]
244
502
245
503
[[package]]
246
504
name = "futures"
247
-
version = "0.3.24"
505
+
version = "0.3.30"
248
506
source = "registry+https://github.com/rust-lang/crates.io-index"
249
-
checksum = "7f21eda599937fba36daeb58a22e8f5cee2d14c4a17b5b7739c7c8e5e3b8230c"
507
+
checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0"
250
508
dependencies = [
251
509
"futures-channel",
252
510
"futures-core",
···
259
517
260
518
[[package]]
261
519
name = "futures-channel"
262
-
version = "0.3.24"
520
+
version = "0.3.30"
263
521
source = "registry+https://github.com/rust-lang/crates.io-index"
264
-
checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050"
522
+
checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78"
265
523
dependencies = [
266
524
"futures-core",
267
525
"futures-sink",
···
269
527
270
528
[[package]]
271
529
name = "futures-core"
272
-
version = "0.3.24"
530
+
version = "0.3.30"
273
531
source = "registry+https://github.com/rust-lang/crates.io-index"
274
-
checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf"
532
+
checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d"
275
533
276
534
[[package]]
277
535
name = "futures-executor"
278
-
version = "0.3.24"
536
+
version = "0.3.30"
279
537
source = "registry+https://github.com/rust-lang/crates.io-index"
280
-
checksum = "9ff63c23854bee61b6e9cd331d523909f238fc7636290b96826e9cfa5faa00ab"
538
+
checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d"
281
539
dependencies = [
282
540
"futures-core",
283
541
"futures-task",
···
286
544
287
545
[[package]]
288
546
name = "futures-io"
289
-
version = "0.3.24"
547
+
version = "0.3.30"
290
548
source = "registry+https://github.com/rust-lang/crates.io-index"
291
-
checksum = "bbf4d2a7a308fd4578637c0b17c7e1c7ba127b8f6ba00b29f717e9655d85eb68"
549
+
checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1"
292
550
293
551
[[package]]
294
552
name = "futures-macro"
295
-
version = "0.3.24"
553
+
version = "0.3.30"
296
554
source = "registry+https://github.com/rust-lang/crates.io-index"
297
-
checksum = "42cd15d1c7456c04dbdf7e88bcd69760d74f3a798d6444e16974b505b0e62f17"
555
+
checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
298
556
dependencies = [
299
557
"proc-macro2",
300
558
"quote",
···
303
561
304
562
[[package]]
305
563
name = "futures-sink"
306
-
version = "0.3.24"
564
+
version = "0.3.30"
307
565
source = "registry+https://github.com/rust-lang/crates.io-index"
308
-
checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56"
566
+
checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5"
309
567
310
568
[[package]]
311
569
name = "futures-task"
312
-
version = "0.3.24"
570
+
version = "0.3.30"
313
571
source = "registry+https://github.com/rust-lang/crates.io-index"
314
-
checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1"
572
+
checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004"
315
573
316
574
[[package]]
317
575
name = "futures-util"
318
-
version = "0.3.24"
576
+
version = "0.3.30"
319
577
source = "registry+https://github.com/rust-lang/crates.io-index"
320
-
checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90"
578
+
checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48"
321
579
dependencies = [
322
580
"futures-channel",
323
581
"futures-core",
···
333
591
334
592
[[package]]
335
593
name = "generic-array"
336
-
version = "0.14.6"
594
+
version = "0.14.7"
337
595
source = "registry+https://github.com/rust-lang/crates.io-index"
338
-
checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9"
596
+
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
339
597
dependencies = [
340
598
"typenum",
341
599
"version_check",
···
343
601
344
602
[[package]]
345
603
name = "getrandom"
346
-
version = "0.2.7"
604
+
version = "0.2.15"
347
605
source = "registry+https://github.com/rust-lang/crates.io-index"
348
-
checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6"
606
+
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
349
607
dependencies = [
350
608
"cfg-if",
351
609
"libc",
352
610
"wasi",
353
611
]
612
+
613
+
[[package]]
614
+
name = "gimli"
615
+
version = "0.29.0"
616
+
source = "registry+https://github.com/rust-lang/crates.io-index"
617
+
checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd"
354
618
355
619
[[package]]
356
620
name = "h2"
357
-
version = "0.3.14"
621
+
version = "0.3.26"
358
622
source = "registry+https://github.com/rust-lang/crates.io-index"
359
-
checksum = "5ca32592cf21ac7ccab1825cd87f6c9b3d9022c44d086172ed0966bec8af30be"
623
+
checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8"
360
624
dependencies = [
361
625
"bytes",
362
626
"fnv",
363
627
"futures-core",
364
628
"futures-sink",
365
629
"futures-util",
366
-
"http",
630
+
"http 0.2.12",
367
631
"indexmap",
368
632
"slab",
369
633
"tokio",
···
373
637
374
638
[[package]]
375
639
name = "hashbrown"
376
-
version = "0.12.3"
640
+
version = "0.14.5"
377
641
source = "registry+https://github.com/rust-lang/crates.io-index"
378
-
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
642
+
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
379
643
380
644
[[package]]
381
645
name = "headers"
382
-
version = "0.3.8"
646
+
version = "0.3.9"
383
647
source = "registry+https://github.com/rust-lang/crates.io-index"
384
-
checksum = "f3e372db8e5c0d213e0cd0b9be18be2aca3d44cf2fe30a9d46a65581cd454584"
648
+
checksum = "06683b93020a07e3dbcf5f8c0f6d40080d725bea7936fc01ad345c01b97dc270"
385
649
dependencies = [
386
-
"base64",
387
-
"bitflags",
650
+
"base64 0.21.7",
388
651
"bytes",
389
652
"headers-core",
390
-
"http",
653
+
"http 0.2.12",
391
654
"httpdate",
392
655
"mime",
393
656
"sha1",
···
399
662
source = "registry+https://github.com/rust-lang/crates.io-index"
400
663
checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429"
401
664
dependencies = [
402
-
"http",
665
+
"http 0.2.12",
403
666
]
404
667
405
668
[[package]]
669
+
name = "heck"
670
+
version = "0.5.0"
671
+
source = "registry+https://github.com/rust-lang/crates.io-index"
672
+
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
673
+
674
+
[[package]]
406
675
name = "hermit-abi"
407
-
version = "0.1.19"
676
+
version = "0.3.9"
408
677
source = "registry+https://github.com/rust-lang/crates.io-index"
409
-
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
410
-
dependencies = [
411
-
"libc",
412
-
]
678
+
checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
413
679
414
680
[[package]]
415
681
name = "hmac"
···
422
688
423
689
[[package]]
424
690
name = "http"
425
-
version = "0.2.8"
691
+
version = "0.2.12"
426
692
source = "registry+https://github.com/rust-lang/crates.io-index"
427
-
checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399"
693
+
checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1"
694
+
dependencies = [
695
+
"bytes",
696
+
"fnv",
697
+
"itoa",
698
+
]
699
+
700
+
[[package]]
701
+
name = "http"
702
+
version = "1.1.0"
703
+
source = "registry+https://github.com/rust-lang/crates.io-index"
704
+
checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258"
428
705
dependencies = [
429
706
"bytes",
430
707
"fnv",
···
433
710
434
711
[[package]]
435
712
name = "http-body"
436
-
version = "0.4.5"
713
+
version = "0.4.6"
437
714
source = "registry+https://github.com/rust-lang/crates.io-index"
438
-
checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1"
715
+
checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2"
439
716
dependencies = [
440
717
"bytes",
441
-
"http",
718
+
"http 0.2.12",
442
719
"pin-project-lite",
443
720
]
444
721
445
722
[[package]]
446
723
name = "httparse"
447
-
version = "1.8.0"
724
+
version = "1.9.4"
448
725
source = "registry+https://github.com/rust-lang/crates.io-index"
449
-
checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904"
726
+
checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9"
450
727
451
728
[[package]]
452
729
name = "httpdate"
453
-
version = "1.0.2"
730
+
version = "1.0.3"
454
731
source = "registry+https://github.com/rust-lang/crates.io-index"
455
-
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
732
+
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
456
733
457
734
[[package]]
458
735
name = "humantime"
459
-
version = "1.3.0"
736
+
version = "2.1.0"
460
737
source = "registry+https://github.com/rust-lang/crates.io-index"
461
-
checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
462
-
dependencies = [
463
-
"quick-error",
464
-
]
738
+
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
465
739
466
740
[[package]]
467
741
name = "hyper"
468
-
version = "0.14.20"
742
+
version = "0.14.30"
469
743
source = "registry+https://github.com/rust-lang/crates.io-index"
470
-
checksum = "02c929dc5c39e335a03c405292728118860721b10190d98c2a0f0efd5baafbac"
744
+
checksum = "a152ddd61dfaec7273fe8419ab357f33aee0d914c5f4efbf0d96fa749eea5ec9"
471
745
dependencies = [
472
746
"bytes",
473
747
"futures-channel",
474
748
"futures-core",
475
749
"futures-util",
476
750
"h2",
477
-
"http",
751
+
"http 0.2.12",
478
752
"http-body",
479
753
"httparse",
480
754
"httpdate",
···
488
762
]
489
763
490
764
[[package]]
765
+
name = "ident_case"
766
+
version = "1.0.1"
767
+
source = "registry+https://github.com/rust-lang/crates.io-index"
768
+
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
769
+
770
+
[[package]]
491
771
name = "idna"
492
-
version = "0.3.0"
772
+
version = "0.5.0"
493
773
source = "registry+https://github.com/rust-lang/crates.io-index"
494
-
checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6"
774
+
checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6"
495
775
dependencies = [
496
776
"unicode-bidi",
497
777
"unicode-normalization",
···
499
779
500
780
[[package]]
501
781
name = "indexmap"
502
-
version = "1.9.1"
782
+
version = "2.3.0"
503
783
source = "registry+https://github.com/rust-lang/crates.io-index"
504
-
checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e"
784
+
checksum = "de3fc2e30ba82dd1b3911c8de1ffc143c74a914a14e99514d7637e3099df5ea0"
505
785
dependencies = [
506
-
"autocfg",
786
+
"equivalent",
507
787
"hashbrown",
508
788
]
509
789
510
790
[[package]]
511
-
name = "instant"
512
-
version = "0.1.12"
791
+
name = "is-terminal"
792
+
version = "0.4.12"
513
793
source = "registry+https://github.com/rust-lang/crates.io-index"
514
-
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
794
+
checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b"
515
795
dependencies = [
516
-
"cfg-if",
796
+
"hermit-abi",
797
+
"libc",
798
+
"windows-sys 0.52.0",
517
799
]
518
800
519
801
[[package]]
802
+
name = "is_terminal_polyfill"
803
+
version = "1.70.1"
804
+
source = "registry+https://github.com/rust-lang/crates.io-index"
805
+
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
806
+
807
+
[[package]]
520
808
name = "itoa"
521
-
version = "1.0.4"
809
+
version = "1.0.11"
522
810
source = "registry+https://github.com/rust-lang/crates.io-index"
523
-
checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"
811
+
checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
524
812
525
813
[[package]]
526
-
name = "lazy_static"
527
-
version = "1.4.0"
814
+
name = "js-sys"
815
+
version = "0.3.70"
528
816
source = "registry+https://github.com/rust-lang/crates.io-index"
529
-
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
817
+
checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a"
818
+
dependencies = [
819
+
"wasm-bindgen",
820
+
]
530
821
531
822
[[package]]
532
823
name = "libc"
533
-
version = "0.2.135"
824
+
version = "0.2.155"
534
825
source = "registry+https://github.com/rust-lang/crates.io-index"
535
-
checksum = "68783febc7782c6c5cb401fbda4de5a9898be1762314da0bb2c10ced61f18b0c"
826
+
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
827
+
828
+
[[package]]
829
+
name = "linux-raw-sys"
830
+
version = "0.4.14"
831
+
source = "registry+https://github.com/rust-lang/crates.io-index"
832
+
checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89"
536
833
537
834
[[package]]
538
835
name = "lock_api"
539
-
version = "0.4.9"
836
+
version = "0.4.12"
540
837
source = "registry+https://github.com/rust-lang/crates.io-index"
541
-
checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df"
838
+
checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17"
542
839
dependencies = [
543
840
"autocfg",
544
841
"scopeguard",
···
546
843
547
844
[[package]]
548
845
name = "log"
549
-
version = "0.4.17"
846
+
version = "0.4.22"
550
847
source = "registry+https://github.com/rust-lang/crates.io-index"
551
-
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
552
-
dependencies = [
553
-
"cfg-if",
554
-
]
848
+
checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
555
849
556
850
[[package]]
557
851
name = "lumen"
···
562
856
"log",
563
857
"native-tls",
564
858
"pretty_env_logger",
859
+
"prometheus-client",
565
860
"tokio",
566
861
"tokio-native-tls",
567
862
"warp",
···
569
864
570
865
[[package]]
571
866
name = "md-5"
572
-
version = "0.10.5"
867
+
version = "0.10.6"
573
868
source = "registry+https://github.com/rust-lang/crates.io-index"
574
-
checksum = "6365506850d44bff6e2fbcb5176cf63650e48bd45ef2fe2665ae1570e0f4b9ca"
869
+
checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf"
575
870
dependencies = [
871
+
"cfg-if",
576
872
"digest",
577
873
]
578
874
579
875
[[package]]
580
876
name = "memchr"
581
-
version = "2.5.0"
877
+
version = "2.7.4"
582
878
source = "registry+https://github.com/rust-lang/crates.io-index"
583
-
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
879
+
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
584
880
585
881
[[package]]
586
882
name = "mime"
587
-
version = "0.3.16"
883
+
version = "0.3.17"
588
884
source = "registry+https://github.com/rust-lang/crates.io-index"
589
-
checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
885
+
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
590
886
591
887
[[package]]
592
888
name = "mime_guess"
593
-
version = "2.0.4"
889
+
version = "2.0.5"
594
890
source = "registry+https://github.com/rust-lang/crates.io-index"
595
-
checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef"
891
+
checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e"
596
892
dependencies = [
597
893
"mime",
598
894
"unicase",
599
895
]
600
896
601
897
[[package]]
898
+
name = "miniz_oxide"
899
+
version = "0.7.4"
900
+
source = "registry+https://github.com/rust-lang/crates.io-index"
901
+
checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08"
902
+
dependencies = [
903
+
"adler",
904
+
]
905
+
906
+
[[package]]
602
907
name = "mio"
603
-
version = "0.8.4"
908
+
version = "1.0.2"
604
909
source = "registry+https://github.com/rust-lang/crates.io-index"
605
-
checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf"
910
+
checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec"
606
911
dependencies = [
912
+
"hermit-abi",
607
913
"libc",
608
-
"log",
609
914
"wasi",
610
-
"windows-sys",
915
+
"windows-sys 0.52.0",
611
916
]
612
917
613
918
[[package]]
614
-
name = "multipart"
615
-
version = "0.18.0"
919
+
name = "multer"
920
+
version = "2.1.0"
616
921
source = "registry+https://github.com/rust-lang/crates.io-index"
617
-
checksum = "00dec633863867f29cb39df64a397cdf4a6354708ddd7759f70c7fb51c5f9182"
922
+
checksum = "01acbdc23469fd8fe07ab135923371d5f5a422fbf9c522158677c8eb15bc51c2"
618
923
dependencies = [
619
-
"buf_redux",
924
+
"bytes",
925
+
"encoding_rs",
926
+
"futures-util",
927
+
"http 0.2.12",
620
928
"httparse",
621
929
"log",
930
+
"memchr",
622
931
"mime",
623
-
"mime_guess",
624
-
"quick-error",
625
-
"rand",
626
-
"safemem",
627
-
"tempfile",
628
-
"twoway",
932
+
"spin",
933
+
"version_check",
629
934
]
630
935
631
936
[[package]]
632
937
name = "native-tls"
633
-
version = "0.2.10"
938
+
version = "0.2.12"
634
939
source = "registry+https://github.com/rust-lang/crates.io-index"
635
-
checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9"
940
+
checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466"
636
941
dependencies = [
637
-
"lazy_static",
638
942
"libc",
639
943
"log",
640
944
"openssl",
···
647
951
]
648
952
649
953
[[package]]
650
-
name = "num_cpus"
651
-
version = "1.13.1"
954
+
name = "num-conv"
955
+
version = "0.1.0"
652
956
source = "registry+https://github.com/rust-lang/crates.io-index"
653
-
checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1"
957
+
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
958
+
959
+
[[package]]
960
+
name = "object"
961
+
version = "0.36.3"
962
+
source = "registry+https://github.com/rust-lang/crates.io-index"
963
+
checksum = "27b64972346851a39438c60b341ebc01bba47464ae329e55cf343eb93964efd9"
654
964
dependencies = [
655
-
"hermit-abi",
656
-
"libc",
965
+
"memchr",
657
966
]
658
967
659
968
[[package]]
660
969
name = "once_cell"
661
-
version = "1.15.0"
970
+
version = "1.19.0"
662
971
source = "registry+https://github.com/rust-lang/crates.io-index"
663
-
checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1"
972
+
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
664
973
665
974
[[package]]
666
975
name = "openssl"
667
-
version = "0.10.42"
976
+
version = "0.10.66"
668
977
source = "registry+https://github.com/rust-lang/crates.io-index"
669
-
checksum = "12fc0523e3bd51a692c8850d075d74dc062ccf251c0110668cbd921917118a13"
978
+
checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1"
670
979
dependencies = [
671
-
"bitflags",
980
+
"bitflags 2.6.0",
672
981
"cfg-if",
673
982
"foreign-types",
674
983
"libc",
···
679
988
680
989
[[package]]
681
990
name = "openssl-macros"
682
-
version = "0.1.0"
991
+
version = "0.1.1"
683
992
source = "registry+https://github.com/rust-lang/crates.io-index"
684
-
checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c"
993
+
checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
685
994
dependencies = [
686
995
"proc-macro2",
687
996
"quote",
···
696
1005
697
1006
[[package]]
698
1007
name = "openssl-sys"
699
-
version = "0.9.76"
1008
+
version = "0.9.103"
700
1009
source = "registry+https://github.com/rust-lang/crates.io-index"
701
-
checksum = "5230151e44c0f05157effb743e8d517472843121cf9243e8b81393edb5acd9ce"
1010
+
checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6"
702
1011
dependencies = [
703
-
"autocfg",
704
1012
"cc",
705
1013
"libc",
706
1014
"pkg-config",
707
1015
"vcpkg",
708
1016
]
709
-
710
-
[[package]]
711
-
name = "os_str_bytes"
712
-
version = "6.3.0"
713
-
source = "registry+https://github.com/rust-lang/crates.io-index"
714
-
checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff"
715
1017
716
1018
[[package]]
717
1019
name = "parking_lot"
718
-
version = "0.12.1"
1020
+
version = "0.12.3"
719
1021
source = "registry+https://github.com/rust-lang/crates.io-index"
720
-
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
1022
+
checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27"
721
1023
dependencies = [
722
1024
"lock_api",
723
1025
"parking_lot_core",
···
725
1027
726
1028
[[package]]
727
1029
name = "parking_lot_core"
728
-
version = "0.9.3"
1030
+
version = "0.9.10"
729
1031
source = "registry+https://github.com/rust-lang/crates.io-index"
730
-
checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929"
1032
+
checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
731
1033
dependencies = [
732
1034
"cfg-if",
733
1035
"libc",
734
-
"redox_syscall",
1036
+
"redox_syscall 0.5.3",
735
1037
"smallvec",
736
-
"windows-sys",
1038
+
"windows-targets",
737
1039
]
738
1040
739
1041
[[package]]
740
1042
name = "percent-encoding"
741
-
version = "2.2.0"
1043
+
version = "2.3.1"
742
1044
source = "registry+https://github.com/rust-lang/crates.io-index"
743
-
checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e"
1045
+
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
744
1046
745
1047
[[package]]
746
1048
name = "phf"
747
-
version = "0.11.1"
1049
+
version = "0.11.2"
748
1050
source = "registry+https://github.com/rust-lang/crates.io-index"
749
-
checksum = "928c6535de93548188ef63bb7c4036bd415cd8f36ad25af44b9789b2ee72a48c"
1051
+
checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc"
750
1052
dependencies = [
751
1053
"phf_shared",
752
1054
]
753
1055
754
1056
[[package]]
755
1057
name = "phf_shared"
756
-
version = "0.11.1"
1058
+
version = "0.11.2"
757
1059
source = "registry+https://github.com/rust-lang/crates.io-index"
758
-
checksum = "e1fb5f6f826b772a8d4c0394209441e7d37cbbb967ae9c7e0e8134365c9ee676"
1060
+
checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b"
759
1061
dependencies = [
760
1062
"siphasher",
761
1063
]
762
1064
763
1065
[[package]]
764
1066
name = "pin-project"
765
-
version = "1.0.12"
1067
+
version = "1.1.5"
766
1068
source = "registry+https://github.com/rust-lang/crates.io-index"
767
-
checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc"
1069
+
checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3"
768
1070
dependencies = [
769
1071
"pin-project-internal",
770
1072
]
771
1073
772
1074
[[package]]
773
1075
name = "pin-project-internal"
774
-
version = "1.0.12"
1076
+
version = "1.1.5"
775
1077
source = "registry+https://github.com/rust-lang/crates.io-index"
776
-
checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55"
1078
+
checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965"
777
1079
dependencies = [
778
1080
"proc-macro2",
779
1081
"quote",
···
782
1084
783
1085
[[package]]
784
1086
name = "pin-project-lite"
785
-
version = "0.2.9"
1087
+
version = "0.2.14"
786
1088
source = "registry+https://github.com/rust-lang/crates.io-index"
787
-
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
1089
+
checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02"
788
1090
789
1091
[[package]]
790
1092
name = "pin-utils"
···
794
1096
795
1097
[[package]]
796
1098
name = "pkg-config"
797
-
version = "0.3.25"
1099
+
version = "0.3.30"
798
1100
source = "registry+https://github.com/rust-lang/crates.io-index"
799
-
checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae"
1101
+
checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
800
1102
801
1103
[[package]]
802
1104
name = "postgres-native-tls"
···
813
1115
814
1116
[[package]]
815
1117
name = "postgres-protocol"
816
-
version = "0.6.4"
1118
+
version = "0.6.7"
817
1119
source = "registry+https://github.com/rust-lang/crates.io-index"
818
-
checksum = "878c6cbf956e03af9aa8204b407b9cbf47c072164800aa918c516cd4b056c50c"
1120
+
checksum = "acda0ebdebc28befa84bee35e651e4c5f09073d668c7aed4cf7e23c3cda84b23"
819
1121
dependencies = [
820
-
"base64",
1122
+
"base64 0.22.1",
821
1123
"byteorder",
822
1124
"bytes",
823
1125
"fallible-iterator",
···
831
1133
832
1134
[[package]]
833
1135
name = "postgres-types"
834
-
version = "0.2.4"
1136
+
version = "0.2.7"
835
1137
source = "registry+https://github.com/rust-lang/crates.io-index"
836
-
checksum = "73d946ec7d256b04dfadc4e6a3292324e6f417124750fc5c0950f981b703a0f1"
1138
+
checksum = "02048d9e032fb3cc3413bbf7b83a15d84a5d419778e2628751896d856498eee9"
837
1139
dependencies = [
838
1140
"bytes",
839
1141
"fallible-iterator",
···
841
1143
]
842
1144
843
1145
[[package]]
1146
+
name = "powerfmt"
1147
+
version = "0.2.0"
1148
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1149
+
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
1150
+
1151
+
[[package]]
844
1152
name = "ppv-lite86"
845
-
version = "0.2.16"
1153
+
version = "0.2.20"
846
1154
source = "registry+https://github.com/rust-lang/crates.io-index"
847
-
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
1155
+
checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04"
1156
+
dependencies = [
1157
+
"zerocopy",
1158
+
]
848
1159
849
1160
[[package]]
850
1161
name = "pretty_env_logger"
851
-
version = "0.4.0"
1162
+
version = "0.5.0"
852
1163
source = "registry+https://github.com/rust-lang/crates.io-index"
853
-
checksum = "926d36b9553851b8b0005f1275891b392ee4d2d833852c417ed025477350fb9d"
1164
+
checksum = "865724d4dbe39d9f3dd3b52b88d859d66bcb2d6a0acfd5ea68a65fb66d4bdc1c"
854
1165
dependencies = [
855
1166
"env_logger",
856
1167
"log",
···
858
1169
859
1170
[[package]]
860
1171
name = "proc-macro2"
861
-
version = "1.0.46"
1172
+
version = "1.0.86"
862
1173
source = "registry+https://github.com/rust-lang/crates.io-index"
863
-
checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b"
1174
+
checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
864
1175
dependencies = [
865
1176
"unicode-ident",
866
1177
]
867
1178
868
1179
[[package]]
869
-
name = "quick-error"
870
-
version = "1.2.3"
1180
+
name = "prometheus-client"
1181
+
version = "0.22.3"
871
1182
source = "registry+https://github.com/rust-lang/crates.io-index"
872
-
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
1183
+
checksum = "504ee9ff529add891127c4827eb481bd69dc0ebc72e9a682e187db4caa60c3ca"
1184
+
dependencies = [
1185
+
"dtoa",
1186
+
"itoa",
1187
+
"parking_lot",
1188
+
"prometheus-client-derive-encode",
1189
+
]
1190
+
1191
+
[[package]]
1192
+
name = "prometheus-client-derive-encode"
1193
+
version = "0.4.2"
1194
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1195
+
checksum = "440f724eba9f6996b75d63681b0a92b06947f1457076d503a4d2e2c8f56442b8"
1196
+
dependencies = [
1197
+
"proc-macro2",
1198
+
"quote",
1199
+
"syn",
1200
+
]
873
1201
874
1202
[[package]]
875
1203
name = "quote"
876
-
version = "1.0.21"
1204
+
version = "1.0.36"
877
1205
source = "registry+https://github.com/rust-lang/crates.io-index"
878
-
checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
1206
+
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
879
1207
dependencies = [
880
1208
"proc-macro2",
881
1209
]
···
912
1240
913
1241
[[package]]
914
1242
name = "redox_syscall"
915
-
version = "0.2.16"
1243
+
version = "0.4.1"
916
1244
source = "registry+https://github.com/rust-lang/crates.io-index"
917
-
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
1245
+
checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa"
918
1246
dependencies = [
919
-
"bitflags",
1247
+
"bitflags 1.3.2",
1248
+
]
1249
+
1250
+
[[package]]
1251
+
name = "redox_syscall"
1252
+
version = "0.5.3"
1253
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1254
+
checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4"
1255
+
dependencies = [
1256
+
"bitflags 2.6.0",
920
1257
]
921
1258
922
1259
[[package]]
923
1260
name = "regex"
924
-
version = "1.6.0"
1261
+
version = "1.10.6"
925
1262
source = "registry+https://github.com/rust-lang/crates.io-index"
926
-
checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b"
1263
+
checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619"
1264
+
dependencies = [
1265
+
"aho-corasick",
1266
+
"memchr",
1267
+
"regex-automata",
1268
+
"regex-syntax",
1269
+
]
1270
+
1271
+
[[package]]
1272
+
name = "regex-automata"
1273
+
version = "0.4.7"
1274
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1275
+
checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df"
927
1276
dependencies = [
928
1277
"aho-corasick",
929
1278
"memchr",
···
932
1281
933
1282
[[package]]
934
1283
name = "regex-syntax"
935
-
version = "0.6.27"
1284
+
version = "0.8.4"
936
1285
source = "registry+https://github.com/rust-lang/crates.io-index"
937
-
checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
1286
+
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
938
1287
939
1288
[[package]]
940
-
name = "remove_dir_all"
941
-
version = "0.5.3"
1289
+
name = "rustc-demangle"
1290
+
version = "0.1.24"
942
1291
source = "registry+https://github.com/rust-lang/crates.io-index"
943
-
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
944
-
dependencies = [
945
-
"winapi",
946
-
]
1292
+
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
947
1293
948
1294
[[package]]
949
-
name = "rustls-pemfile"
950
-
version = "0.2.1"
1295
+
name = "rustix"
1296
+
version = "0.38.34"
951
1297
source = "registry+https://github.com/rust-lang/crates.io-index"
952
-
checksum = "5eebeaeb360c87bfb72e84abdb3447159c0eaececf1bef2aecd65a8be949d1c9"
1298
+
checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f"
953
1299
dependencies = [
954
-
"base64",
1300
+
"bitflags 2.6.0",
1301
+
"errno",
1302
+
"libc",
1303
+
"linux-raw-sys",
1304
+
"windows-sys 0.52.0",
955
1305
]
956
1306
957
1307
[[package]]
958
1308
name = "ryu"
959
-
version = "1.0.11"
1309
+
version = "1.0.18"
960
1310
source = "registry+https://github.com/rust-lang/crates.io-index"
961
-
checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
1311
+
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
962
1312
963
1313
[[package]]
964
-
name = "safemem"
965
-
version = "0.3.3"
1314
+
name = "schannel"
1315
+
version = "0.1.23"
966
1316
source = "registry+https://github.com/rust-lang/crates.io-index"
967
-
checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072"
1317
+
checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534"
1318
+
dependencies = [
1319
+
"windows-sys 0.52.0",
1320
+
]
968
1321
969
1322
[[package]]
970
-
name = "schannel"
971
-
version = "0.1.20"
1323
+
name = "scoped-futures"
1324
+
version = "0.1.3"
972
1325
source = "registry+https://github.com/rust-lang/crates.io-index"
973
-
checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2"
1326
+
checksum = "b1473e24c637950c9bd38763220bea91ec3e095a89f672bbd7a10d03e77ba467"
974
1327
dependencies = [
975
-
"lazy_static",
976
-
"windows-sys",
1328
+
"cfg-if",
1329
+
"pin-utils",
977
1330
]
978
1331
979
1332
[[package]]
980
1333
name = "scoped-tls"
981
-
version = "1.0.0"
1334
+
version = "1.0.1"
982
1335
source = "registry+https://github.com/rust-lang/crates.io-index"
983
-
checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2"
1336
+
checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294"
984
1337
985
1338
[[package]]
986
1339
name = "scopeguard"
987
-
version = "1.1.0"
1340
+
version = "1.2.0"
988
1341
source = "registry+https://github.com/rust-lang/crates.io-index"
989
-
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
1342
+
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
990
1343
991
1344
[[package]]
992
1345
name = "security-framework"
993
-
version = "2.7.0"
1346
+
version = "2.11.1"
994
1347
source = "registry+https://github.com/rust-lang/crates.io-index"
995
-
checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c"
1348
+
checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02"
996
1349
dependencies = [
997
-
"bitflags",
1350
+
"bitflags 2.6.0",
998
1351
"core-foundation",
999
1352
"core-foundation-sys",
1000
1353
"libc",
···
1003
1356
1004
1357
[[package]]
1005
1358
name = "security-framework-sys"
1006
-
version = "2.6.1"
1359
+
version = "2.11.1"
1007
1360
source = "registry+https://github.com/rust-lang/crates.io-index"
1008
-
checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556"
1361
+
checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf"
1009
1362
dependencies = [
1010
1363
"core-foundation-sys",
1011
1364
"libc",
···
1013
1366
1014
1367
[[package]]
1015
1368
name = "serde"
1016
-
version = "1.0.145"
1369
+
version = "1.0.207"
1017
1370
source = "registry+https://github.com/rust-lang/crates.io-index"
1018
-
checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b"
1371
+
checksum = "5665e14a49a4ea1b91029ba7d3bca9f299e1f7cfa194388ccc20f14743e784f2"
1019
1372
dependencies = [
1020
1373
"serde_derive",
1021
1374
]
1022
1375
1023
1376
[[package]]
1024
1377
name = "serde_derive"
1025
-
version = "1.0.145"
1378
+
version = "1.0.207"
1026
1379
source = "registry+https://github.com/rust-lang/crates.io-index"
1027
-
checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c"
1380
+
checksum = "6aea2634c86b0e8ef2cfdc0c340baede54ec27b1e46febd7f80dffb2aa44a00e"
1028
1381
dependencies = [
1029
1382
"proc-macro2",
1030
1383
"quote",
···
1033
1386
1034
1387
[[package]]
1035
1388
name = "serde_json"
1036
-
version = "1.0.86"
1389
+
version = "1.0.124"
1037
1390
source = "registry+https://github.com/rust-lang/crates.io-index"
1038
-
checksum = "41feea4228a6f1cd09ec7a3593a682276702cd67b5273544757dae23c096f074"
1391
+
checksum = "66ad62847a56b3dba58cc891acd13884b9c61138d330c0d7b6181713d4fce38d"
1039
1392
dependencies = [
1040
1393
"itoa",
1394
+
"memchr",
1041
1395
"ryu",
1042
1396
"serde",
1043
1397
]
1044
1398
1045
1399
[[package]]
1400
+
name = "serde_spanned"
1401
+
version = "0.6.7"
1402
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1403
+
checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d"
1404
+
dependencies = [
1405
+
"serde",
1406
+
]
1407
+
1408
+
[[package]]
1046
1409
name = "serde_urlencoded"
1047
1410
version = "0.7.1"
1048
1411
source = "registry+https://github.com/rust-lang/crates.io-index"
···
1055
1418
]
1056
1419
1057
1420
[[package]]
1058
-
name = "sha-1"
1059
-
version = "0.10.0"
1060
-
source = "registry+https://github.com/rust-lang/crates.io-index"
1061
-
checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f"
1062
-
dependencies = [
1063
-
"cfg-if",
1064
-
"cpufeatures",
1065
-
"digest",
1066
-
]
1067
-
1068
-
[[package]]
1069
1421
name = "sha1"
1070
-
version = "0.10.5"
1422
+
version = "0.10.6"
1071
1423
source = "registry+https://github.com/rust-lang/crates.io-index"
1072
-
checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3"
1424
+
checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba"
1073
1425
dependencies = [
1074
1426
"cfg-if",
1075
1427
"cpufeatures",
···
1078
1430
1079
1431
[[package]]
1080
1432
name = "sha2"
1081
-
version = "0.10.6"
1433
+
version = "0.10.8"
1082
1434
source = "registry+https://github.com/rust-lang/crates.io-index"
1083
-
checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0"
1435
+
checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8"
1084
1436
dependencies = [
1085
1437
"cfg-if",
1086
1438
"cpufeatures",
···
1089
1441
1090
1442
[[package]]
1091
1443
name = "signal-hook-registry"
1092
-
version = "1.4.0"
1444
+
version = "1.4.2"
1093
1445
source = "registry+https://github.com/rust-lang/crates.io-index"
1094
-
checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0"
1446
+
checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1"
1095
1447
dependencies = [
1096
1448
"libc",
1097
1449
]
1098
1450
1099
1451
[[package]]
1100
1452
name = "siphasher"
1101
-
version = "0.3.10"
1453
+
version = "0.3.11"
1102
1454
source = "registry+https://github.com/rust-lang/crates.io-index"
1103
-
checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
1455
+
checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d"
1104
1456
1105
1457
[[package]]
1106
1458
name = "slab"
1107
-
version = "0.4.7"
1459
+
version = "0.4.9"
1108
1460
source = "registry+https://github.com/rust-lang/crates.io-index"
1109
-
checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef"
1461
+
checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67"
1110
1462
dependencies = [
1111
1463
"autocfg",
1112
1464
]
1113
1465
1114
1466
[[package]]
1115
1467
name = "smallvec"
1116
-
version = "1.10.0"
1468
+
version = "1.13.2"
1117
1469
source = "registry+https://github.com/rust-lang/crates.io-index"
1118
-
checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
1470
+
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
1119
1471
1120
1472
[[package]]
1121
1473
name = "socket2"
1122
-
version = "0.4.7"
1474
+
version = "0.5.7"
1123
1475
source = "registry+https://github.com/rust-lang/crates.io-index"
1124
-
checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd"
1476
+
checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c"
1125
1477
dependencies = [
1126
1478
"libc",
1127
-
"winapi",
1479
+
"windows-sys 0.52.0",
1128
1480
]
1129
1481
1130
1482
[[package]]
1483
+
name = "spin"
1484
+
version = "0.9.8"
1485
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1486
+
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
1487
+
1488
+
[[package]]
1131
1489
name = "stringprep"
1132
-
version = "0.1.2"
1490
+
version = "0.1.5"
1133
1491
source = "registry+https://github.com/rust-lang/crates.io-index"
1134
-
checksum = "8ee348cb74b87454fff4b551cbf727025810a004f88aeacae7f85b87f4e9a1c1"
1492
+
checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1"
1135
1493
dependencies = [
1136
1494
"unicode-bidi",
1137
1495
"unicode-normalization",
1496
+
"unicode-properties",
1138
1497
]
1139
1498
1140
1499
[[package]]
1141
1500
name = "strsim"
1142
-
version = "0.10.0"
1501
+
version = "0.11.1"
1143
1502
source = "registry+https://github.com/rust-lang/crates.io-index"
1144
-
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
1503
+
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
1145
1504
1146
1505
[[package]]
1147
1506
name = "subtle"
1148
-
version = "2.4.1"
1507
+
version = "2.6.1"
1149
1508
source = "registry+https://github.com/rust-lang/crates.io-index"
1150
-
checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
1509
+
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
1151
1510
1152
1511
[[package]]
1153
1512
name = "syn"
1154
-
version = "1.0.102"
1513
+
version = "2.0.74"
1155
1514
source = "registry+https://github.com/rust-lang/crates.io-index"
1156
-
checksum = "3fcd952facd492f9be3ef0d0b7032a6e442ee9b361d4acc2b1d0c4aaa5f613a1"
1515
+
checksum = "1fceb41e3d546d0bd83421d3409b1460cc7444cd389341a4c880fe7a042cb3d7"
1157
1516
dependencies = [
1158
1517
"proc-macro2",
1159
1518
"quote",
···
1162
1521
1163
1522
[[package]]
1164
1523
name = "tempfile"
1165
-
version = "3.3.0"
1524
+
version = "3.12.0"
1166
1525
source = "registry+https://github.com/rust-lang/crates.io-index"
1167
-
checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4"
1526
+
checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64"
1168
1527
dependencies = [
1169
1528
"cfg-if",
1170
1529
"fastrand",
1171
-
"libc",
1172
-
"redox_syscall",
1173
-
"remove_dir_all",
1174
-
"winapi",
1530
+
"once_cell",
1531
+
"rustix",
1532
+
"windows-sys 0.59.0",
1175
1533
]
1176
1534
1177
1535
[[package]]
1178
1536
name = "termcolor"
1179
-
version = "1.1.3"
1537
+
version = "1.4.1"
1180
1538
source = "registry+https://github.com/rust-lang/crates.io-index"
1181
-
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
1539
+
checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755"
1182
1540
dependencies = [
1183
1541
"winapi-util",
1184
1542
]
1185
1543
1186
1544
[[package]]
1187
1545
name = "thiserror"
1188
-
version = "1.0.37"
1546
+
version = "1.0.63"
1189
1547
source = "registry+https://github.com/rust-lang/crates.io-index"
1190
-
checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e"
1548
+
checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724"
1191
1549
dependencies = [
1192
1550
"thiserror-impl",
1193
1551
]
1194
1552
1195
1553
[[package]]
1196
1554
name = "thiserror-impl"
1197
-
version = "1.0.37"
1555
+
version = "1.0.63"
1198
1556
source = "registry+https://github.com/rust-lang/crates.io-index"
1199
-
checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb"
1557
+
checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261"
1200
1558
dependencies = [
1201
1559
"proc-macro2",
1202
1560
"quote",
···
1204
1562
]
1205
1563
1206
1564
[[package]]
1565
+
name = "time"
1566
+
version = "0.3.36"
1567
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1568
+
checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885"
1569
+
dependencies = [
1570
+
"deranged",
1571
+
"num-conv",
1572
+
"powerfmt",
1573
+
"serde",
1574
+
"time-core",
1575
+
"time-macros",
1576
+
]
1577
+
1578
+
[[package]]
1579
+
name = "time-core"
1580
+
version = "0.1.2"
1581
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1582
+
checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
1583
+
1584
+
[[package]]
1585
+
name = "time-macros"
1586
+
version = "0.2.18"
1587
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1588
+
checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf"
1589
+
dependencies = [
1590
+
"num-conv",
1591
+
"time-core",
1592
+
]
1593
+
1594
+
[[package]]
1207
1595
name = "tinyvec"
1208
-
version = "1.6.0"
1596
+
version = "1.8.0"
1209
1597
source = "registry+https://github.com/rust-lang/crates.io-index"
1210
-
checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"
1598
+
checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938"
1211
1599
dependencies = [
1212
1600
"tinyvec_macros",
1213
1601
]
1214
1602
1215
1603
[[package]]
1216
1604
name = "tinyvec_macros"
1217
-
version = "0.1.0"
1605
+
version = "0.1.1"
1218
1606
source = "registry+https://github.com/rust-lang/crates.io-index"
1219
-
checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
1607
+
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
1220
1608
1221
1609
[[package]]
1222
1610
name = "tokio"
1223
-
version = "1.21.2"
1611
+
version = "1.39.2"
1224
1612
source = "registry+https://github.com/rust-lang/crates.io-index"
1225
-
checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099"
1613
+
checksum = "daa4fb1bc778bd6f04cbfc4bb2d06a7396a8f299dc33ea1900cedaa316f467b1"
1226
1614
dependencies = [
1227
-
"autocfg",
1615
+
"backtrace",
1228
1616
"bytes",
1229
1617
"libc",
1230
-
"memchr",
1231
1618
"mio",
1232
-
"num_cpus",
1233
1619
"parking_lot",
1234
1620
"pin-project-lite",
1235
1621
"signal-hook-registry",
1236
1622
"socket2",
1237
1623
"tokio-macros",
1238
-
"winapi",
1624
+
"windows-sys 0.52.0",
1239
1625
]
1240
1626
1241
1627
[[package]]
1242
1628
name = "tokio-macros"
1243
-
version = "1.8.0"
1629
+
version = "2.4.0"
1244
1630
source = "registry+https://github.com/rust-lang/crates.io-index"
1245
-
checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484"
1631
+
checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752"
1246
1632
dependencies = [
1247
1633
"proc-macro2",
1248
1634
"quote",
···
1251
1637
1252
1638
[[package]]
1253
1639
name = "tokio-native-tls"
1254
-
version = "0.3.0"
1640
+
version = "0.3.1"
1255
1641
source = "registry+https://github.com/rust-lang/crates.io-index"
1256
-
checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b"
1642
+
checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2"
1257
1643
dependencies = [
1258
1644
"native-tls",
1259
1645
"tokio",
···
1261
1647
1262
1648
[[package]]
1263
1649
name = "tokio-postgres"
1264
-
version = "0.7.7"
1650
+
version = "0.7.11"
1265
1651
source = "registry+https://github.com/rust-lang/crates.io-index"
1266
-
checksum = "29a12c1b3e0704ae7dfc25562629798b29c72e6b1d0a681b6f29ab4ae5e7f7bf"
1652
+
checksum = "03adcf0147e203b6032c0b2d30be1415ba03bc348901f3ff1cc0df6a733e60c3"
1267
1653
dependencies = [
1268
1654
"async-trait",
1269
1655
"byteorder",
···
1278
1664
"pin-project-lite",
1279
1665
"postgres-protocol",
1280
1666
"postgres-types",
1667
+
"rand",
1281
1668
"socket2",
1282
1669
"tokio",
1283
1670
"tokio-util",
1284
-
]
1285
-
1286
-
[[package]]
1287
-
name = "tokio-stream"
1288
-
version = "0.1.11"
1289
-
source = "registry+https://github.com/rust-lang/crates.io-index"
1290
-
checksum = "d660770404473ccd7bc9f8b28494a811bc18542b915c0855c51e8f419d5223ce"
1291
-
dependencies = [
1292
-
"futures-core",
1293
-
"pin-project-lite",
1294
-
"tokio",
1671
+
"whoami",
1295
1672
]
1296
1673
1297
1674
[[package]]
1298
1675
name = "tokio-tungstenite"
1299
-
version = "0.17.2"
1676
+
version = "0.21.0"
1300
1677
source = "registry+https://github.com/rust-lang/crates.io-index"
1301
-
checksum = "f714dd15bead90401d77e04243611caec13726c2408afd5b31901dfcdcb3b181"
1678
+
checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38"
1302
1679
dependencies = [
1303
1680
"futures-util",
1304
1681
"log",
···
1308
1685
1309
1686
[[package]]
1310
1687
name = "tokio-util"
1311
-
version = "0.7.4"
1688
+
version = "0.7.11"
1312
1689
source = "registry+https://github.com/rust-lang/crates.io-index"
1313
-
checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740"
1690
+
checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1"
1314
1691
dependencies = [
1315
1692
"bytes",
1316
1693
"futures-core",
1317
1694
"futures-sink",
1318
1695
"pin-project-lite",
1319
1696
"tokio",
1320
-
"tracing",
1321
1697
]
1322
1698
1323
1699
[[package]]
1324
1700
name = "toml"
1325
-
version = "0.5.9"
1701
+
version = "0.8.19"
1326
1702
source = "registry+https://github.com/rust-lang/crates.io-index"
1327
-
checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7"
1703
+
checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e"
1704
+
dependencies = [
1705
+
"serde",
1706
+
"serde_spanned",
1707
+
"toml_datetime",
1708
+
"toml_edit",
1709
+
]
1710
+
1711
+
[[package]]
1712
+
name = "toml_datetime"
1713
+
version = "0.6.8"
1714
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1715
+
checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41"
1328
1716
dependencies = [
1329
1717
"serde",
1330
1718
]
1331
1719
1332
1720
[[package]]
1721
+
name = "toml_edit"
1722
+
version = "0.22.20"
1723
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1724
+
checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d"
1725
+
dependencies = [
1726
+
"indexmap",
1727
+
"serde",
1728
+
"serde_spanned",
1729
+
"toml_datetime",
1730
+
"winnow",
1731
+
]
1732
+
1733
+
[[package]]
1333
1734
name = "tower-service"
1334
1735
version = "0.3.2"
1335
1736
source = "registry+https://github.com/rust-lang/crates.io-index"
···
1337
1738
1338
1739
[[package]]
1339
1740
name = "tracing"
1340
-
version = "0.1.37"
1741
+
version = "0.1.40"
1341
1742
source = "registry+https://github.com/rust-lang/crates.io-index"
1342
-
checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
1743
+
checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
1343
1744
dependencies = [
1344
-
"cfg-if",
1345
1745
"log",
1346
1746
"pin-project-lite",
1347
1747
"tracing-core",
···
1349
1749
1350
1750
[[package]]
1351
1751
name = "tracing-core"
1352
-
version = "0.1.30"
1752
+
version = "0.1.32"
1353
1753
source = "registry+https://github.com/rust-lang/crates.io-index"
1354
-
checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a"
1754
+
checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
1355
1755
dependencies = [
1356
1756
"once_cell",
1357
1757
]
1358
1758
1359
1759
[[package]]
1360
1760
name = "try-lock"
1361
-
version = "0.2.3"
1761
+
version = "0.2.5"
1362
1762
source = "registry+https://github.com/rust-lang/crates.io-index"
1363
-
checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
1763
+
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
1364
1764
1365
1765
[[package]]
1366
1766
name = "tungstenite"
1367
-
version = "0.17.3"
1767
+
version = "0.21.0"
1368
1768
source = "registry+https://github.com/rust-lang/crates.io-index"
1369
-
checksum = "e27992fd6a8c29ee7eef28fc78349aa244134e10ad447ce3b9f0ac0ed0fa4ce0"
1769
+
checksum = "9ef1a641ea34f399a848dea702823bbecfb4c486f911735368f1f137cb8257e1"
1370
1770
dependencies = [
1371
-
"base64",
1372
1771
"byteorder",
1373
1772
"bytes",
1374
-
"http",
1773
+
"data-encoding",
1774
+
"http 1.1.0",
1375
1775
"httparse",
1376
1776
"log",
1377
1777
"rand",
1378
-
"sha-1",
1778
+
"sha1",
1379
1779
"thiserror",
1380
1780
"url",
1381
1781
"utf-8",
1382
1782
]
1383
1783
1384
1784
[[package]]
1385
-
name = "twoway"
1386
-
version = "0.1.8"
1387
-
source = "registry+https://github.com/rust-lang/crates.io-index"
1388
-
checksum = "59b11b2b5241ba34be09c3cc85a36e56e48f9888862e19cedf23336d35316ed1"
1389
-
dependencies = [
1390
-
"memchr",
1391
-
]
1392
-
1393
-
[[package]]
1394
1785
name = "typenum"
1395
-
version = "1.15.0"
1786
+
version = "1.17.0"
1396
1787
source = "registry+https://github.com/rust-lang/crates.io-index"
1397
-
checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
1788
+
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
1398
1789
1399
1790
[[package]]
1400
1791
name = "unicase"
1401
-
version = "2.6.0"
1792
+
version = "2.7.0"
1402
1793
source = "registry+https://github.com/rust-lang/crates.io-index"
1403
-
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
1794
+
checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89"
1404
1795
dependencies = [
1405
1796
"version_check",
1406
1797
]
1407
1798
1408
1799
[[package]]
1409
1800
name = "unicode-bidi"
1410
-
version = "0.3.8"
1801
+
version = "0.3.15"
1411
1802
source = "registry+https://github.com/rust-lang/crates.io-index"
1412
-
checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992"
1803
+
checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75"
1413
1804
1414
1805
[[package]]
1415
1806
name = "unicode-ident"
1416
-
version = "1.0.5"
1807
+
version = "1.0.12"
1417
1808
source = "registry+https://github.com/rust-lang/crates.io-index"
1418
-
checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
1809
+
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
1419
1810
1420
1811
[[package]]
1421
1812
name = "unicode-normalization"
1422
-
version = "0.1.22"
1813
+
version = "0.1.23"
1423
1814
source = "registry+https://github.com/rust-lang/crates.io-index"
1424
-
checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921"
1815
+
checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5"
1425
1816
dependencies = [
1426
1817
"tinyvec",
1427
1818
]
1819
+
1820
+
[[package]]
1821
+
name = "unicode-properties"
1822
+
version = "0.1.1"
1823
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1824
+
checksum = "e4259d9d4425d9f0661581b804cb85fe66a4c631cadd8f490d1c13a35d5d9291"
1428
1825
1429
1826
[[package]]
1430
1827
name = "url"
1431
-
version = "2.3.1"
1828
+
version = "2.5.2"
1432
1829
source = "registry+https://github.com/rust-lang/crates.io-index"
1433
-
checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643"
1830
+
checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c"
1434
1831
dependencies = [
1435
1832
"form_urlencoded",
1436
1833
"idna",
···
1444
1841
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
1445
1842
1446
1843
[[package]]
1844
+
name = "utf8parse"
1845
+
version = "0.2.2"
1846
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1847
+
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
1848
+
1849
+
[[package]]
1447
1850
name = "vcpkg"
1448
1851
version = "0.2.15"
1449
1852
source = "registry+https://github.com/rust-lang/crates.io-index"
···
1451
1854
1452
1855
[[package]]
1453
1856
name = "version_check"
1454
-
version = "0.9.4"
1857
+
version = "0.9.5"
1455
1858
source = "registry+https://github.com/rust-lang/crates.io-index"
1456
-
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
1859
+
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
1457
1860
1458
1861
[[package]]
1459
1862
name = "want"
1460
-
version = "0.3.0"
1863
+
version = "0.3.1"
1461
1864
source = "registry+https://github.com/rust-lang/crates.io-index"
1462
-
checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0"
1865
+
checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e"
1463
1866
dependencies = [
1464
-
"log",
1465
1867
"try-lock",
1466
1868
]
1467
1869
1468
1870
[[package]]
1469
1871
name = "warp"
1470
-
version = "0.3.3"
1872
+
version = "0.3.7"
1471
1873
source = "registry+https://github.com/rust-lang/crates.io-index"
1472
-
checksum = "ed7b8be92646fc3d18b06147664ebc5f48d222686cb11a8755e561a735aacc6d"
1874
+
checksum = "4378d202ff965b011c64817db11d5829506d3404edeadb61f190d111da3f231c"
1473
1875
dependencies = [
1474
1876
"bytes",
1475
1877
"futures-channel",
1476
1878
"futures-util",
1477
1879
"headers",
1478
-
"http",
1880
+
"http 0.2.12",
1479
1881
"hyper",
1480
1882
"log",
1481
1883
"mime",
1482
1884
"mime_guess",
1483
-
"multipart",
1885
+
"multer",
1484
1886
"percent-encoding",
1485
1887
"pin-project",
1486
-
"rustls-pemfile",
1487
1888
"scoped-tls",
1488
1889
"serde",
1489
1890
"serde_json",
1490
1891
"serde_urlencoded",
1491
1892
"tokio",
1492
-
"tokio-stream",
1493
1893
"tokio-tungstenite",
1494
1894
"tokio-util",
1495
1895
"tower-service",
···
1503
1903
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
1504
1904
1505
1905
[[package]]
1506
-
name = "winapi"
1507
-
version = "0.3.9"
1906
+
name = "wasite"
1907
+
version = "0.1.0"
1908
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1909
+
checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b"
1910
+
1911
+
[[package]]
1912
+
name = "wasm-bindgen"
1913
+
version = "0.2.93"
1508
1914
source = "registry+https://github.com/rust-lang/crates.io-index"
1509
-
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
1915
+
checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5"
1510
1916
dependencies = [
1511
-
"winapi-i686-pc-windows-gnu",
1512
-
"winapi-x86_64-pc-windows-gnu",
1917
+
"cfg-if",
1918
+
"once_cell",
1919
+
"wasm-bindgen-macro",
1513
1920
]
1514
1921
1515
1922
[[package]]
1516
-
name = "winapi-i686-pc-windows-gnu"
1517
-
version = "0.4.0"
1923
+
name = "wasm-bindgen-backend"
1924
+
version = "0.2.93"
1518
1925
source = "registry+https://github.com/rust-lang/crates.io-index"
1519
-
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
1926
+
checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b"
1927
+
dependencies = [
1928
+
"bumpalo",
1929
+
"log",
1930
+
"once_cell",
1931
+
"proc-macro2",
1932
+
"quote",
1933
+
"syn",
1934
+
"wasm-bindgen-shared",
1935
+
]
1936
+
1937
+
[[package]]
1938
+
name = "wasm-bindgen-macro"
1939
+
version = "0.2.93"
1940
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1941
+
checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf"
1942
+
dependencies = [
1943
+
"quote",
1944
+
"wasm-bindgen-macro-support",
1945
+
]
1946
+
1947
+
[[package]]
1948
+
name = "wasm-bindgen-macro-support"
1949
+
version = "0.2.93"
1950
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1951
+
checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836"
1952
+
dependencies = [
1953
+
"proc-macro2",
1954
+
"quote",
1955
+
"syn",
1956
+
"wasm-bindgen-backend",
1957
+
"wasm-bindgen-shared",
1958
+
]
1959
+
1960
+
[[package]]
1961
+
name = "wasm-bindgen-shared"
1962
+
version = "0.2.93"
1963
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1964
+
checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484"
1965
+
1966
+
[[package]]
1967
+
name = "web-sys"
1968
+
version = "0.3.70"
1969
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1970
+
checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0"
1971
+
dependencies = [
1972
+
"js-sys",
1973
+
"wasm-bindgen",
1974
+
]
1975
+
1976
+
[[package]]
1977
+
name = "whoami"
1978
+
version = "1.5.1"
1979
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1980
+
checksum = "a44ab49fad634e88f55bf8f9bb3abd2f27d7204172a112c7c9987e01c1c94ea9"
1981
+
dependencies = [
1982
+
"redox_syscall 0.4.1",
1983
+
"wasite",
1984
+
"web-sys",
1985
+
]
1520
1986
1521
1987
[[package]]
1522
1988
name = "winapi-util"
1523
-
version = "0.1.5"
1989
+
version = "0.1.9"
1524
1990
source = "registry+https://github.com/rust-lang/crates.io-index"
1525
-
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
1991
+
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
1526
1992
dependencies = [
1527
-
"winapi",
1993
+
"windows-sys 0.59.0",
1528
1994
]
1529
1995
1530
1996
[[package]]
1531
-
name = "winapi-x86_64-pc-windows-gnu"
1532
-
version = "0.4.0"
1997
+
name = "windows-sys"
1998
+
version = "0.52.0"
1533
1999
source = "registry+https://github.com/rust-lang/crates.io-index"
1534
-
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
2000
+
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
2001
+
dependencies = [
2002
+
"windows-targets",
2003
+
]
1535
2004
1536
2005
[[package]]
1537
2006
name = "windows-sys"
1538
-
version = "0.36.1"
2007
+
version = "0.59.0"
2008
+
source = "registry+https://github.com/rust-lang/crates.io-index"
2009
+
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
2010
+
dependencies = [
2011
+
"windows-targets",
2012
+
]
2013
+
2014
+
[[package]]
2015
+
name = "windows-targets"
2016
+
version = "0.52.6"
1539
2017
source = "registry+https://github.com/rust-lang/crates.io-index"
1540
-
checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2"
2018
+
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
1541
2019
dependencies = [
2020
+
"windows_aarch64_gnullvm",
1542
2021
"windows_aarch64_msvc",
1543
2022
"windows_i686_gnu",
2023
+
"windows_i686_gnullvm",
1544
2024
"windows_i686_msvc",
1545
2025
"windows_x86_64_gnu",
2026
+
"windows_x86_64_gnullvm",
1546
2027
"windows_x86_64_msvc",
1547
2028
]
1548
2029
1549
2030
[[package]]
2031
+
name = "windows_aarch64_gnullvm"
2032
+
version = "0.52.6"
2033
+
source = "registry+https://github.com/rust-lang/crates.io-index"
2034
+
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
2035
+
2036
+
[[package]]
1550
2037
name = "windows_aarch64_msvc"
1551
-
version = "0.36.1"
2038
+
version = "0.52.6"
1552
2039
source = "registry+https://github.com/rust-lang/crates.io-index"
1553
-
checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47"
2040
+
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
1554
2041
1555
2042
[[package]]
1556
2043
name = "windows_i686_gnu"
1557
-
version = "0.36.1"
2044
+
version = "0.52.6"
2045
+
source = "registry+https://github.com/rust-lang/crates.io-index"
2046
+
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
2047
+
2048
+
[[package]]
2049
+
name = "windows_i686_gnullvm"
2050
+
version = "0.52.6"
1558
2051
source = "registry+https://github.com/rust-lang/crates.io-index"
1559
-
checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6"
2052
+
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
1560
2053
1561
2054
[[package]]
1562
2055
name = "windows_i686_msvc"
1563
-
version = "0.36.1"
2056
+
version = "0.52.6"
1564
2057
source = "registry+https://github.com/rust-lang/crates.io-index"
1565
-
checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024"
2058
+
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
1566
2059
1567
2060
[[package]]
1568
2061
name = "windows_x86_64_gnu"
1569
-
version = "0.36.1"
2062
+
version = "0.52.6"
1570
2063
source = "registry+https://github.com/rust-lang/crates.io-index"
1571
-
checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1"
2064
+
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
2065
+
2066
+
[[package]]
2067
+
name = "windows_x86_64_gnullvm"
2068
+
version = "0.52.6"
2069
+
source = "registry+https://github.com/rust-lang/crates.io-index"
2070
+
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
1572
2071
1573
2072
[[package]]
1574
2073
name = "windows_x86_64_msvc"
1575
-
version = "0.36.1"
2074
+
version = "0.52.6"
2075
+
source = "registry+https://github.com/rust-lang/crates.io-index"
2076
+
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
2077
+
2078
+
[[package]]
2079
+
name = "winnow"
2080
+
version = "0.6.18"
1576
2081
source = "registry+https://github.com/rust-lang/crates.io-index"
1577
-
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
2082
+
checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f"
2083
+
dependencies = [
2084
+
"memchr",
2085
+
]
2086
+
2087
+
[[package]]
2088
+
name = "zerocopy"
2089
+
version = "0.7.35"
2090
+
source = "registry+https://github.com/rust-lang/crates.io-index"
2091
+
checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
2092
+
dependencies = [
2093
+
"byteorder",
2094
+
"zerocopy-derive",
2095
+
]
2096
+
2097
+
[[package]]
2098
+
name = "zerocopy-derive"
2099
+
version = "0.7.35"
2100
+
source = "registry+https://github.com/rust-lang/crates.io-index"
2101
+
checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
2102
+
dependencies = [
2103
+
"proc-macro2",
2104
+
"quote",
2105
+
"syn",
2106
+
]
+21
-12
Dockerfile
+21
-12
Dockerfile
···
1
-
FROM debian:buster-slim
1
+
FROM rust:1.80.1-slim
2
2
ARG DEBIAN_FRONTEND=noninteractive
3
-
ENV RUSTUP_HOME=/usr/local/rustup \
4
-
CARGO_HOME=/usr/local/cargo \
5
-
PATH=/usr/local/cargo/bin:$PATH
6
-
RUN apt-get update && apt-get install -y --no-install-recommends --no-install-suggests ca-certificates pkg-config libssl-dev gcc-multilib curl && \
7
-
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s \
8
-
-- --profile minimal -y
3
+
RUN apt-get update && apt-get install -y --no-install-recommends --no-install-suggests ca-certificates pkg-config libssl-dev libpq-dev
4
+
ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
5
+
6
+
RUN --mount=type=cache,target=$CARGO_HOME/registry \
7
+
cargo install diesel_cli --version 2.2.1 --no-default-features --features postgres
8
+
9
9
COPY common /lumen/common
10
10
COPY lumen /lumen/lumen
11
11
COPY Cargo.toml /lumen/
12
-
RUN cd /lumen && cargo build --release
12
+
RUN --mount=type=cache,target=$CARGO_HOME/registry,target=/lumen/target \
13
+
cd /lumen && cargo build --release && cp /lumen/target/release/lumen /root/
13
14
14
15
FROM debian:buster-slim
15
16
ARG DEBIAN_FRONTEND=noninteractive
16
-
RUN apt-get update && apt-get install -y --no-install-recommends --no-install-suggests openssl netcat-openbsd && \
17
-
sed -i -e 's,\[ v3_req \],\[ v3_req \]\nextendedKeyUsage = serverAuth,' /etc/ssl/openssl.cnf
18
-
COPY --from=0 /lumen/target/release/lumen /usr/bin/lumen
17
+
RUN apt-get update && apt-get install -y --no-install-recommends --no-install-suggests openssl libpq5 && \
18
+
sed -i -e 's,\[ v3_req \],\[ v3_req \]\nextendedKeyUsage = serverAuth,' /etc/ssl/openssl.cnf
19
+
RUN mkdir /usr/lib/lumen/
20
+
21
+
COPY --from=0 /usr/local/cargo/bin/diesel /usr/bin/diesel
22
+
COPY --from=0 /lumen/common/migrations /usr/lib/lumen/migrations
23
+
COPY --from=0 /lumen/common/diesel.toml /usr/lib/lumen/
24
+
COPY --from=0 /root/lumen /usr/bin/lumen
25
+
19
26
COPY config-example.toml docker-init.sh /lumen/
20
-
RUN chmod ug+x /lumen/docker-init.sh && chmod ug+x /usr/bin/lumen
27
+
RUN chmod a+x /lumen/docker-init.sh && chmod a+x /usr/bin/lumen
21
28
WORKDIR /lumen
29
+
STOPSIGNAL SIGINT
30
+
CMD /lumen/docker-init.sh
+125
-76
README.md
+125
-76
README.md
···
1
-
# Lumen
2
-
A private Lumina server that can be used with IDA Pro 7.2+.
3
-
4
-
[lumen.abda.nl](https://lumen.abda.nl/) runs this server.
5
-
6
-
You can read about the protocol research [here](https://abda.nl/posts/introducing-lumen/).
7
-
8
-
## Features
9
-
- Stores function signatures so you (and your team) can quickly identify functions that you found in the past using IDA's built-in Lumina features.
10
-
- Backed by PostgreSQL
11
-
- Experimental HTTP API that allows querying the database for comments by file or function hash.
12
-
13
-
## Getting Started
14
-
### Binary releases
15
-
Release binaries are available at https://github.com/naim94a/lumen/releases/latest.
16
-
17
-
### Building from source with Rust
18
-
1. `git clone https://github.com/naim94a/lumen.git`
19
-
2. Get a rust toolchain: https://rustup.rs/
20
-
3. `cd lumen`
21
-
4. Setup a Postgres database and execute src/schema.sql on it
22
-
5. `cargo build --release`
23
-
24
-
### Docker Method
25
-
1. Install `docker-engine` and `docker-compose`.
26
-
2. If using a custom TLS certificate, copy the private key (`.p12`/`.pfx` extension) to `./dockershare` and set the key password in `.env` as `PKCSPASSWD`.
27
-
3. If using a custom Lumen config, copy it to `./dockershare/config.toml`.
28
-
4. Otherwise, or if you have finished these steps, just run `docker-compose up`.
29
-
5. Regardless, if TLS is enabled in the `config.toml`, a `hexrays.crt` will be generated in `./dockershare` to be copied to the IDA install directory.
30
-
31
-
### Usage
32
-
```
33
-
./lumen -c config.toml
34
-
```
35
-
36
-
### Configuring IDA
37
-
You will need IDA Pro 7.2 or above in order to use _lumen_.
38
-
39
-
> The following information may get sent to _lumen_ server: IDA key, Hostname, IDB path, original file path, file MD5, function signature, stack frames & comments.
40
-
41
-
- In your IDA's installation directory open "cfg\ida.cfg" with your favorite text editor _(Example: C:\Program Files\IDA Pro 7.5\cfg\ida.cfg)_
42
-
- Locate the commented out `LUMINA_HOST`, `LUMINA_PORT`, and change their values to the address of your _lumen_ server.
43
-
- If you didn't configure TLS, Add "LUMINA_TLS = NO" after the line with `LUMINA_PORT`.
44
-
45
-
Example:
46
-
```C
47
-
LUMINA_HOST = "192.168.1.1";
48
-
LUMINA_PORT = 1234
49
-
50
-
// Only if TLS isn't used:
51
-
LUMINA_TLS = NO
52
-
```
53
-
54
-
### Configuring TLS
55
-
IDA Pro uses a pinned certificate for Lumina's communcation, so adding a self-signed certificate to your root certificates won't work.
56
-
Luckily, we can override the hard-coded public key by writing a DER-base64 encoded certificate to "hexrays.crt" in IDA's install directory.
57
-
58
-
You may find the following commands useful:
59
-
```bash
60
-
# create a certificate
61
-
openssl req -x509 -newkey rsa:4096 -keyout lumen_key.pem -out lumen_crt.pem -days 365 -nodes
62
-
63
-
# convert to pkcs12 for lumen; used for `lumen.tls` in config
64
-
openssl pkcs12 -export -out lumen.p12 -inkey lumen_key.pem -in lumen_crt.pem
65
-
66
-
# export public-key for IDA; Copy hexrays.crt to IDA installation folder
67
-
openssl x509 -in lumen_crt.pem -out hexrays.crt
68
-
```
69
-
70
-
No attempt is made to merge function data - this may casuse a situation where metadata is inconsistent.
71
-
Instead, the metadata with the highest calculated score is returned to the user.
72
-
73
-
74
-
---
75
-
76
-
Developed by [Naim A.](https://github.com/naim94a); License: MIT.
1
+
# Lumen
2
+
3
+
A private Lumina server that can be used with IDA Pro 7.2+.
4
+
5
+
[lumen.abda.nl](https://lumen.abda.nl/) runs this server.
6
+
7
+
You can read about the protocol research [here](https://abda.nl/posts/introducing-lumen/).
8
+
9
+
## Features
10
+
11
+
- Stores function signatures so you (and your team) can quickly identify functions that you found in the past using IDA's built-in Lumina features.
12
+
- Backed by PostgreSQL
13
+
- Experimental HTTP API that allows querying the database for comments by file or function hash.
14
+
15
+
## Getting Started
16
+
17
+
### Docker Method (Recommended)
18
+
19
+
In this method precompiled docker images will be downloaded, All you need is [docker-compose.yml](./docker-compose.yml).
20
+
21
+
1. Install `docker-engine` and `docker-compose`.
22
+
2. If using a custom TLS certificate, copy the private key (`.p12`/`.pfx` extension) to `./dockershare` and set the key password in `.env` as `PKCSPASSWD`.
23
+
3. If using a custom Lumen config, copy it to `./dockershare/config.toml`.
24
+
4. Otherwise, or if you have finished these steps, just run `docker-compose up`.
25
+
5. Regardless, if TLS is enabled in the `config.toml`, a `hexrays.crt` will be generated in `./dockershare` to be copied to the IDA install directory.
26
+
27
+
### Building from source with Rust
28
+
29
+
1. `git clone https://github.com/naim94a/lumen.git`
30
+
2. Get a rust toolchain: https://rustup.rs/
31
+
3. `cd lumen`
32
+
4. Setup a the database
33
+
34
+
- install postgres
35
+
- install diesel-cli and run migrations:
36
+
37
+
```bash
38
+
cargo install diesel_cli --no-default-features -Fpostgres
39
+
diesel --config-file common/diesel.toml \
40
+
--database-url postgres://postgres:password@localhost/lumen \
41
+
migration run
42
+
```
43
+
44
+
5. `cargo build --release`
45
+
46
+
### Usage
47
+
48
+
```bash
49
+
./lumen -c config.toml
50
+
```
51
+
52
+
### Configuring IDA
53
+
54
+
#### IDA Pro >= 8.1
55
+
56
+
If you used LUMEN in the past, remove the LUMINA settings in the ida.cfg or idauser.cfg files, otherwise you will get a warning about
57
+
bad config parameters.
58
+
59
+
##### Setup under Linux :
60
+
61
+
```bash
62
+
#!/bin/sh
63
+
export LUMINA_TLS=false
64
+
$1
65
+
```
66
+
67
+
- save as ida_lumen.sh, "chmod +x ida_lumen.sh", now you can run IDA using "./ida_lumen.sh ./ida" or "./ida_lumen ./ida64"
68
+
69
+
##### Setup under Windows :
70
+
71
+
```batch
72
+
set LUMINA_TLS=false
73
+
%1
74
+
```
75
+
76
+
- save as ida_lumen.bat, now you can run IDA using "./ida_lumen.bat ida.exe" or "./ida_lumen.bat ida64.exe"
77
+
78
+
##### Setup IDA
79
+
80
+
- Go to Options, General, Lumina. Select "Use a private server", then set your host and port and "guest" as username and password. Click on ok.
81
+
82
+
#### IDA Pro < 8.1
83
+
84
+
You will need IDA Pro 7.2 or above in order to use _lumen_.
85
+
86
+
> The following information may get sent to _lumen_ server: IDA key, Hostname, IDB path, original file path, file MD5, function signature, stack frames & comments.
87
+
88
+
- In your IDA's installation directory open "cfg\ida.cfg" with your favorite text editor _(Example: C:\Program Files\IDA Pro 7.5\cfg\ida.cfg)_
89
+
- Locate the commented out `LUMINA_HOST`, `LUMINA_PORT`, and change their values to the address of your _lumen_ server.
90
+
- If you didn't configure TLS, Add "LUMINA_TLS = NO" after the line with `LUMINA_PORT`.
91
+
92
+
Example:
93
+
94
+
```C
95
+
LUMINA_HOST = "192.168.1.1";
96
+
LUMINA_PORT = 1234
97
+
98
+
// Only if TLS isn't used:
99
+
LUMINA_TLS = NO
100
+
```
101
+
102
+
### Configuring TLS
103
+
104
+
IDA Pro uses a pinned certificate for Lumina's communcation, so adding a self-signed certificate to your root certificates won't work.
105
+
Luckily, we can override the hard-coded public key by writing a DER-base64 encoded certificate to "hexrays.crt" in IDA's install directory.
106
+
107
+
You may find the following commands useful:
108
+
109
+
```bash
110
+
# create a certificate
111
+
openssl req -x509 -newkey rsa:4096 -keyout lumen_key.pem -out lumen_crt.pem -days 365 -nodes
112
+
113
+
# convert to pkcs12 for lumen; used for `lumen.tls` in config
114
+
openssl pkcs12 -export -out lumen.p12 -inkey lumen_key.pem -in lumen_crt.pem
115
+
116
+
# export public-key for IDA; Copy hexrays.crt to IDA installation folder
117
+
openssl x509 -in lumen_crt.pem -out hexrays.crt
118
+
```
119
+
120
+
No attempt is made to merge function data - this may cause a situation where metadata is inconsistent.
121
+
Instead, the metadata with the highest calculated score is returned to the user.
122
+
123
+
---
124
+
125
+
Developed by [Naim A.](https://github.com/naim94a); License: MIT.
+30
-10
common/Cargo.toml
+30
-10
common/Cargo.toml
···
3
3
description = "common utilities for lumen"
4
4
version = "0.2.0"
5
5
authors = ["Naim A. <naim@abda.nl>"]
6
-
edition = "2018"
6
+
edition = "2021"
7
7
publish = false
8
8
9
9
[dependencies]
10
-
tokio = {version = "1.21", features = ["full"], optional = true}
11
-
log = {version = "0.4", features = ["release_max_level_debug"]}
12
-
serde = {version = "1.0", features = ["derive"]}
13
-
tokio-postgres = {version = "0.7", optional = true}
14
-
postgres-native-tls = {version = "0.5", optional = true}
15
-
native-tls = {version = "0.2", optional = true}
10
+
tokio = { version = "1.39", features = ["full"], optional = true }
11
+
log = { version = "0.4", features = ["release_max_level_debug"] }
12
+
serde = { version = "1.0", features = ["derive"] }
13
+
postgres-native-tls = { version = "0.5", optional = true }
14
+
native-tls = { version = "0.2", optional = true }
16
15
futures-util = "0.3"
17
-
toml = "0.5"
18
-
warp = {version = "0.3", optional = true}
16
+
toml = "0.8"
17
+
warp = { version = "0.3", optional = true }
19
18
binascii = "0.1"
20
19
20
+
tokio-postgres = { version = "0.7", default-features = false, optional = true }
21
+
diesel = { version = "2.2", optional = true, default-features = false, features = [
22
+
"postgres_backend",
23
+
"time",
24
+
] }
25
+
time = { version = "0.3.36", optional = true }
26
+
diesel-async = { version = "0.5", optional = true, features = [
27
+
"postgres",
28
+
"bb8",
29
+
] }
30
+
anyhow = "1.0"
31
+
prometheus-client = "0.22"
32
+
21
33
[features]
22
34
default = ["web", "db"]
23
35
web = ["warp"]
24
-
db = ["tokio", "tokio-postgres", "postgres-native-tls", "native-tls"]
36
+
db = [
37
+
"tokio",
38
+
"postgres-native-tls",
39
+
"native-tls",
40
+
"diesel",
41
+
"diesel-async",
42
+
"tokio-postgres",
43
+
"time",
44
+
]
+8
common/diesel.toml
+8
common/diesel.toml
common/migrations/.keep
common/migrations/.keep
This is a binary file and will not be displayed.
+6
common/migrations/00000000000000_diesel_initial_setup/down.sql
+6
common/migrations/00000000000000_diesel_initial_setup/down.sql
···
1
+
-- This file was automatically created by Diesel to setup helper functions
2
+
-- and other internal bookkeeping. This file is safe to edit, any future
3
+
-- changes will be added to existing projects as new migrations.
4
+
5
+
DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass);
6
+
DROP FUNCTION IF EXISTS diesel_set_updated_at();
+36
common/migrations/00000000000000_diesel_initial_setup/up.sql
+36
common/migrations/00000000000000_diesel_initial_setup/up.sql
···
1
+
-- This file was automatically created by Diesel to setup helper functions
2
+
-- and other internal bookkeeping. This file is safe to edit, any future
3
+
-- changes will be added to existing projects as new migrations.
4
+
5
+
6
+
7
+
8
+
-- Sets up a trigger for the given table to automatically set a column called
9
+
-- `updated_at` whenever the row is modified (unless `updated_at` was included
10
+
-- in the modified columns)
11
+
--
12
+
-- # Example
13
+
--
14
+
-- ```sql
15
+
-- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW());
16
+
--
17
+
-- SELECT diesel_manage_updated_at('users');
18
+
-- ```
19
+
CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$
20
+
BEGIN
21
+
EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s
22
+
FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl);
23
+
END;
24
+
$$ LANGUAGE plpgsql;
25
+
26
+
CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$
27
+
BEGIN
28
+
IF (
29
+
NEW IS DISTINCT FROM OLD AND
30
+
NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at
31
+
) THEN
32
+
NEW.updated_at := current_timestamp;
33
+
END IF;
34
+
RETURN NEW;
35
+
END;
36
+
$$ LANGUAGE plpgsql;
+39
common/migrations/2023-02-01-210714_init/up.sql
+39
common/migrations/2023-02-01-210714_init/up.sql
···
1
+
CREATE TABLE IF NOT EXISTS users (
2
+
id SERIAL PRIMARY KEY,
3
+
lic_id bytea,
4
+
lic_data bytea,
5
+
hostname VARCHAR(260),
6
+
first_seen TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
7
+
);
8
+
CREATE UNIQUE INDEX IF NOT EXISTS user_rec ON users(lic_id,lic_data,hostname);
9
+
CREATE UNIQUE INDEX IF NOT EXISTS user_hn_null ON users (lic_id,lic_data, (hostname IS NULL)) WHERE hostname is NULL;
10
+
11
+
CREATE TABLE IF NOT EXISTS files (
12
+
id SERIAL PRIMARY KEY,
13
+
chksum bytea UNIQUE /* file chksum */
14
+
);
15
+
16
+
CREATE TABLE IF NOT EXISTS dbs (
17
+
id SERIAL PRIMARY KEY,
18
+
file_path VARCHAR(260),
19
+
idb_path VARCHAR(260),
20
+
file_id INTEGER REFERENCES files(id),
21
+
user_id INTEGER REFERENCES users(id)
22
+
);
23
+
CREATE UNIQUE INDEX IF NOT EXISTS db_paths ON dbs(file_id, user_id, idb_path);
24
+
25
+
CREATE TABLE IF NOT EXISTS funcs (
26
+
id SERIAL PRIMARY KEY,
27
+
name TEXT NOT NULL,
28
+
len INTEGER NOT NULL,
29
+
db_id INTEGER REFERENCES dbs(id) NOT NULL,
30
+
chksum bytea, /* function chksum */
31
+
metadata bytea,
32
+
rank INTEGER,
33
+
34
+
push_dt TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
35
+
update_dt TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
36
+
);
37
+
CREATE UNIQUE INDEX IF NOT EXISTS funcs_db ON funcs(chksum, db_id);
38
+
CREATE INDEX IF NOT EXISTS funcs_ranking ON funcs(chksum,rank);
39
+
CREATE INDEX IF NOT EXISTS func_chksum ON funcs(chksum);
+77
common/src/async_drop.rs
+77
common/src/async_drop.rs
···
1
+
use futures_util::{future::BoxFuture, Future};
2
+
use log::trace;
3
+
use tokio::sync::mpsc::{unbounded_channel, UnboundedSender, WeakUnboundedSender};
4
+
5
+
enum AsyncDropperMsg {
6
+
Future(BoxFuture<'static, ()>),
7
+
Termination,
8
+
}
9
+
10
+
/// Assists with executing code in a future when the future is cancelled.
11
+
pub struct AsyncDropper {
12
+
tx: UnboundedSender<AsyncDropperMsg>,
13
+
}
14
+
impl AsyncDropper {
15
+
/// Creates a new `AsyncDropper`
16
+
/// Returns a tuple containing the AsyncDropper struct and a future that will perform tasks when a future is dropped.
17
+
#[track_caller]
18
+
pub fn new() -> (AsyncDropper, impl Future<Output = ()> + 'static) {
19
+
let orig = format!("{}", std::panic::Location::caller());
20
+
trace!("new dropper '{orig}'");
21
+
22
+
let (tx, mut rx) = unbounded_channel();
23
+
let fut = async move {
24
+
while let Some(msg) = rx.recv().await {
25
+
match msg {
26
+
AsyncDropperMsg::Future(fut) => {
27
+
fut.await;
28
+
},
29
+
AsyncDropperMsg::Termination => {
30
+
trace!("term received for '{orig}'...");
31
+
break;
32
+
},
33
+
}
34
+
}
35
+
trace!("dropper '{orig}' exited.");
36
+
};
37
+
38
+
(Self { tx }, fut)
39
+
}
40
+
41
+
/// Defers execution of a future to when the returned `AsyncDropGuard` is dropped
42
+
pub fn defer<F: Future<Output = ()> + Send + 'static>(&self, fut: F) -> AsyncDropGuard {
43
+
let tx = self.tx.downgrade();
44
+
AsyncDropGuard { tx, run: Some(Box::pin(fut)) }
45
+
}
46
+
}
47
+
impl Drop for AsyncDropper {
48
+
fn drop(&mut self) {
49
+
if let Err(err) = self.tx.send(AsyncDropperMsg::Termination) {
50
+
// If this ever panics, we're not cleaning up resources properly.
51
+
panic!("failed to send termination: {}", err);
52
+
}
53
+
}
54
+
}
55
+
56
+
/// A Guard struct. When dropped executes the defered future.
57
+
pub struct AsyncDropGuard {
58
+
tx: WeakUnboundedSender<AsyncDropperMsg>,
59
+
run: Option<BoxFuture<'static, ()>>,
60
+
}
61
+
62
+
impl AsyncDropGuard {
63
+
/// This consumes the guard, causing the internal future not to execute.
64
+
pub fn consume(mut self) {
65
+
self.run.take();
66
+
}
67
+
}
68
+
69
+
impl Drop for AsyncDropGuard {
70
+
fn drop(&mut self) {
71
+
if let Some(fun) = self.run.take() {
72
+
if let Some(tx) = self.tx.upgrade() {
73
+
let _ = tx.send(AsyncDropperMsg::Future(fun));
74
+
}
75
+
}
76
+
}
77
+
}
+92
-54
common/src/config.rs
+92
-54
common/src/config.rs
···
1
-
use serde::Deserialize;
2
-
use toml::from_slice;
3
-
use std::{net::SocketAddr, path::PathBuf};
4
-
5
-
#[derive(Deserialize)]
6
-
pub struct TlsIdentity {
7
-
pub server_cert: PathBuf,
8
-
}
9
-
10
-
#[derive(Deserialize)]
11
-
pub struct LuminaServer {
12
-
pub bind_addr: SocketAddr,
13
-
pub use_tls: Option<bool>,
14
-
pub tls: Option<TlsIdentity>,
15
-
pub server_name: Option<String>,
16
-
}
17
-
18
-
#[derive(Deserialize)]
19
-
pub struct WebServer {
20
-
pub bind_addr: SocketAddr,
21
-
}
22
-
23
-
#[derive(Deserialize)]
24
-
pub struct Database {
25
-
pub connection_info: String,
26
-
27
-
pub use_tls: bool,
28
-
pub server_ca: Option<PathBuf>,
29
-
pub client_id: Option<PathBuf>,
30
-
}
31
-
32
-
#[derive(Deserialize)]
33
-
pub struct Config {
34
-
pub lumina: LuminaServer,
35
-
pub api_server: Option<WebServer>,
36
-
pub database: Database,
37
-
}
38
-
39
-
pub trait HasConfig {
40
-
fn get_config(&self) -> &Config;
41
-
}
42
-
43
-
impl HasConfig for Config {
44
-
fn get_config(&self) -> &Config {
45
-
self
46
-
}
47
-
}
48
-
49
-
pub fn load_config<R: std::io::Read>(mut fd: R) -> Config {
50
-
let mut buf = vec![];
51
-
fd.read_to_end(&mut buf).expect("failed to read config");
52
-
53
-
from_slice(&buf).expect("failed to parse configuration")
54
-
}
1
+
use serde::Deserialize;
2
+
use std::time::Duration;
3
+
use std::{net::SocketAddr, path::PathBuf};
4
+
use toml::from_str;
5
+
6
+
#[derive(Deserialize)]
7
+
pub struct TlsIdentity {
8
+
pub server_cert: PathBuf,
9
+
}
10
+
11
+
#[derive(Deserialize)]
12
+
pub struct LuminaServer {
13
+
pub bind_addr: SocketAddr,
14
+
pub use_tls: Option<bool>,
15
+
pub tls: Option<TlsIdentity>,
16
+
pub server_name: Option<String>,
17
+
pub allow_deletes: Option<bool>,
18
+
19
+
/// limit of function histories to return per function.
20
+
/// `None`, or `Some(0)` will disable the feature on the server.
21
+
pub get_history_limit: Option<u32>,
22
+
}
23
+
24
+
#[derive(Deserialize)]
25
+
pub struct WebServer {
26
+
pub bind_addr: SocketAddr,
27
+
}
28
+
29
+
#[derive(Deserialize)]
30
+
pub struct Database {
31
+
pub connection_info: String,
32
+
33
+
pub use_tls: bool,
34
+
pub server_ca: Option<PathBuf>,
35
+
pub client_id: Option<PathBuf>,
36
+
}
37
+
38
+
#[derive(Deserialize, Debug)]
39
+
#[serde(default)]
40
+
pub struct Limits {
41
+
/// Maximum time to wait on an idle connection between commands.
42
+
pub command_timeout: Duration,
43
+
44
+
/// Maximum time to all `PULL_MD` queries.
45
+
pub pull_md_timeout: Duration,
46
+
47
+
/// Maximum time to wait for `HELO` message.
48
+
pub hello_timeout: Duration,
49
+
50
+
/// Maximum time allowed until TLS handshake completes.
51
+
pub tls_handshake_timeout: Duration,
52
+
}
53
+
54
+
impl Default for Limits {
55
+
fn default() -> Self {
56
+
Self {
57
+
command_timeout: Duration::from_secs(3600),
58
+
pull_md_timeout: Duration::from_secs(4 * 60),
59
+
hello_timeout: Duration::from_secs(15),
60
+
tls_handshake_timeout: Duration::from_secs(10),
61
+
}
62
+
}
63
+
}
64
+
65
+
#[derive(Deserialize)]
66
+
pub struct Config {
67
+
pub lumina: LuminaServer,
68
+
pub api_server: Option<WebServer>,
69
+
pub database: Database,
70
+
71
+
#[serde(default)]
72
+
pub limits: Limits,
73
+
}
74
+
75
+
pub trait HasConfig {
76
+
fn get_config(&self) -> &Config;
77
+
}
78
+
79
+
impl HasConfig for Config {
80
+
fn get_config(&self) -> &Config {
81
+
self
82
+
}
83
+
}
84
+
85
+
pub fn load_config<R: std::io::Read>(mut fd: R) -> Config {
86
+
let mut buf = vec![];
87
+
fd.read_to_end(&mut buf).expect("failed to read config");
88
+
89
+
let buf = std::str::from_utf8(&buf).expect("file contains invalid utf-8");
90
+
91
+
from_str(buf).expect("failed to parse configuration")
92
+
}
+478
-384
common/src/db/mod.rs
+478
-384
common/src/db/mod.rs
···
1
-
use log::*;
2
-
use tokio_postgres::{Client, NoTls};
3
-
use serde::Serialize;
4
-
use std::{collections::HashMap, sync::Arc};
5
-
use tokio::sync::RwLock;
6
-
use crate::config::Config;
7
-
8
-
pub type DynConfig = dyn crate::config::HasConfig + Send + Sync;
9
-
10
-
pub struct Database {
11
-
config: Arc<DynConfig>,
12
-
conn: RwLock<Client>,
13
-
cache: RwLock<HashMap<String, tokio_postgres::Statement>>,
14
-
}
15
-
16
-
pub struct FunctionInfo {
17
-
pub name: String,
18
-
pub len: u32,
19
-
pub data: Vec<u8>,
20
-
pub popularity: u32,
21
-
}
22
-
23
-
#[derive(Debug, Serialize)]
24
-
pub struct DbStats {
25
-
unique_lics: i32,
26
-
unique_hosts_per_lic: i32,
27
-
28
-
unique_funcs: i32,
29
-
total_funcs: i32,
30
-
31
-
dbs: i32,
32
-
unique_files: i32,
33
-
}
34
-
35
-
impl Database {
36
-
pub async fn open(config: Arc<DynConfig>) -> Result<Self, tokio_postgres::Error> {
37
-
let client = Self::connect(config.get_config()).await?;
38
-
39
-
Ok(Database{
40
-
config,
41
-
conn: RwLock::new(client),
42
-
cache: RwLock::new(HashMap::new()),
43
-
})
44
-
}
45
-
46
-
pub async fn get_conn(&self) -> tokio::sync::RwLockReadGuard<'_, Client> {
47
-
self.conn.read().await
48
-
}
49
-
50
-
async fn connect_tls(conn_info: &Config) -> Result<tokio_postgres::Client, tokio_postgres::Error> {
51
-
use postgres_native_tls::MakeTlsConnector;
52
-
use native_tls::{TlsConnector, Certificate, Identity};
53
-
54
-
let mut tls_connector = TlsConnector::builder();
55
-
56
-
if let Some(ref client_identity) = conn_info.database.client_id {
57
-
let client_identity = tokio::fs::read(client_identity).await.expect("failed to read db's client id");
58
-
let client_identity = Identity::from_pkcs12(&client_identity, "").expect("failed to load db's client identity (PKCS12)");
59
-
tls_connector.identity(client_identity);
60
-
}
61
-
62
-
if let Some(ref server_ca) = conn_info.database.server_ca {
63
-
let server_ca = tokio::fs::read(server_ca).await.expect("failed to read db's server ca");
64
-
let server_ca = Certificate::from_pem(&server_ca).expect("failed to load db's server ca (PEM)");
65
-
tls_connector.add_root_certificate(server_ca);
66
-
}
67
-
68
-
let tls_connector = tls_connector
69
-
.danger_accept_invalid_hostnames(true)
70
-
.build()
71
-
.expect("failed to build TlsConnector");
72
-
73
-
let connector = MakeTlsConnector::new(tls_connector);
74
-
75
-
let (client, conn) = tokio_postgres::connect(&conn_info.database.connection_info, connector).await?;
76
-
info!("database connected (tls).");
77
-
78
-
tokio::spawn(async {
79
-
if let Err(e) = conn.await {
80
-
error!("db connection error: {}", e);
81
-
}
82
-
});
83
-
84
-
Ok(client)
85
-
}
86
-
87
-
async fn connect_plain(conn_info: &str) -> Result<tokio_postgres::Client, tokio_postgres::Error> {
88
-
let (client, conn) = tokio_postgres::connect(conn_info, NoTls).await?;
89
-
info!("database connected.");
90
-
91
-
tokio::spawn(async {
92
-
if let Err(e) = conn.await {
93
-
error!("db connection error: {}", e);
94
-
}
95
-
});
96
-
97
-
Ok(client)
98
-
}
99
-
100
-
async fn connect(conn_info: &Config) -> Result<tokio_postgres::Client, tokio_postgres::Error> {
101
-
if conn_info.database.use_tls {
102
-
info!("connecting with TLS...");
103
-
Self::connect_tls(conn_info).await
104
-
}
105
-
else {
106
-
info!("connecting plain...");
107
-
Self::connect_plain(&conn_info.database.connection_info).await
108
-
}
109
-
}
110
-
111
-
async fn prepare_cached<'a, 'b>(&'a self, sql: &'b str) -> Result<tokio_postgres::Statement, tokio_postgres::Error> {
112
-
{
113
-
let rd = self.cache.read().await;
114
-
if let Some(v) = rd.get(sql) {
115
-
return Ok(v.clone());
116
-
}
117
-
}
118
-
{
119
-
let stmt = self.conn.read().await.prepare(sql).await?;
120
-
let mut wr = self.cache.write().await;
121
-
wr.insert(sql.to_string(), stmt);
122
-
123
-
let v = wr.get(sql).expect("failed to get recently added value");
124
-
Ok(v.clone())
125
-
}
126
-
}
127
-
128
-
pub async fn get_funcs(&self, funcs: &[crate::rpc::PullMetadataFunc<'_>]) -> Result<Vec<Option<FunctionInfo>>, tokio_postgres::Error> {
129
-
let stmt = self.prepare_cached(r#"
130
-
WITH best AS (
131
-
select chksum,MAX(rank) as maxrank from funcs f1
132
-
WHERE chksum = ANY($1)
133
-
GROUP BY chksum
134
-
)
135
-
SELECT f2.name,f2.len,f2.metadata,f2.chksum FROM best
136
-
LEFT JOIN funcs f2 ON (best.chksum=f2.chksum AND best.maxrank=f2.rank)
137
-
"#).await?;
138
-
139
-
let conn = self.conn.read().await;
140
-
141
-
let chksums: Vec<&[u8]> = funcs.iter().map(|v| v.mb_hash).collect();
142
-
143
-
let rows = conn.query(&stmt, &[&chksums]).await?;
144
-
let mut partial: HashMap<Vec<u8>, FunctionInfo> = rows
145
-
.into_iter()
146
-
.map(|row| {
147
-
let chksum: Vec<u8> = row.get(3);
148
-
let v = FunctionInfo {
149
-
name: row.get(0),
150
-
len: row.get::<_, i32>(1) as u32,
151
-
data: row.get(2),
152
-
popularity: 0,
153
-
};
154
-
155
-
(chksum, v)
156
-
})
157
-
.collect();
158
-
159
-
let results = partial.len();
160
-
161
-
let res: Vec<Option<FunctionInfo>> = chksums.iter().map(|&chksum| {
162
-
partial.remove(chksum)
163
-
}).collect();
164
-
165
-
trace!("found {}/{} results", results, chksums.len());
166
-
debug_assert_eq!(chksums.len(), res.len());
167
-
Ok(res)
168
-
}
169
-
170
-
pub async fn get_or_create_user<'a>(&self, user: &'a crate::rpc::RpcHello<'a>, funcs: Option<&'a crate::rpc::PushMetadata<'a>>) -> Result<i32, tokio_postgres::Error> {
171
-
let stmt = self.prepare_cached(
172
-
r#"
173
-
WITH ins AS (
174
-
INSERT INTO users(lic_id, lic_data, hostname)
175
-
VALUES ($1, $3, $2)
176
-
ON CONFLICT DO NOTHING
177
-
RETURNING id
178
-
)
179
-
SELECT id FROM ins
180
-
UNION
181
-
SELECT id FROM users WHERE lic_id=$1 AND lic_data=$3 AND (($2 is not null AND hostname = $2) OR ($2 is null AND hostname is null))
182
-
"#).await?;
183
-
184
-
let lic_id = &user.lic_number[..];
185
-
let lic_data = user.license_data;
186
-
let hostname = funcs.map(|v| v.hostname);
187
-
188
-
let row = self.conn.read().await.query(&stmt, &[&lic_id, &hostname, &lic_data]).await?;
189
-
if !row.is_empty() {
190
-
let id = row[0].get(0);
191
-
if row.len() > 1 {
192
-
let vals: Vec<i32> = row.iter().map(|v| v.get(0)).collect();
193
-
debug!("expected single row, got: {:?}", &vals);
194
-
}
195
-
Ok(id)
196
-
} else {
197
-
error!("no rows for user. ret 0");
198
-
Ok(0)
199
-
}
200
-
}
201
-
202
-
async fn get_or_create_file<'a>(&self, funcs: &'a crate::rpc::PushMetadata<'a>) -> Result<i32, tokio_postgres::Error> {
203
-
let stmt = self.prepare_cached(r#"
204
-
WITH ins AS (
205
-
INSERT INTO files(chksum)
206
-
VALUES ($1)
207
-
ON CONFLICT(chksum) DO NOTHING
208
-
RETURNING id
209
-
)
210
-
SELECT id FROM files WHERE chksum=$1
211
-
UNION
212
-
SELECT id FROM ins
213
-
"#).await?;
214
-
215
-
let hash = &funcs.md5[..];
216
-
217
-
let id: i32 = self.conn.read().await
218
-
.query_one(&stmt, &[&hash]).await?
219
-
.get(0);
220
-
Ok(id)
221
-
}
222
-
223
-
async fn get_or_create_db<'a>(&self, user: &'a crate::rpc::RpcHello<'a>, funcs: &'a crate::rpc::PushMetadata<'a>) -> Result<i32, tokio_postgres::Error> {
224
-
let file_id = self.get_or_create_file(funcs);
225
-
let user_id = self.get_or_create_user(user, Some(funcs));
226
-
227
-
let (file_id, user_id): (i32, i32) = futures_util::try_join!(file_id, user_id)?;
228
-
229
-
let stmt = self.prepare_cached(r#"
230
-
WITH ins AS (
231
-
INSERT INTO dbs (user_id, file_id, file_path, idb_path)
232
-
VALUES ($1, $2, $3, $4)
233
-
ON CONFLICT(idb_path,file_id,user_id) DO NOTHING
234
-
RETURNING id
235
-
)
236
-
SELECT id FROM dbs WHERE user_id=$1 AND file_id=$2 AND idb_path=$4
237
-
UNION
238
-
SELECT id FROM ins
239
-
"#).await?;
240
-
241
-
let idb_path = funcs.idb_path;
242
-
let file_path = funcs.file_path;
243
-
244
-
trace!("fid={}; uid={}", file_id, user_id);
245
-
let row = self.conn.read().await
246
-
.query_one(&stmt, &[&user_id, &file_id, &file_path, &idb_path]).await?;
247
-
248
-
let db_id = row.get(0);
249
-
250
-
Ok(db_id)
251
-
}
252
-
253
-
pub async fn push_funcs<'a, 'b>(&'b self, user: &'a crate::rpc::RpcHello<'a>, funcs: &'a crate::rpc::PushMetadata<'a>, scores: &[u32]) -> Result<Vec<bool>, tokio_postgres::Error> {
254
-
let db_id = self.get_or_create_db(user, funcs).await?;
255
-
256
-
let stmt = self.prepare_cached(r#"
257
-
INSERT INTO funcs AS f (name, len, chksum, metadata, db_id, rank)
258
-
VALUES ($1, $2, $3, $4, $5, $6)
259
-
ON CONFLICT (db_id,chksum) DO UPDATE
260
-
SET metadata=$4, rank=$6, name=$1, update_dt=CURRENT_TIMESTAMP
261
-
WHERE f.db_id=$5 AND f.chksum=$3 AND f.len=$2
262
-
RETURNING exists(SELECT 1 FROM funcs WHERE chksum=$3)
263
-
"#).await?;
264
-
265
-
debug_assert_eq!(scores.len(), funcs.funcs.len());
266
-
267
-
let mut res = Vec::with_capacity(funcs.funcs.len());
268
-
269
-
// NOTE: Do not access self.conn/prepare_cached before dropping tx - it will deadlock!
270
-
{
271
-
let mut tx = self.conn.write().await;
272
-
let tx = tx.transaction().await?;
273
-
274
-
for (func, &score) in funcs.funcs.iter().zip(scores.iter()) {
275
-
let name = func.name;
276
-
let len = func.func_len as i32;
277
-
let chksum = func.hash;
278
-
let md = func.func_data;
279
-
let score = score as i32;
280
-
let row_exists = tx.query_one(&stmt, &[
281
-
&name, &len, &chksum, &md, &db_id, &score
282
-
]).await?;
283
-
284
-
let row_exists: bool = row_exists.try_get(0)?;
285
-
286
-
res.push(!row_exists);
287
-
}
288
-
289
-
tx.commit().await?;
290
-
}
291
-
292
-
Ok(res)
293
-
}
294
-
295
-
pub async fn is_online(&self) -> bool {
296
-
let read = self.conn.read().await;
297
-
!read.is_closed()
298
-
}
299
-
300
-
pub async fn reconnect(&self) -> Result<(), tokio_postgres::Error> {
301
-
let connection = Self::connect(self.config.get_config()).await?;
302
-
303
-
let conn = &mut *self.conn.write().await;
304
-
305
-
self.cache.write().await.clear();
306
-
307
-
*conn = connection;
308
-
Ok(())
309
-
}
310
-
311
-
pub async fn get_stats(&self) -> Result<DbStats, tokio_postgres::Error> {
312
-
let stmt = self.prepare_cached(r#"
313
-
SELECT
314
-
(SELECT COUNT(*)::int FROM users) as users,
315
-
(SELECT COUNT(distinct lic_id)::int FROM users) as hosts,
316
-
(SELECT COUNT(distinct chksum)::int FROM funcs) as funcs,
317
-
(SELECT COUNT(*)::int FROM funcs) as total_funcs,
318
-
(SELECT COUNT(*)::int FROM dbs) as dbs,
319
-
(SELECT COUNT(*)::int FROM files) as files
320
-
"#).await?;
321
-
let db = self.conn.read().await;
322
-
let row = db.query_one(&stmt, &[]).await?;
323
-
324
-
Ok(DbStats {
325
-
unique_lics: row.try_get(0)?,
326
-
unique_hosts_per_lic: row.try_get(1)?,
327
-
unique_funcs: row.try_get(2)?,
328
-
total_funcs: row.try_get(3)?,
329
-
dbs: row.try_get(4)?,
330
-
unique_files: row.try_get(5)?,
331
-
})
332
-
}
333
-
334
-
pub async fn get_file_funcs(&self, md5: &[u8], offset: i64, limit: i64) -> Result<Vec<(String, u32, [u8; 16])>, tokio_postgres::Error> {
335
-
let stmt = self.prepare_cached(r#"
336
-
SELECT fns.name, fns.len, fns.chksum FROM funcs AS fns
337
-
LEFT JOIN dbs AS d ON (d.id=fns.db_id)
338
-
LEFT JOIN files AS f ON (d.file_id=f.id)
339
-
WHERE
340
-
f.chksum=$1
341
-
LIMIT $2
342
-
OFFSET $3
343
-
"#).await?;
344
-
let db = self.conn.read().await;
345
-
let rows = db.query(&stmt, &[&md5, &limit, &offset]).await?;
346
-
347
-
let res = rows.into_iter()
348
-
.map(|row| {
349
-
let name: String = row.get(0);
350
-
let len: i32 = row.get(1);
351
-
let md5_a: Vec<u8> = row.get(2);
352
-
353
-
let mut md5 = [0u8; 16];
354
-
md5.copy_from_slice(&md5_a);
355
-
356
-
(name, len as u32, md5)
357
-
})
358
-
.collect();
359
-
Ok(res)
360
-
}
361
-
362
-
pub async fn get_files_with_func(&self, func: &[u8]) -> Result<Vec<[u8; 16]>, tokio_postgres::Error> {
363
-
let stmt = self.prepare_cached(r#"
364
-
SELECT DISTINCT f.chksum FROM files f
365
-
LEFT JOIN dbs d ON (d.file_id = f.id)
366
-
LEFT JOIN funcs fns ON (fns.db_id = d.id)
367
-
WHERE
368
-
fns.chksum = $1
369
-
"#).await?;
370
-
let db = self.conn.read().await;
371
-
let rows = db.query(&stmt, &[&func]).await?;
372
-
373
-
let res = rows
374
-
.into_iter()
375
-
.map(|v| {
376
-
let mut chksum = [0u8; 16];
377
-
let v: Vec<u8> = v.get(0);
378
-
chksum.copy_from_slice(&v);
379
-
chksum
380
-
})
381
-
.collect();
382
-
Ok(res)
383
-
}
384
-
}
1
+
use crate::async_drop::{AsyncDropGuard, AsyncDropper};
2
+
use log::*;
3
+
use postgres_native_tls::MakeTlsConnector;
4
+
use serde::Serialize;
5
+
use std::collections::HashMap;
6
+
use time::OffsetDateTime;
7
+
use tokio_postgres::{tls::MakeTlsConnect, NoTls, Socket};
8
+
pub mod schema;
9
+
mod schema_auto;
10
+
11
+
use diesel::{
12
+
query_builder::{Query, QueryFragment},
13
+
sql_types::{Array, Binary, Integer, VarChar},
14
+
upsert::excluded,
15
+
ExpressionMethods, NullableExpressionMethods, QueryDsl,
16
+
};
17
+
use diesel_async::{pooled_connection::ManagerConfig, RunQueryDsl};
18
+
19
+
pub type DynConfig = dyn crate::config::HasConfig + Send + Sync;
20
+
21
+
pub struct Database {
22
+
tls_connector: Option<MakeTlsConnector>,
23
+
diesel: diesel_async::pooled_connection::bb8::Pool<diesel_async::AsyncPgConnection>,
24
+
dropper: AsyncDropper,
25
+
}
26
+
27
+
pub struct FunctionInfo {
28
+
pub name: String,
29
+
pub len: u32,
30
+
pub data: Vec<u8>,
31
+
pub popularity: u32,
32
+
}
33
+
34
+
#[derive(Debug, Serialize)]
35
+
pub struct DbStats {
36
+
unique_lics: i32,
37
+
unique_hosts_per_lic: i32,
38
+
39
+
unique_funcs: i32,
40
+
total_funcs: i32,
41
+
42
+
dbs: i32,
43
+
unique_files: i32,
44
+
}
45
+
46
+
impl Database {
47
+
pub async fn open(config: &crate::config::Database) -> Result<Self, anyhow::Error> {
48
+
let connection_string = config.connection_info.as_str();
49
+
let tls_connector = if config.use_tls { Some(Self::make_tls(config).await) } else { None };
50
+
51
+
let (dropper, worker) = AsyncDropper::new();
52
+
tokio::task::spawn(worker);
53
+
54
+
let diesel = Self::make_bb8_pool(connection_string, tls_connector.clone()).await?;
55
+
56
+
Ok(Database { tls_connector, dropper, diesel })
57
+
}
58
+
59
+
async fn make_pg_client<T>(
60
+
db_url: &str, tls: T,
61
+
) -> diesel::result::ConnectionResult<diesel_async::AsyncPgConnection>
62
+
where
63
+
T: MakeTlsConnect<Socket>,
64
+
T::Stream: Send + 'static,
65
+
{
66
+
let (cli, conn) = tokio_postgres::connect(db_url, tls).await.map_err(|e| {
67
+
error!("failed to connect db: {e}");
68
+
diesel::result::ConnectionError::BadConnection(format!("{e}"))
69
+
})?;
70
+
71
+
tokio::spawn(async move {
72
+
if let Err(e) = conn.await {
73
+
error!("connection task error: {e}");
74
+
}
75
+
});
76
+
77
+
diesel_async::AsyncPgConnection::try_from(cli).await
78
+
}
79
+
80
+
async fn make_bb8_pool(
81
+
db_url: &str, tls: Option<MakeTlsConnector>,
82
+
) -> Result<
83
+
diesel_async::pooled_connection::bb8::Pool<diesel_async::AsyncPgConnection>,
84
+
anyhow::Error,
85
+
> {
86
+
let mut config = ManagerConfig::default();
87
+
config.custom_setup = Box::new(move |db_url| {
88
+
let tls = tls.clone();
89
+
Box::pin(async move {
90
+
if let Some(tls) = tls {
91
+
Self::make_pg_client(db_url, tls).await
92
+
} else {
93
+
Self::make_pg_client(db_url, NoTls).await
94
+
}
95
+
})
96
+
});
97
+
let cfg = diesel_async::pooled_connection::AsyncDieselConnectionManager::<
98
+
diesel_async::AsyncPgConnection,
99
+
>::new_with_config(db_url, config);
100
+
101
+
let pool = diesel_async::pooled_connection::bb8::Pool::builder()
102
+
.min_idle(Some(1))
103
+
.build(cfg)
104
+
.await?;
105
+
Ok(pool)
106
+
}
107
+
108
+
async fn make_tls(database: &crate::config::Database) -> MakeTlsConnector {
109
+
use native_tls::{Certificate, Identity, TlsConnector};
110
+
111
+
let mut tls_connector = TlsConnector::builder();
112
+
113
+
if let Some(ref client_identity) = database.client_id {
114
+
let client_identity =
115
+
tokio::fs::read(client_identity).await.expect("failed to read db's client id");
116
+
let client_identity = Identity::from_pkcs12(&client_identity, "")
117
+
.expect("failed to load db's client identity (PKCS12)");
118
+
tls_connector.identity(client_identity);
119
+
}
120
+
121
+
if let Some(ref server_ca) = database.server_ca {
122
+
let server_ca =
123
+
tokio::fs::read(server_ca).await.expect("failed to read db's server ca");
124
+
let server_ca =
125
+
Certificate::from_pem(&server_ca).expect("failed to load db's server ca (PEM)");
126
+
tls_connector.add_root_certificate(server_ca);
127
+
}
128
+
129
+
let tls_connector = tls_connector
130
+
.danger_accept_invalid_hostnames(true)
131
+
.build()
132
+
.expect("failed to build TlsConnector");
133
+
134
+
MakeTlsConnector::new(tls_connector)
135
+
}
136
+
137
+
pub async fn get_funcs(
138
+
&self, funcs: &[crate::rpc::PullMetadataFunc<'_>],
139
+
) -> Result<Vec<Option<FunctionInfo>>, anyhow::Error> {
140
+
let chksums: Vec<&[u8]> = funcs.iter().map(|v| v.mb_hash).collect();
141
+
142
+
let rows: Vec<(String, i32, Vec<u8>, Vec<u8>)> = {
143
+
let conn = &mut self.diesel.get().await?;
144
+
145
+
let ct = self.cancel_guard(&*conn);
146
+
147
+
let res: Vec<_> = BestMds(chksums.as_slice()).get_results::<_>(conn).await?;
148
+
ct.consume();
149
+
res
150
+
};
151
+
152
+
let mut partial: HashMap<Vec<u8>, FunctionInfo> = rows
153
+
.into_iter()
154
+
.map(|row| {
155
+
let v = FunctionInfo { name: row.0, len: row.1 as u32, data: row.2, popularity: 0 };
156
+
157
+
(row.3, v)
158
+
})
159
+
.collect();
160
+
161
+
let results = partial.len();
162
+
163
+
let res: Vec<Option<FunctionInfo>> =
164
+
chksums.iter().map(|&chksum| partial.remove(chksum)).collect();
165
+
166
+
trace!("found {}/{} results", results, chksums.len());
167
+
debug_assert_eq!(chksums.len(), res.len());
168
+
Ok(res)
169
+
}
170
+
171
+
pub async fn get_or_create_user<'a>(
172
+
&self, user: &'a crate::rpc::RpcHello<'a>, hostname: &str,
173
+
) -> Result<i32, anyhow::Error> {
174
+
use schema::users;
175
+
176
+
let conn = &mut self.diesel.get().await?;
177
+
178
+
let lic_id = &user.lic_number[..];
179
+
let lic_data = user.license_data;
180
+
181
+
let get_user = || {
182
+
users::table
183
+
.select(users::id)
184
+
.filter(users::lic_data.eq(lic_data))
185
+
.filter(users::lic_id.eq(lic_id))
186
+
.filter(users::hostname.eq(hostname))
187
+
};
188
+
189
+
match get_user().get_result::<i32>(conn).await {
190
+
Ok(v) => return Ok(v),
191
+
Err(err) if err != diesel::result::Error::NotFound => return Err(err.into()),
192
+
_ => {},
193
+
};
194
+
195
+
match diesel::insert_into(users::table)
196
+
.values(vec![(
197
+
users::lic_id.eq(lic_id),
198
+
users::lic_data.eq(lic_data),
199
+
users::hostname.eq(hostname),
200
+
)])
201
+
.returning(users::id) // xmax = 0 if the row is new
202
+
.get_result::<i32>(conn)
203
+
.await
204
+
{
205
+
Ok(v) => return Ok(v),
206
+
Err(diesel::result::Error::DatabaseError(
207
+
diesel::result::DatabaseErrorKind::UniqueViolation,
208
+
_,
209
+
)) => {},
210
+
Err(e) => return Err(e.into()),
211
+
}
212
+
213
+
Ok(get_user().get_result::<i32>(conn).await?)
214
+
}
215
+
216
+
async fn get_or_create_file<'a>(
217
+
&self, funcs: &'a crate::rpc::PushMetadata<'a>,
218
+
) -> Result<i32, anyhow::Error> {
219
+
use schema::files::{chksum, id, table as files};
220
+
221
+
let hash = &funcs.md5[..];
222
+
223
+
let conn = &mut self.diesel.get().await?;
224
+
225
+
let get_file = || files.filter(chksum.eq(hash)).select(id);
226
+
227
+
match get_file().get_result::<i32>(conn).await {
228
+
Ok(v) => return Ok(v),
229
+
Err(err) if err != diesel::result::Error::NotFound => return Err(err.into()),
230
+
_ => {},
231
+
}
232
+
233
+
match diesel::insert_into(files)
234
+
.values(vec![(chksum.eq(hash),)])
235
+
.returning(id)
236
+
.get_result::<i32>(conn)
237
+
.await
238
+
{
239
+
Ok(v) => return Ok(v),
240
+
Err(diesel::result::Error::DatabaseError(
241
+
diesel::result::DatabaseErrorKind::UniqueViolation,
242
+
_,
243
+
)) => {},
244
+
Err(e) => return Err(e.into()),
245
+
}
246
+
Ok(get_file().get_result::<i32>(conn).await?)
247
+
}
248
+
249
+
async fn get_or_create_db<'a>(
250
+
&self, user: &'a crate::rpc::RpcHello<'a>, funcs: &'a crate::rpc::PushMetadata<'a>,
251
+
) -> Result<i32, anyhow::Error> {
252
+
use schema::dbs::{
253
+
file_id as db_file_id, file_path, id as db_id, idb_path, table as dbs,
254
+
user_id as db_user,
255
+
};
256
+
257
+
let file_id = self.get_or_create_file(funcs);
258
+
let user_id = self.get_or_create_user(user, funcs.hostname);
259
+
260
+
let (file_id, user_id): (i32, i32) = futures_util::try_join!(file_id, user_id)?;
261
+
262
+
let conn = &mut self.diesel.get().await?;
263
+
264
+
let get_db = || {
265
+
dbs.select(db_id)
266
+
.filter(db_user.eq(user_id))
267
+
.filter(db_file_id.eq(file_id))
268
+
.filter(file_path.eq(funcs.file_path))
269
+
.filter(idb_path.eq(funcs.idb_path))
270
+
};
271
+
272
+
match get_db().get_result::<i32>(conn).await {
273
+
Ok(v) => return Ok(v),
274
+
Err(err) if err != diesel::result::Error::NotFound => return Err(err.into()),
275
+
_ => {},
276
+
};
277
+
278
+
match diesel::insert_into(dbs)
279
+
.values(vec![(
280
+
db_user.eq(user_id),
281
+
db_file_id.eq(file_id),
282
+
file_path.eq(funcs.file_path),
283
+
idb_path.eq(funcs.idb_path),
284
+
)])
285
+
.returning(db_id)
286
+
.get_result::<i32>(conn)
287
+
.await
288
+
{
289
+
Ok(id) => return Ok(id),
290
+
Err(diesel::result::Error::DatabaseError(
291
+
diesel::result::DatabaseErrorKind::UniqueViolation,
292
+
_,
293
+
)) => {},
294
+
Err(e) => return Err(e.into()),
295
+
};
296
+
Ok(get_db().get_result::<i32>(conn).await?)
297
+
}
298
+
299
+
pub async fn push_funcs<'a, 'b>(
300
+
&'b self, user: &'a crate::rpc::RpcHello<'a>, funcs: &'a crate::rpc::PushMetadata<'a>,
301
+
scores: &[u32],
302
+
) -> Result<Vec<bool>, anyhow::Error> {
303
+
use futures_util::TryStreamExt;
304
+
305
+
// postgres has a limitation of binding per statement (i16::MAX). Split large push requests into smaller chunks.
306
+
const PUSH_FUNC_CHUNK_SIZE: usize = 3000;
307
+
308
+
let db_id = self.get_or_create_db(user, funcs).await?;
309
+
310
+
let mut rows = Vec::with_capacity(funcs.funcs.len().min(PUSH_FUNC_CHUNK_SIZE));
311
+
let mut is_new = Vec::with_capacity(funcs.funcs.len());
312
+
let conn = &mut self.diesel.get().await?;
313
+
let f2 = diesel::alias!(schema::funcs as f2);
314
+
315
+
for (idx, (func, &score)) in funcs.funcs.iter().zip(scores.iter()).enumerate() {
316
+
let name = func.name;
317
+
let len = func.func_len as i32;
318
+
let chksum = func.hash;
319
+
let md = func.func_data;
320
+
let score = score as i32;
321
+
322
+
rows.push((
323
+
schema::funcs::name.eq(name),
324
+
schema::funcs::len.eq(len),
325
+
schema::funcs::chksum.eq(chksum),
326
+
schema::funcs::metadata.eq(md),
327
+
schema::funcs::rank.eq(score),
328
+
schema::funcs::db_id.eq(db_id),
329
+
));
330
+
331
+
if rows.len() < PUSH_FUNC_CHUNK_SIZE && idx < funcs.funcs.len() - 1 {
332
+
continue;
333
+
}
334
+
335
+
let mut current_rows =
336
+
Vec::with_capacity((funcs.funcs.len() - (idx + 1)).max(PUSH_FUNC_CHUNK_SIZE));
337
+
std::mem::swap(&mut current_rows, &mut rows);
338
+
339
+
diesel::insert_into(schema::funcs::table)
340
+
.values(current_rows)
341
+
.on_conflict((schema::funcs::chksum, schema::funcs::db_id))
342
+
.do_update()
343
+
.set((
344
+
schema::funcs::name.eq(excluded(schema::funcs::name)),
345
+
schema::funcs::metadata.eq(excluded(schema::funcs::metadata)),
346
+
schema::funcs::rank.eq(excluded(schema::funcs::rank)),
347
+
schema::funcs::update_dt.eq(diesel::dsl::now),
348
+
))
349
+
.returning(diesel::dsl::not(diesel::dsl::exists(
350
+
f2.filter(f2.field(schema::funcs::chksum).eq(schema::funcs::chksum)),
351
+
))) // xmax=0 when a new row is created.
352
+
.load_stream::<bool>(conn)
353
+
.await?
354
+
.try_fold(&mut is_new, |acc, item: bool| {
355
+
acc.push(item);
356
+
futures_util::future::ready(Ok(acc))
357
+
})
358
+
.await?;
359
+
}
360
+
361
+
Ok(is_new)
362
+
}
363
+
364
+
pub async fn get_file_funcs(
365
+
&self, md5: &[u8], offset: i64, limit: i64,
366
+
) -> Result<Vec<(String, i32, Vec<u8>)>, anyhow::Error> {
367
+
let conn = &mut self.diesel.get().await?;
368
+
let results = schema::funcs::table
369
+
.left_join(schema::dbs::table.left_join(schema::files::table))
370
+
.select((
371
+
schema::funcs::name.assume_not_null(),
372
+
schema::funcs::len.assume_not_null(),
373
+
schema::funcs::chksum.assume_not_null(),
374
+
))
375
+
.filter(schema::files::chksum.eq(md5))
376
+
.offset(offset)
377
+
.limit(limit)
378
+
.get_results::<(String, i32, Vec<u8>)>(conn)
379
+
.await?;
380
+
Ok(results)
381
+
}
382
+
383
+
pub async fn get_files_with_func(&self, func: &[u8]) -> Result<Vec<Vec<u8>>, anyhow::Error> {
384
+
let conn = &mut self.diesel.get().await?;
385
+
386
+
let res = schema::files::table
387
+
.left_join(schema::dbs::table.left_join(schema::funcs::table))
388
+
.select(schema::files::chksum.assume_not_null())
389
+
.distinct()
390
+
.filter(schema::funcs::chksum.eq(func))
391
+
.get_results::<Vec<u8>>(conn)
392
+
.await?;
393
+
Ok(res)
394
+
}
395
+
396
+
fn cancel_guard(
397
+
&self,
398
+
conn: &diesel_async::pooled_connection::bb8::PooledConnection<
399
+
'_,
400
+
diesel_async::AsyncPgConnection,
401
+
>,
402
+
) -> AsyncDropGuard {
403
+
let token = conn.cancel_token();
404
+
let tls_connector = self.tls_connector.clone();
405
+
self.dropper.defer(async move {
406
+
debug!("cancelling query...");
407
+
408
+
if let Some(tls) = tls_connector {
409
+
let _ = token.cancel_query(tls).await;
410
+
} else {
411
+
let _ = token.cancel_query(NoTls).await;
412
+
}
413
+
})
414
+
}
415
+
416
+
pub async fn delete_metadata(
417
+
&self, req: &crate::rpc::DelHistory<'_>,
418
+
) -> Result<(), anyhow::Error> {
419
+
use schema::funcs::{chksum, table as funcs};
420
+
421
+
let chksums = req.funcs.iter().map(|v| v.as_slice()).collect::<Vec<_>>();
422
+
423
+
let conn = &mut self.diesel.get().await?;
424
+
let rows_modified =
425
+
diesel::delete(funcs.filter(chksum.eq_any(&chksums))).execute(conn).await?;
426
+
427
+
debug!("deleted {rows_modified} rows");
428
+
429
+
Ok(())
430
+
}
431
+
432
+
pub async fn get_func_histories(
433
+
&self, chksum: &[u8], limit: u32,
434
+
) -> Result<Vec<(OffsetDateTime, String, Vec<u8>)>, anyhow::Error> {
435
+
let conn = &mut self.diesel.get().await?;
436
+
let rows = &schema::funcs::table.select((
437
+
schema::funcs::update_dt.assume_not_null(),
438
+
schema::funcs::name,
439
+
schema::funcs::metadata.assume_not_null(),
440
+
));
441
+
let rows = rows
442
+
.limit(limit as i64)
443
+
.order_by(schema::funcs::update_dt.desc())
444
+
.filter(schema::funcs::chksum.eq(chksum))
445
+
.get_results::<(time::OffsetDateTime, String, Vec<u8>)>(conn)
446
+
.await?;
447
+
Ok(rows)
448
+
}
449
+
}
450
+
451
+
// This is eww, but it's the fastest.
452
+
struct BestMds<'a>(&'a [&'a [u8]]);
453
+
impl<'a> QueryFragment<diesel::pg::Pg> for BestMds<'a> {
454
+
fn walk_ast<'b>(
455
+
&'b self, mut pass: diesel::query_builder::AstPass<'_, 'b, diesel::pg::Pg>,
456
+
) -> diesel::QueryResult<()> {
457
+
pass.push_sql(
458
+
r#"WITH best AS (
459
+
select chksum,MAX(rank) as maxrank from funcs f1
460
+
WHERE chksum = ANY("#,
461
+
);
462
+
pass.push_bind_param::<Array<Binary>, _>(&self.0)?;
463
+
pass.push_sql(
464
+
r#")
465
+
GROUP BY chksum
466
+
)
467
+
SELECT f2.name,f2.len,f2.metadata,f2.chksum FROM best
468
+
LEFT JOIN funcs f2 ON (best.chksum=f2.chksum AND best.maxrank=f2.rank)"#,
469
+
);
470
+
Ok(())
471
+
}
472
+
}
473
+
impl<'a> diesel::query_builder::QueryId for BestMds<'a> {
474
+
type QueryId = BestMds<'static>;
475
+
}
476
+
impl<'a> Query for BestMds<'a> {
477
+
type SqlType = (VarChar, Integer, Binary, Binary);
478
+
}
+17
common/src/db/schema.rs
+17
common/src/db/schema.rs
···
1
+
pub use super::schema_auto::*;
2
+
3
+
diesel::table! {
4
+
func_ranks {
5
+
id -> Int4,
6
+
name -> Text,
7
+
len -> Int4,
8
+
db_id -> Int4,
9
+
chksum -> Nullable<Bytea>,
10
+
metadata -> Nullable<Bytea>,
11
+
rank -> Nullable<Int4>,
12
+
push_dt -> Nullable<Timestamptz>,
13
+
update_dt -> Nullable<Timestamptz>,
14
+
}
15
+
}
16
+
17
+
diesel::joinable!(func_ranks -> dbs (id));
+48
common/src/db/schema_auto.rs
+48
common/src/db/schema_auto.rs
···
1
+
// @generated automatically by Diesel CLI.
2
+
3
+
diesel::table! {
4
+
dbs (id) {
5
+
id -> Int4,
6
+
file_path -> Nullable<Varchar>,
7
+
idb_path -> Nullable<Varchar>,
8
+
file_id -> Nullable<Int4>,
9
+
user_id -> Nullable<Int4>,
10
+
}
11
+
}
12
+
13
+
diesel::table! {
14
+
files (id) {
15
+
id -> Int4,
16
+
chksum -> Nullable<Bytea>,
17
+
}
18
+
}
19
+
20
+
diesel::table! {
21
+
funcs (id) {
22
+
id -> Int4,
23
+
name -> Text,
24
+
len -> Int4,
25
+
db_id -> Int4,
26
+
chksum -> Nullable<Bytea>,
27
+
metadata -> Nullable<Bytea>,
28
+
rank -> Nullable<Int4>,
29
+
push_dt -> Nullable<Timestamptz>,
30
+
update_dt -> Nullable<Timestamptz>,
31
+
}
32
+
}
33
+
34
+
diesel::table! {
35
+
users (id) {
36
+
id -> Int4,
37
+
lic_id -> Nullable<Bytea>,
38
+
lic_data -> Nullable<Bytea>,
39
+
hostname -> Nullable<Varchar>,
40
+
first_seen -> Nullable<Timestamptz>,
41
+
}
42
+
}
43
+
44
+
diesel::joinable!(dbs -> files (file_id));
45
+
diesel::joinable!(dbs -> users (user_id));
46
+
diesel::joinable!(funcs -> dbs (db_id));
47
+
48
+
diesel::allow_tables_to_appear_in_same_query!(dbs, files, funcs, users,);
+10
-3
common/src/lib.rs
+10
-3
common/src/lib.rs
···
3
3
4
4
use std::fmt::Write;
5
5
6
-
pub mod db;
6
+
pub mod async_drop;
7
7
pub mod config;
8
+
pub mod db;
8
9
pub mod md;
10
+
pub mod metrics;
9
11
pub mod rpc;
10
12
pub mod web;
11
13
···
13
15
pub db: db::Database,
14
16
pub config: std::sync::Arc<config::Config>,
15
17
pub server_name: String,
18
+
pub metrics: metrics::Metrics,
16
19
}
17
20
18
21
pub type SharedState = std::sync::Arc<SharedState_>;
···
22
25
const CHUNK_SIZE: usize = 32;
23
26
data.chunks(CHUNK_SIZE).for_each(|chunk| {
24
27
for &ch in chunk {
25
-
let _ = write!(&mut output, "{:02x} ", ch);
28
+
let _ = write!(&mut output, "{ch:02x} ");
26
29
}
27
30
let padding = CHUNK_SIZE - chunk.len();
28
31
for _ in 0..padding {
···
30
33
}
31
34
32
35
let _ = write!(&mut output, " | ");
33
-
for ch in chunk.iter().chain(std::iter::repeat(&b' ').take(padding)).map(|&v| std::char::from_u32(v as u32).unwrap_or('.')) {
36
+
for ch in chunk
37
+
.iter()
38
+
.chain(std::iter::repeat(&b' ').take(padding))
39
+
.map(|&v| std::char::from_u32(v as u32).unwrap_or('.'))
40
+
{
34
41
if !ch.is_ascii_graphic() {
35
42
output.push('.');
36
43
} else {
+218
-214
common/src/md.rs
+218
-214
common/src/md.rs
···
1
-
use std::collections::HashSet;
2
-
3
-
use serde::{Serialize, Deserialize};
4
-
use crate::rpc::de::from_slice;
5
-
6
-
#[derive(Serialize, Deserialize)]
7
-
pub struct MetadataChunk<'a> {
8
-
code: u32,
9
-
data: &'a [u8],
10
-
}
11
-
12
-
#[derive(Debug)]
13
-
pub enum FunctionMetadata<'a> {
14
-
FunctionComment(FunctionComment<'a>),
15
-
ByteComment(ByteComment<'a>),
16
-
ExtraComment(ExtraComment<'a>),
17
-
}
18
-
19
-
#[derive(Debug)]
20
-
pub struct FunctionComment<'a> {
21
-
pub is_repeatable: bool,
22
-
pub comment: &'a str,
23
-
}
24
-
25
-
#[derive(Debug)]
26
-
pub struct ByteComment<'a> {
27
-
pub is_repeatable: bool,
28
-
pub offset: u32,
29
-
pub comment: &'a str,
30
-
}
31
-
32
-
#[derive(Debug)]
33
-
pub struct ExtraComment<'a> {
34
-
pub offset: u32,
35
-
pub anterior: &'a str,
36
-
pub posterior: &'a str,
37
-
}
38
-
39
-
impl<'a> FunctionMetadata<'a> {
40
-
fn is_useful(&self) -> bool {
41
-
// TODO: rewrite using regex with configurable library names
42
-
match self {
43
-
FunctionMetadata::ExtraComment(cmt) => {
44
-
if cmt.anterior.starts_with("; Exported entry ") // offset=0
45
-
{
46
-
return false;
47
-
}
48
-
if cmt.anterior.is_empty() && cmt.posterior.is_empty() {
49
-
return false;
50
-
}
51
-
},
52
-
FunctionMetadata::FunctionComment(cmt) => {
53
-
if cmt.comment == "Microsoft VisualC v14 64bit runtime"
54
-
|| cmt.comment == "Microsoft VisualC 64bit universal runtime"
55
-
{
56
-
return false;
57
-
}
58
-
if cmt.comment.is_empty() {
59
-
return false;
60
-
}
61
-
},
62
-
FunctionMetadata::ByteComment(cmt) => {
63
-
if cmt.comment == "Trap to Debugger"
64
-
|| (cmt.comment.starts_with("jumptable ") && cmt.comment.contains(" case")) // repeatable=true
65
-
|| cmt.comment == "switch jump"
66
-
|| (cmt.comment.starts_with("switch ") && cmt.comment.ends_with(" cases "))
67
-
|| cmt.comment == "jump table for switch statement"
68
-
|| cmt.comment == "indirect table for switch statement"
69
-
|| cmt.comment == "Microsoft VisualC v7/14 64bit runtime"
70
-
|| cmt.comment == "Microsoft VisualC v7/14 64bit runtime\nMicrosoft VisualC v14 64bit runtime"
71
-
|| cmt.comment == "Microsoft VisualC v14 64bit runtime" {
72
-
return false;
73
-
}
74
-
if cmt.comment.is_empty() {
75
-
return false;
76
-
}
77
-
},
78
-
}
79
-
true
80
-
}
81
-
}
82
-
83
-
fn deserialize_seq<'de, T: Deserialize<'de>>(mut data: &'de [u8]) -> Result<Vec<(u32, T)>, crate::rpc::Error> {
84
-
let mut res = vec![];
85
-
let mut reset = true;
86
-
let (mut offset, used): (u32, usize) = from_slice(data)?;
87
-
data = &data[used..];
88
-
if data.is_empty() {
89
-
return Err(crate::rpc::Error::UnexpectedEof);
90
-
}
91
-
92
-
loop {
93
-
let (offset_diff, used): (u32, usize) = from_slice(data)?;
94
-
data = &data[used..];
95
-
if data.is_empty() {
96
-
return Err(crate::rpc::Error::UnexpectedEof);
97
-
}
98
-
99
-
if (offset_diff > 0) || reset {
100
-
offset += offset_diff;
101
-
let (e, used): (T, usize) = from_slice(data)?;
102
-
data = &data[used..];
103
-
104
-
res.push((offset, e));
105
-
106
-
reset = false;
107
-
} else {
108
-
let (offset_diff, used): (u32, usize) = from_slice(data)?;
109
-
data = &data[used..];
110
-
111
-
offset = offset_diff;
112
-
reset = true;
113
-
}
114
-
115
-
if data.is_empty() {
116
-
break;
117
-
}
118
-
}
119
-
120
-
Ok(res)
121
-
}
122
-
123
-
pub fn parse_metadata(mut data: &[u8]) -> Result<Vec<FunctionMetadata<'_>>, crate::rpc::Error> {
124
-
let mut res = vec![];
125
-
let mut bad_codes = HashSet::new();
126
-
127
-
while !data.is_empty() {
128
-
let (chunk, used) :(MetadataChunk, _) = from_slice(data)?;
129
-
data = &data[used..];
130
-
131
-
let data = chunk.data;
132
-
133
-
if data.is_empty() {
134
-
continue;
135
-
}
136
-
137
-
match chunk.code {
138
-
1 => {}, // TODO: parse typeinfo
139
-
2 => {}, // nop
140
-
3 | 4 => { // function comments
141
-
let is_repeatable = chunk.code == 4;
142
-
let cmt = std::str::from_utf8(data)?;
143
-
res.push(FunctionMetadata::FunctionComment(FunctionComment{
144
-
is_repeatable,
145
-
comment: cmt,
146
-
}));
147
-
},
148
-
5 | 6 => { // comments
149
-
let is_repeatable = chunk.code == 6;
150
-
let byte_comments: Vec<(_, &[u8])> = match deserialize_seq(data) {
151
-
Ok(v) => v,
152
-
Err(err) => {
153
-
log::error!("err: {}\n{}", err, super::make_pretty_hex(data));
154
-
return Err(err);
155
-
},
156
-
};
157
-
158
-
for comment in byte_comments {
159
-
let cmt = std::str::from_utf8(comment.1)?;
160
-
res.push(FunctionMetadata::ByteComment(
161
-
ByteComment{
162
-
is_repeatable,
163
-
offset: comment.0,
164
-
comment: cmt,
165
-
}
166
-
));
167
-
}
168
-
},
169
-
7 => { // extra comments
170
-
let byte_comments: Vec<(_, (&[u8], &[u8]))> = match deserialize_seq(data) {
171
-
Ok(v) => v,
172
-
Err(err) => {
173
-
log::error!("err: {}\n{}", err, super::make_pretty_hex(data));
174
-
return Err(err);
175
-
},
176
-
};
177
-
178
-
for comment in byte_comments {
179
-
res.push(FunctionMetadata::ExtraComment(ExtraComment{
180
-
offset: comment.0,
181
-
anterior: std::str::from_utf8(comment.1.0)?,
182
-
posterior: std::str::from_utf8(comment.1.1)?,
183
-
}));
184
-
}
185
-
},
186
-
9 | 10 => { /* TODO! */ },
187
-
_ => {
188
-
bad_codes.insert(chunk.code);
189
-
},
190
-
}
191
-
}
192
-
193
-
Ok(res)
194
-
}
195
-
196
-
pub fn get_score(md: &crate::rpc::PushMetadataFunc) -> u32 {
197
-
let mut score = 0;
198
-
199
-
let md = match parse_metadata(md.func_data) {
200
-
Ok(v) => v,
201
-
Err(e) => {
202
-
log::warn!("failed to parse metadata: {}", e);
203
-
return 0;
204
-
}
205
-
};
206
-
207
-
for md in md {
208
-
if md.is_useful() {
209
-
score += 10;
210
-
}
211
-
}
212
-
213
-
score
214
-
}
1
+
use std::collections::HashSet;
2
+
3
+
use crate::rpc::de::from_slice;
4
+
use serde::{Deserialize, Serialize};
5
+
6
+
#[derive(Serialize, Deserialize)]
7
+
pub struct MetadataChunk<'a> {
8
+
code: u32,
9
+
data: &'a [u8],
10
+
}
11
+
12
+
#[derive(Debug)]
13
+
pub enum FunctionMetadata<'a> {
14
+
FunctionComment(FunctionComment<'a>),
15
+
ByteComment(ByteComment<'a>),
16
+
ExtraComment(ExtraComment<'a>),
17
+
}
18
+
19
+
#[derive(Debug)]
20
+
pub struct FunctionComment<'a> {
21
+
pub is_repeatable: bool,
22
+
pub comment: &'a str,
23
+
}
24
+
25
+
#[derive(Debug)]
26
+
pub struct ByteComment<'a> {
27
+
pub is_repeatable: bool,
28
+
pub offset: u32,
29
+
pub comment: &'a str,
30
+
}
31
+
32
+
#[derive(Debug)]
33
+
pub struct ExtraComment<'a> {
34
+
pub offset: u32,
35
+
pub anterior: &'a str,
36
+
pub posterior: &'a str,
37
+
}
38
+
39
+
impl<'a> FunctionMetadata<'a> {
40
+
fn is_useful(&self) -> bool {
41
+
// TODO: rewrite using regex with configurable library names
42
+
match self {
43
+
FunctionMetadata::ExtraComment(cmt) => {
44
+
if cmt.anterior.starts_with("; Exported entry ")
45
+
// offset=0
46
+
{
47
+
return false;
48
+
}
49
+
if cmt.anterior.is_empty() && cmt.posterior.is_empty() {
50
+
return false;
51
+
}
52
+
},
53
+
FunctionMetadata::FunctionComment(cmt) => {
54
+
if cmt.comment == "Microsoft VisualC v14 64bit runtime"
55
+
|| cmt.comment == "Microsoft VisualC 64bit universal runtime"
56
+
{
57
+
return false;
58
+
}
59
+
if cmt.comment.is_empty() {
60
+
return false;
61
+
}
62
+
},
63
+
FunctionMetadata::ByteComment(cmt) => {
64
+
if cmt.comment == "Trap to Debugger"
65
+
|| (cmt.comment.starts_with("jumptable ") && cmt.comment.contains(" case")) // repeatable=true
66
+
|| cmt.comment == "switch jump"
67
+
|| (cmt.comment.starts_with("switch ") && cmt.comment.ends_with(" cases "))
68
+
|| cmt.comment == "jump table for switch statement"
69
+
|| cmt.comment == "indirect table for switch statement"
70
+
|| cmt.comment == "Microsoft VisualC v7/14 64bit runtime"
71
+
|| cmt.comment == "Microsoft VisualC v7/14 64bit runtime\nMicrosoft VisualC v14 64bit runtime"
72
+
|| cmt.comment == "Microsoft VisualC v14 64bit runtime" {
73
+
return false;
74
+
}
75
+
if cmt.comment.is_empty() {
76
+
return false;
77
+
}
78
+
},
79
+
}
80
+
true
81
+
}
82
+
}
83
+
84
+
fn deserialize_seq<'de, T: Deserialize<'de>>(
85
+
mut data: &'de [u8],
86
+
) -> Result<Vec<(u32, T)>, crate::rpc::Error> {
87
+
let mut res = vec![];
88
+
let mut reset = true;
89
+
let (mut offset, used): (u32, usize) = from_slice(data)?;
90
+
data = &data[used..];
91
+
if data.is_empty() {
92
+
return Err(crate::rpc::Error::UnexpectedEof);
93
+
}
94
+
95
+
loop {
96
+
let (offset_diff, used): (u32, usize) = from_slice(data)?;
97
+
data = &data[used..];
98
+
if data.is_empty() {
99
+
return Err(crate::rpc::Error::UnexpectedEof);
100
+
}
101
+
102
+
if (offset_diff > 0) || reset {
103
+
offset += offset_diff;
104
+
let (e, used): (T, usize) = from_slice(data)?;
105
+
data = &data[used..];
106
+
107
+
res.push((offset, e));
108
+
109
+
reset = false;
110
+
} else {
111
+
let (offset_diff, used): (u32, usize) = from_slice(data)?;
112
+
data = &data[used..];
113
+
114
+
offset = offset_diff;
115
+
reset = true;
116
+
}
117
+
118
+
if data.is_empty() {
119
+
break;
120
+
}
121
+
}
122
+
123
+
Ok(res)
124
+
}
125
+
126
+
pub fn parse_metadata(mut data: &[u8]) -> Result<Vec<FunctionMetadata<'_>>, crate::rpc::Error> {
127
+
let mut res = vec![];
128
+
let mut bad_codes = HashSet::new();
129
+
130
+
while !data.is_empty() {
131
+
let (chunk, used): (MetadataChunk, _) = from_slice(data)?;
132
+
data = &data[used..];
133
+
134
+
let data = chunk.data;
135
+
136
+
if data.is_empty() {
137
+
continue;
138
+
}
139
+
140
+
match chunk.code {
141
+
1 => {}, // TODO: parse typeinfo
142
+
2 => {}, // nop
143
+
3 | 4 => {
144
+
// function comments
145
+
let is_repeatable = chunk.code == 4;
146
+
let cmt = std::str::from_utf8(data)?;
147
+
res.push(FunctionMetadata::FunctionComment(FunctionComment {
148
+
is_repeatable,
149
+
comment: cmt,
150
+
}));
151
+
},
152
+
5 | 6 => {
153
+
// comments
154
+
let is_repeatable = chunk.code == 6;
155
+
let byte_comments: Vec<(_, &[u8])> = match deserialize_seq(data) {
156
+
Ok(v) => v,
157
+
Err(err) => {
158
+
log::error!("err: {}\n{}", err, super::make_pretty_hex(data));
159
+
return Err(err);
160
+
},
161
+
};
162
+
163
+
for comment in byte_comments {
164
+
let cmt = std::str::from_utf8(comment.1)?;
165
+
res.push(FunctionMetadata::ByteComment(ByteComment {
166
+
is_repeatable,
167
+
offset: comment.0,
168
+
comment: cmt,
169
+
}));
170
+
}
171
+
},
172
+
7 => {
173
+
// extra comments
174
+
let byte_comments: Vec<(_, (&[u8], &[u8]))> = match deserialize_seq(data) {
175
+
Ok(v) => v,
176
+
Err(err) => {
177
+
log::error!("err: {}\n{}", err, super::make_pretty_hex(data));
178
+
return Err(err);
179
+
},
180
+
};
181
+
182
+
for comment in byte_comments {
183
+
res.push(FunctionMetadata::ExtraComment(ExtraComment {
184
+
offset: comment.0,
185
+
anterior: std::str::from_utf8(comment.1 .0)?,
186
+
posterior: std::str::from_utf8(comment.1 .1)?,
187
+
}));
188
+
}
189
+
},
190
+
9 | 10 => { /* TODO! */ },
191
+
_ => {
192
+
bad_codes.insert(chunk.code);
193
+
},
194
+
}
195
+
}
196
+
197
+
Ok(res)
198
+
}
199
+
200
+
pub fn get_score(md: &crate::rpc::PushMetadataFunc) -> u32 {
201
+
let mut score = 0;
202
+
203
+
let md = match parse_metadata(md.func_data) {
204
+
Ok(v) => v,
205
+
Err(e) => {
206
+
log::warn!("failed to parse metadata: {}", e);
207
+
return 0;
208
+
},
209
+
};
210
+
211
+
for md in md {
212
+
if md.is_useful() {
213
+
score += 10;
214
+
}
215
+
}
216
+
217
+
score
218
+
}
+80
common/src/metrics.rs
+80
common/src/metrics.rs
···
1
+
use std::sync::atomic::AtomicI64;
2
+
3
+
use prometheus_client::{
4
+
encoding::EncodeLabelSet,
5
+
metrics::{counter::Counter, family::Family, gauge::Gauge},
6
+
registry::Registry,
7
+
};
8
+
9
+
pub struct Metrics {
10
+
pub registry: Registry,
11
+
12
+
/// Count active lumina connections
13
+
pub active_connections: Gauge<i64, AtomicI64>,
14
+
15
+
/// Record connected client versions
16
+
pub lumina_version: Family<LuminaVersion, Gauge>,
17
+
18
+
/// Count new functions pushes
19
+
pub new_funcs: Counter<u64>,
20
+
21
+
/// Count pushed functions
22
+
pub pushes: Counter<u64>,
23
+
24
+
/// Count pulled functions (only found)
25
+
pub pulls: Counter<u64>,
26
+
27
+
/// Queried functions
28
+
pub queried_funcs: Counter<u64>,
29
+
}
30
+
31
+
#[derive(EncodeLabelSet, Debug, Hash, Eq, PartialEq, Clone)]
32
+
pub struct LuminaVersion {
33
+
pub protocol_version: u32,
34
+
}
35
+
36
+
impl Default for Metrics {
37
+
fn default() -> Self {
38
+
let mut registry = Registry::default();
39
+
40
+
let active_connections = Gauge::default();
41
+
registry.register(
42
+
"lumen_active_connections",
43
+
"Active Lumina connections",
44
+
active_connections.clone(),
45
+
);
46
+
47
+
let lumina_version = Family::<LuminaVersion, Gauge>::default();
48
+
registry.register(
49
+
"lumen_protocol_version",
50
+
"Version of Lumina protocol being used",
51
+
lumina_version.clone(),
52
+
);
53
+
54
+
let new_funcs = Counter::default();
55
+
registry.register(
56
+
"lumen_new_funcs",
57
+
"Pushes previously unknown functions",
58
+
new_funcs.clone(),
59
+
);
60
+
61
+
let pushes = Counter::default();
62
+
registry.register("lumen_pushes_total", "Total pushes functions", pushes.clone());
63
+
64
+
let pulls = Counter::default();
65
+
registry.register("lumen_pulls_total", "Total pulled functions", pulls.clone());
66
+
67
+
let queried_funcs = Counter::default();
68
+
registry.register("lumen_queried_total", "Total Queried functions", queried_funcs.clone());
69
+
70
+
Metrics {
71
+
registry,
72
+
active_connections,
73
+
lumina_version,
74
+
new_funcs,
75
+
pushes,
76
+
pulls,
77
+
queried_funcs,
78
+
}
79
+
}
80
+
}
+163
-159
common/src/rpc/de.rs
+163
-159
common/src/rpc/de.rs
···
1
-
use serde::Deserialize;
2
-
use serde::de::{self, DeserializeSeed, SeqAccess, Visitor};
3
-
use super::Error;
4
-
5
-
struct Deserializer<'de> {
6
-
input: &'de [u8],
7
-
}
8
-
9
-
impl<'de> Deserializer<'de> {
10
-
fn from_bytes(b: &'de [u8]) -> Self {
11
-
Self {
12
-
input: b,
13
-
}
14
-
}
15
-
16
-
fn unpack_dd(&mut self) -> Result<u32, Error> {
17
-
let (v, len) = super::packing::unpack_dd(self.input);
18
-
if len == 0 {
19
-
Err(Error::UnexpectedEof)
20
-
} else {
21
-
self.input = &self.input[len..];
22
-
Ok(v)
23
-
}
24
-
}
25
-
26
-
fn unpack_dq(&mut self) -> Result<u64, Error> {
27
-
let a = self.unpack_dd()? as u64;
28
-
let b = self.unpack_dd()? as u64;
29
-
Ok((a << 32) | b)
30
-
}
31
-
32
-
fn unpack_var_bytes(&mut self) -> Result<&'de [u8], Error> {
33
-
let bytes = self.unpack_dd()? as usize;
34
-
if bytes > self.input.len() {
35
-
return Err(Error::UnexpectedEof);
36
-
}
37
-
38
-
let payload = &self.input[..bytes];
39
-
self.input = &self.input[bytes..];
40
-
assert_eq!(payload.len(), bytes);
41
-
42
-
Ok(payload)
43
-
}
44
-
45
-
fn unpack_cstr(&mut self) -> Result<&'de str, Error> {
46
-
let len = self.input.iter().enumerate().find_map(|(idx, &v)| if v == 0 { Some(idx) } else { None });
47
-
let len = match len {
48
-
Some(v) => v,
49
-
None => return Err(Error::UnexpectedEof),
50
-
};
51
-
let res = match std::str::from_utf8(&self.input[..len]) {
52
-
Ok(v) => v,
53
-
Err(err) => {
54
-
return Err(err.into());
55
-
}
56
-
};
57
-
self.input = &self.input[len + 1..];
58
-
Ok(res)
59
-
}
60
-
61
-
fn take_byte(&mut self) -> Result<u8, Error> {
62
-
if self.input.is_empty() {
63
-
return Err(Error::UnexpectedEof);
64
-
}
65
-
66
-
let v = self.input[0];
67
-
self.input = &self.input[1..];
68
-
Ok(v)
69
-
}
70
-
}
71
-
72
-
/// Returns: a tuple containing the deserialized struct and the bytes used
73
-
pub fn from_slice<'a, T: Deserialize<'a>>(b: &'a [u8]) -> Result<(T, usize), Error> {
74
-
let mut de = Deserializer::from_bytes(b);
75
-
let v = T::deserialize(&mut de)?;
76
-
Ok((v, b.len() - de.input.len()))
77
-
}
78
-
79
-
impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
80
-
type Error = Error;
81
-
82
-
fn deserialize_any<V: Visitor<'de>>(self, _: V) -> Result<V::Value, Self::Error> {
83
-
unimplemented!()
84
-
}
85
-
86
-
fn deserialize_u8<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value, Self::Error> {
87
-
visitor.visit_u8(self.take_byte()?)
88
-
}
89
-
90
-
fn deserialize_u32<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value, Self::Error> {
91
-
visitor.visit_u32(self.unpack_dd()?)
92
-
}
93
-
94
-
fn deserialize_u64<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value, Self::Error> {
95
-
visitor.visit_u64(self.unpack_dq()?)
96
-
}
97
-
98
-
fn deserialize_seq<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value, Self::Error> {
99
-
let len = self.unpack_dd()?;
100
-
101
-
visitor.visit_seq(Access {
102
-
len: len as usize,
103
-
de: &mut *self,
104
-
})
105
-
}
106
-
107
-
fn deserialize_str<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value, Self::Error> {
108
-
visitor.visit_borrowed_str(self.unpack_cstr()?)
109
-
}
110
-
111
-
fn deserialize_bytes<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value, Self::Error> {
112
-
let v = self.unpack_var_bytes()?;
113
-
visitor.visit_borrowed_bytes(v)
114
-
}
115
-
116
-
fn deserialize_tuple<V: Visitor<'de>>(self, len: usize, visitor: V) -> Result<V::Value, Self::Error> {
117
-
visitor.visit_seq(Access {
118
-
len,
119
-
de: &mut *self,
120
-
})
121
-
}
122
-
123
-
fn deserialize_tuple_struct<V: Visitor<'de>>(self, _name: &'static str, len: usize, visitor: V) -> Result<V::Value, Self::Error> {
124
-
self.deserialize_tuple(len, visitor)
125
-
}
126
-
127
-
fn deserialize_struct<V: Visitor<'de>>(self, name: &'static str, fields: &'static [&'static str], visitor: V) -> Result<V::Value, Self::Error> {
128
-
self.deserialize_tuple_struct(name, fields.len(), visitor)
129
-
}
130
-
131
-
serde::forward_to_deserialize_any! {
132
-
i8 i16 i32 i64 char u16 bool
133
-
f32 f64 string byte_buf option unit unit_struct newtype_struct map enum identifier ignored_any
134
-
}
135
-
}
136
-
137
-
struct Access<'a, 'de> {
138
-
de: &'a mut Deserializer<'de>,
139
-
len: usize,
140
-
}
141
-
142
-
impl<'de, 'a> SeqAccess<'a> for Access<'de, 'a> {
143
-
type Error = Error;
144
-
145
-
fn next_element_seed<T: DeserializeSeed<'a>>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error> {
146
-
if self.len > 0 {
147
-
self.len -= 1;
148
-
149
-
let v = serde::de::DeserializeSeed::deserialize(seed, &mut *self.de)?;
150
-
Ok(Some(v))
151
-
} else {
152
-
Ok(None)
153
-
}
154
-
}
155
-
156
-
fn size_hint(&self) -> Option<usize> {
157
-
Some(self.len)
158
-
}
159
-
}
1
+
use super::Error;
2
+
use serde::de::{self, DeserializeSeed, SeqAccess, Visitor};
3
+
use serde::Deserialize;
4
+
5
+
struct Deserializer<'de> {
6
+
input: &'de [u8],
7
+
}
8
+
9
+
impl<'de> Deserializer<'de> {
10
+
fn from_bytes(b: &'de [u8]) -> Self {
11
+
Self { input: b }
12
+
}
13
+
14
+
fn unpack_dd(&mut self) -> Result<u32, Error> {
15
+
let (v, len) = super::packing::unpack_dd(self.input);
16
+
if len == 0 {
17
+
Err(Error::UnexpectedEof)
18
+
} else {
19
+
self.input = &self.input[len..];
20
+
Ok(v)
21
+
}
22
+
}
23
+
24
+
fn unpack_dq(&mut self) -> Result<u64, Error> {
25
+
let a = self.unpack_dd()? as u64;
26
+
let b = self.unpack_dd()? as u64;
27
+
Ok((a << 32) | b)
28
+
}
29
+
30
+
fn unpack_var_bytes(&mut self) -> Result<&'de [u8], Error> {
31
+
let bytes = self.unpack_dd()? as usize;
32
+
if bytes > self.input.len() {
33
+
return Err(Error::UnexpectedEof);
34
+
}
35
+
36
+
let payload = &self.input[..bytes];
37
+
self.input = &self.input[bytes..];
38
+
assert_eq!(payload.len(), bytes);
39
+
40
+
Ok(payload)
41
+
}
42
+
43
+
fn unpack_cstr(&mut self) -> Result<&'de str, Error> {
44
+
let len = self
45
+
.input
46
+
.iter()
47
+
.enumerate()
48
+
.find_map(|(idx, &v)| if v == 0 { Some(idx) } else { None });
49
+
let len = match len {
50
+
Some(v) => v,
51
+
None => return Err(Error::UnexpectedEof),
52
+
};
53
+
let res = match std::str::from_utf8(&self.input[..len]) {
54
+
Ok(v) => v,
55
+
Err(err) => {
56
+
return Err(err.into());
57
+
},
58
+
};
59
+
self.input = &self.input[len + 1..];
60
+
Ok(res)
61
+
}
62
+
63
+
fn take_byte(&mut self) -> Result<u8, Error> {
64
+
if self.input.is_empty() {
65
+
return Err(Error::UnexpectedEof);
66
+
}
67
+
68
+
let v = self.input[0];
69
+
self.input = &self.input[1..];
70
+
Ok(v)
71
+
}
72
+
}
73
+
74
+
/// Returns: a tuple containing the deserialized struct and the bytes used
75
+
pub fn from_slice<'a, T: Deserialize<'a>>(b: &'a [u8]) -> Result<(T, usize), Error> {
76
+
let mut de = Deserializer::from_bytes(b);
77
+
let v = T::deserialize(&mut de)?;
78
+
Ok((v, b.len() - de.input.len()))
79
+
}
80
+
81
+
impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
82
+
type Error = Error;
83
+
84
+
fn deserialize_any<V: Visitor<'de>>(self, _: V) -> Result<V::Value, Self::Error> {
85
+
unimplemented!()
86
+
}
87
+
88
+
fn deserialize_u8<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value, Self::Error> {
89
+
visitor.visit_u8(self.take_byte()?)
90
+
}
91
+
92
+
fn deserialize_u32<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value, Self::Error> {
93
+
visitor.visit_u32(self.unpack_dd()?)
94
+
}
95
+
96
+
fn deserialize_u64<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value, Self::Error> {
97
+
visitor.visit_u64(self.unpack_dq()?)
98
+
}
99
+
100
+
fn deserialize_seq<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value, Self::Error> {
101
+
let len = self.unpack_dd()?;
102
+
103
+
visitor.visit_seq(Access { len: len as usize, de: &mut *self })
104
+
}
105
+
106
+
fn deserialize_str<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value, Self::Error> {
107
+
visitor.visit_borrowed_str(self.unpack_cstr()?)
108
+
}
109
+
110
+
fn deserialize_bytes<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value, Self::Error> {
111
+
let v = self.unpack_var_bytes()?;
112
+
visitor.visit_borrowed_bytes(v)
113
+
}
114
+
115
+
fn deserialize_tuple<V: Visitor<'de>>(
116
+
self, len: usize, visitor: V,
117
+
) -> Result<V::Value, Self::Error> {
118
+
visitor.visit_seq(Access { len, de: &mut *self })
119
+
}
120
+
121
+
fn deserialize_tuple_struct<V: Visitor<'de>>(
122
+
self, _name: &'static str, len: usize, visitor: V,
123
+
) -> Result<V::Value, Self::Error> {
124
+
self.deserialize_tuple(len, visitor)
125
+
}
126
+
127
+
fn deserialize_struct<V: Visitor<'de>>(
128
+
self, name: &'static str, fields: &'static [&'static str], visitor: V,
129
+
) -> Result<V::Value, Self::Error> {
130
+
self.deserialize_tuple_struct(name, fields.len(), visitor)
131
+
}
132
+
133
+
serde::forward_to_deserialize_any! {
134
+
i8 i16 i32 i64 char u16 bool
135
+
f32 f64 string byte_buf option unit unit_struct newtype_struct map enum identifier ignored_any
136
+
}
137
+
}
138
+
139
+
struct Access<'a, 'de> {
140
+
de: &'a mut Deserializer<'de>,
141
+
len: usize,
142
+
}
143
+
144
+
impl<'de, 'a> SeqAccess<'a> for Access<'de, 'a> {
145
+
type Error = Error;
146
+
147
+
fn next_element_seed<T: DeserializeSeed<'a>>(
148
+
&mut self, seed: T,
149
+
) -> Result<Option<T::Value>, Self::Error> {
150
+
if self.len > 0 {
151
+
self.len -= 1;
152
+
153
+
let v = serde::de::DeserializeSeed::deserialize(seed, &mut *self.de)?;
154
+
Ok(Some(v))
155
+
} else {
156
+
Ok(None)
157
+
}
158
+
}
159
+
160
+
fn size_hint(&self) -> Option<usize> {
161
+
Some(self.len)
162
+
}
163
+
}
+156
-86
common/src/rpc/messages.rs
+156
-86
common/src/rpc/messages.rs
···
1
-
use serde::{Serialize, Deserialize};
2
-
use std::borrow::Cow;
3
-
4
-
#[derive(Deserialize, Serialize)]
5
-
pub struct RpcFail<'a> {
6
-
pub code: u32,
7
-
pub message: &'a str,
8
-
}
9
-
10
-
#[derive(Serialize, Deserialize)]
11
-
pub struct RpcNotify<'a> {
12
-
pub code: u32,
13
-
pub msg: &'a str,
14
-
}
15
-
16
-
#[derive(Serialize, Deserialize, Debug)]
17
-
pub struct Creds<'a> {
18
-
pub username: &'a str,
19
-
pub password: &'a str,
20
-
}
21
-
22
-
#[derive(Serialize, Deserialize)]
23
-
pub struct RpcHello<'a> {
24
-
pub protocol_version: u32,
25
-
pub license_data: &'a [u8],
26
-
pub lic_number: [u8; 6],
27
-
pub unk2: u32,
28
-
}
29
-
30
-
#[derive(Deserialize, Serialize, Clone)]
31
-
pub struct PullMetadataFunc<'a> {
32
-
pub unk0: u32,
33
-
pub mb_hash: &'a [u8],
34
-
}
35
-
36
-
#[derive(Deserialize, Serialize)]
37
-
pub struct PullMetadata<'a> {
38
-
pub unk0: u32,
39
-
pub unk1: Cow<'a, [u32]>,
40
-
41
-
#[serde(borrow)]
42
-
pub funcs: Cow<'a, [PullMetadataFunc<'a>]>,
43
-
}
44
-
45
-
#[derive(Deserialize, Serialize, Clone)]
46
-
pub struct PullMetadataResultFunc<'a> {
47
-
pub name: Cow<'a, str>,
48
-
pub len: u32,
49
-
pub mb_data: Cow<'a, [u8]>,
50
-
pub popularity: u32,
51
-
}
52
-
53
-
#[derive(Deserialize, Serialize)]
54
-
pub struct PullMetadataResult<'a> {
55
-
pub unk0: Cow<'a, [u32]>,
56
-
#[serde(borrow)]
57
-
pub funcs: Cow<'a, [PullMetadataResultFunc<'a>]>,
58
-
}
59
-
60
-
#[derive(Clone, Deserialize, Serialize)]
61
-
pub struct PushMetadataFunc<'a> {
62
-
pub name: &'a str,
63
-
pub func_len: u32,
64
-
pub func_data: &'a [u8],
65
-
66
-
// PullMetadata's fields (tuple 'unk2') are similar to these two
67
-
pub unk2: u32,
68
-
pub hash: &'a [u8],
69
-
}
70
-
71
-
#[derive(Deserialize, Serialize)]
72
-
pub struct PushMetadata<'a> {
73
-
pub unk0: u32,
74
-
pub idb_path: &'a str,
75
-
pub file_path: &'a str,
76
-
pub md5: [u8; 16],
77
-
pub hostname: &'a str,
78
-
pub funcs: Cow<'a, [PushMetadataFunc<'a>]>,
79
-
pub unk1: Cow<'a, [u64]>,
80
-
}
81
-
82
-
#[derive(Deserialize, Serialize)]
83
-
pub struct PushMetadataResult<'a> {
84
-
// array of 0=exists, 1=NEW
85
-
pub status: Cow<'a, [u32]>,
86
-
}
1
+
use serde::{Deserialize, Serialize};
2
+
use std::borrow::Cow;
3
+
4
+
#[derive(Deserialize, Serialize)]
5
+
pub struct RpcFail<'a> {
6
+
pub code: u32,
7
+
pub message: &'a str,
8
+
}
9
+
10
+
#[derive(Serialize, Deserialize)]
11
+
pub struct RpcNotify<'a> {
12
+
pub code: u32,
13
+
pub msg: &'a str,
14
+
}
15
+
16
+
#[derive(Serialize, Deserialize, Debug)]
17
+
pub struct Creds<'a> {
18
+
pub username: &'a str,
19
+
pub password: &'a str,
20
+
}
21
+
22
+
#[derive(Serialize, Deserialize)]
23
+
pub struct RpcHello<'a> {
24
+
pub protocol_version: u32,
25
+
pub license_data: &'a [u8],
26
+
pub lic_number: [u8; 6],
27
+
pub unk2: u32,
28
+
}
29
+
30
+
#[derive(Debug, Deserialize, Serialize, Clone)]
31
+
pub struct PullMetadataFunc<'a> {
32
+
pub unk0: u32,
33
+
pub mb_hash: &'a [u8],
34
+
}
35
+
36
+
#[derive(Deserialize, Serialize)]
37
+
pub struct PullMetadata<'a> {
38
+
pub unk0: u32,
39
+
pub unk1: Cow<'a, [u32]>,
40
+
41
+
#[serde(borrow)]
42
+
pub funcs: Cow<'a, [PullMetadataFunc<'a>]>,
43
+
}
44
+
45
+
#[derive(Deserialize, Serialize, Clone)]
46
+
pub struct PullMetadataResultFunc<'a> {
47
+
pub name: Cow<'a, str>,
48
+
pub len: u32,
49
+
pub mb_data: Cow<'a, [u8]>,
50
+
pub popularity: u32,
51
+
}
52
+
53
+
#[derive(Deserialize, Serialize)]
54
+
pub struct PullMetadataResult<'a> {
55
+
pub unk0: Cow<'a, [u32]>,
56
+
#[serde(borrow)]
57
+
pub funcs: Cow<'a, [PullMetadataResultFunc<'a>]>,
58
+
}
59
+
60
+
#[derive(Clone, Deserialize, Serialize)]
61
+
pub struct PushMetadataFunc<'a> {
62
+
pub name: &'a str,
63
+
pub func_len: u32,
64
+
pub func_data: &'a [u8],
65
+
66
+
// PullMetadata's fields (tuple 'unk2') are similar to these two
67
+
pub unk2: u32,
68
+
pub hash: &'a [u8],
69
+
}
70
+
71
+
#[derive(Deserialize, Serialize)]
72
+
pub struct PushMetadata<'a> {
73
+
pub unk0: u32,
74
+
pub idb_path: &'a str,
75
+
pub file_path: &'a str,
76
+
pub md5: [u8; 16],
77
+
pub hostname: &'a str,
78
+
pub funcs: Cow<'a, [PushMetadataFunc<'a>]>,
79
+
pub unk1: Cow<'a, [u64]>,
80
+
}
81
+
82
+
#[derive(Deserialize, Serialize)]
83
+
pub struct PushMetadataResult<'a> {
84
+
// array of 0=exists, 1=NEW
85
+
pub status: Cow<'a, [u32]>,
86
+
}
87
+
88
+
#[derive(Debug, Deserialize, Serialize)]
89
+
pub struct DelHistory<'a> {
90
+
pub unk0: u32, // =0x08
91
+
pub unk1: Cow<'a, [Cow<'a, str>]>,
92
+
pub unk2: Cow<'a, [[u64; 2]]>,
93
+
pub unk3: Cow<'a, [[u64; 2]]>,
94
+
pub unk4: Cow<'a, [Cow<'a, str>]>,
95
+
pub unk5: Cow<'a, [Cow<'a, str>]>,
96
+
pub unk6: Cow<'a, [Cow<'a, str>]>,
97
+
pub unk7: Cow<'a, [Cow<'a, str>]>,
98
+
pub unk8: Cow<'a, [Cow<'a, [u8; 16]>]>,
99
+
pub funcs: Cow<'a, [Cow<'a, [u8; 16]>]>,
100
+
pub unk10: Cow<'a, [[u64; 2]]>,
101
+
pub unk11: u64,
102
+
}
103
+
104
+
#[derive(Deserialize, Serialize)]
105
+
pub struct DelHistoryResult {
106
+
pub deleted_mds: u32,
107
+
}
108
+
109
+
#[derive(Debug, Deserialize, Serialize, Default)]
110
+
pub struct LicenseInfo<'a> {
111
+
pub id: Cow<'a, str>,
112
+
pub name: Cow<'a, str>,
113
+
pub email: Cow<'a, str>,
114
+
}
115
+
116
+
#[derive(Debug, Deserialize, Serialize, Default)]
117
+
pub struct HelloResult<'a> {
118
+
pub license_info: LicenseInfo<'a>,
119
+
pub username: Cow<'a, str>,
120
+
pub karma: u32,
121
+
pub last_active: u64,
122
+
pub features: u32,
123
+
}
124
+
125
+
#[derive(Debug, Deserialize, Serialize)]
126
+
pub struct GetFuncHistories<'a> {
127
+
#[serde(borrow)]
128
+
pub funcs: Cow<'a, [PullMetadataFunc<'a>]>,
129
+
pub unk0: u32,
130
+
}
131
+
132
+
#[derive(Debug, Deserialize, Serialize, Clone)]
133
+
pub struct FunctionHistory<'a> {
134
+
pub unk0: u64,
135
+
pub unk1: u64,
136
+
pub name: Cow<'a, str>,
137
+
pub metadata: Cow<'a, [u8]>,
138
+
pub timestamp: u64,
139
+
pub author_idx: u32,
140
+
pub idb_path_idx: u32,
141
+
}
142
+
143
+
#[derive(Debug, Deserialize, Serialize, Clone)]
144
+
pub struct FunctionHistories<'a> {
145
+
#[serde(borrow)]
146
+
pub log: Cow<'a, [FunctionHistory<'a>]>,
147
+
}
148
+
149
+
#[derive(Debug, Deserialize, Serialize)]
150
+
pub struct GetFuncHistoriesResult<'a> {
151
+
pub status: Cow<'a, [u32]>,
152
+
#[serde(borrow)]
153
+
pub funcs: Cow<'a, [FunctionHistories<'a>]>,
154
+
pub users: Cow<'a, [Cow<'a, str>]>,
155
+
pub dbs: Cow<'a, [Cow<'a, str>]>,
156
+
}
+257
-228
common/src/rpc/mod.rs
+257
-228
common/src/rpc/mod.rs
···
1
-
use tokio::io::{AsyncWriteExt, AsyncWrite, AsyncRead, AsyncReadExt};
2
-
use log::*;
3
-
mod ser;
4
-
pub(crate) mod de;
5
-
mod messages;
6
-
mod packing;
7
-
use serde::Serializer;
8
-
9
-
pub use messages::*;
10
-
11
-
#[derive(Debug)]
12
-
pub enum Error {
13
-
UnexpectedEof,
14
-
Utf8Error(std::str::Utf8Error),
15
-
IOError(std::io::Error),
16
-
Serde(String),
17
-
DbError(tokio_postgres::Error),
18
-
InvalidData,
19
-
OutOfMemory,
20
-
Todo,
21
-
Timeout,
22
-
Eof,
23
-
}
24
-
25
-
impl std::fmt::Display for Error {
26
-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27
-
std::fmt::Debug::fmt(self, f)
28
-
}
29
-
}
30
-
31
-
impl std::error::Error for Error {}
32
-
impl serde::ser::Error for Error {
33
-
fn custom<T: std::fmt::Display>(msg: T) -> Self {
34
-
Error::Serde(msg.to_string())
35
-
}
36
-
}
37
-
impl serde::de::Error for Error {
38
-
fn custom<T: std::fmt::Display>(msg: T) -> Self {
39
-
Error::Serde(msg.to_string())
40
-
}
41
-
}
42
-
impl From<std::io::Error> for Error {
43
-
fn from(v: std::io::Error) -> Self {
44
-
Error::IOError(v)
45
-
}
46
-
}
47
-
impl From<std::str::Utf8Error> for Error {
48
-
fn from(v: std::str::Utf8Error) -> Self {
49
-
Error::Utf8Error(v)
50
-
}
51
-
}
52
-
impl From<tokio_postgres::Error> for Error {
53
-
fn from(v: tokio_postgres::Error) -> Self {
54
-
Error::DbError(v)
55
-
}
56
-
}
57
-
impl From<std::collections::TryReserveError> for Error {
58
-
fn from(v: std::collections::TryReserveError) -> Self {
59
-
error!("failed to allocate {} bytes", v);
60
-
Error::OutOfMemory
61
-
}
62
-
}
63
-
64
-
fn get_code_maxlen(code: u8) -> usize {
65
-
match code {
66
-
0x0e => 50 * 1024 * 1024, // PullMD: 50 MiB
67
-
0x10 => 200 * 1024 * 1024, // PushMD: 200 MiB
68
-
_ => 1024 * 50, // otherwise 50K
69
-
}
70
-
}
71
-
72
-
pub async fn read_packet<R: AsyncRead + Unpin>(mut reader: R) -> Result<Vec<u8>, Error> {
73
-
let mut head = [0u8; 5];
74
-
match reader.read_exact(&mut head).await {
75
-
Ok(_) => {},
76
-
Err(e) if e.kind() == std::io::ErrorKind::UnexpectedEof => return Err(Error::Eof), // client decided to disconnect...
77
-
Err(e) => return Err(e.into()),
78
-
}
79
-
let code = head[4];
80
-
let mut buf_len = [0u8; 4];
81
-
buf_len.copy_from_slice(&head[..4]);
82
-
83
-
let buf_len = u32::from_be_bytes(buf_len) as usize;
84
-
if buf_len < 4 {
85
-
return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "payload size is too small").into());
86
-
}
87
-
88
-
let max_len = get_code_maxlen(code);
89
-
90
-
if buf_len > max_len {
91
-
info!("maxium size exceeded: code={}: max={}; req={}", code, max_len, buf_len);
92
-
return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "request length exceeded maximum limit").into());
93
-
}
94
-
95
-
// the additional byte is for the RPC code
96
-
trace!("expecting {} bytes...", buf_len);
97
-
let buf_len = buf_len + 1;
98
-
99
-
let mut data = Vec::new();
100
-
data.try_reserve_exact(buf_len)?;
101
-
data.resize(buf_len, 0);
102
-
data[0] = code;
103
-
reader.read_exact(&mut data[1..]).await?;
104
-
105
-
Ok(data)
106
-
}
107
-
108
-
async fn write_packet<W: AsyncWrite + Unpin>(mut w: W, data: &[u8]) -> Result<(), std::io::Error> {
109
-
let buf_len: u32 = (data.len() - 1) as u32;
110
-
let buf_len = buf_len.to_be_bytes();
111
-
w.write_all(&buf_len).await?;
112
-
w.write_all(data).await?;
113
-
Ok(())
114
-
}
115
-
116
-
pub enum RpcMessage<'a> {
117
-
Ok(()),
118
-
Fail(RpcFail<'a>),
119
-
Notify(RpcNotify<'a>),
120
-
Hello(RpcHello<'a>, Option<Creds<'a>>),
121
-
PullMetadata(PullMetadata<'a>),
122
-
PullMetadataResult(PullMetadataResult<'a>),
123
-
PushMetadata(PushMetadata<'a>),
124
-
PushMetadataResult(PushMetadataResult<'a>),
125
-
}
126
-
127
-
impl<'a> serde::Serialize for RpcMessage<'a> {
128
-
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
129
-
use serde::ser::SerializeTuple;
130
-
131
-
let code = self.get_code();
132
-
let mut tuple = serializer.serialize_tuple(2)?;
133
-
134
-
// u8 is pushed without further encoding...
135
-
tuple.serialize_element(&code)?;
136
-
137
-
match self {
138
-
RpcMessage::Ok(msg) => tuple.serialize_element(msg)?,
139
-
RpcMessage::Fail(msg) => tuple.serialize_element(msg)?,
140
-
RpcMessage::Notify(msg) => tuple.serialize_element(msg)?,
141
-
RpcMessage::Hello(msg, _) => tuple.serialize_element(msg)?,
142
-
RpcMessage::PullMetadata(msg) => tuple.serialize_element(msg)?,
143
-
RpcMessage::PullMetadataResult(msg) => tuple.serialize_element(msg)?,
144
-
RpcMessage::PushMetadata(msg) => tuple.serialize_element(msg)?,
145
-
RpcMessage::PushMetadataResult(msg) => tuple.serialize_element(msg)?,
146
-
}
147
-
148
-
tuple.end()
149
-
}
150
-
}
151
-
152
-
impl<'a> RpcMessage<'a> {
153
-
fn deserialize_check<T: serde::Deserialize<'a>>(payload: &'a [u8]) -> Result<T, Error> {
154
-
let v = de::from_slice(payload)?;
155
-
if v.1 != payload.len() {
156
-
let bytes_remaining = crate::make_pretty_hex(&payload[v.1..]);
157
-
trace!("{} remaining bytes after deserializing {}\n{bytes_remaining}", payload.len() - v.1, std::any::type_name::<T>());
158
-
}
159
-
Ok(v.0)
160
-
}
161
-
162
-
pub fn deserialize(payload: &'a [u8]) -> Result<RpcMessage<'a>, Error> {
163
-
let msg_type = payload[0];
164
-
let payload = &payload[1..];
165
-
166
-
let res = match msg_type {
167
-
0x0a => {
168
-
if !payload.is_empty() {
169
-
trace!("Ok message with additional data: {} bytes: {payload:02x?}", payload.len());
170
-
}
171
-
RpcMessage::Ok(())
172
-
},
173
-
0x0b => RpcMessage::Fail(Self::deserialize_check(payload)?),
174
-
0x0c => RpcMessage::Notify(Self::deserialize_check(payload)?),
175
-
0x0d => {
176
-
let (hello, consumed) = de::from_slice::<messages::RpcHello>(payload)?;
177
-
let creds = if payload.len() > consumed && hello.protocol_version > 2 {
178
-
let payload = &payload[consumed..];
179
-
let (creds, consumed) = de::from_slice::<Creds>(payload)?;
180
-
if payload.len() != consumed {
181
-
trace!("bytes remaining after HelloV2: {payload:02x?}");
182
-
}
183
-
Some(creds)
184
-
} else {
185
-
if hello.protocol_version > 2 || payload.len() != consumed {
186
-
trace!("Unexpected Hello msg: {payload:02x?}");
187
-
}
188
-
None
189
-
};
190
-
RpcMessage::Hello(hello, creds)
191
-
},
192
-
0x0e => RpcMessage::PullMetadata(Self::deserialize_check(payload)?),
193
-
0x0f => RpcMessage::PullMetadataResult(Self::deserialize_check(payload)?),
194
-
0x10 => RpcMessage::PushMetadata(Self::deserialize_check(payload)?),
195
-
0x11 => RpcMessage::PushMetadataResult(Self::deserialize_check(payload)?),
196
-
_ => {
197
-
trace!("got invalid message type '{:02x}'", msg_type);
198
-
return Err(Error::InvalidData);
199
-
},
200
-
};
201
-
202
-
Ok(res)
203
-
}
204
-
205
-
pub async fn async_write<W: AsyncWrite + Unpin>(&self, w: W) -> Result<(), Error> {
206
-
let mut output = Vec::with_capacity(32);
207
-
ser::to_writer(self, &mut output)?;
208
-
209
-
write_packet(w, &output).await?;
210
-
211
-
Ok(())
212
-
}
213
-
214
-
fn get_code(&self) -> u8 {
215
-
use RpcMessage::*;
216
-
217
-
match self {
218
-
Ok(_) => 0x0a,
219
-
Fail(_) => 0x0b,
220
-
Notify(_) => 0x0c,
221
-
Hello(..) => 0x0d,
222
-
PullMetadata(_) => 0x0e,
223
-
PullMetadataResult(_) => 0x0f,
224
-
PushMetadata(_) => 0x10,
225
-
PushMetadataResult(_) => 0x11,
226
-
}
227
-
}
228
-
}
1
+
use log::*;
2
+
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
3
+
pub(crate) mod de;
4
+
mod messages;
5
+
mod packing;
6
+
mod ser;
7
+
use serde::Serializer;
8
+
9
+
pub use messages::*;
10
+
11
+
#[derive(Debug)]
12
+
pub enum Error {
13
+
UnexpectedEof,
14
+
Utf8Error(std::str::Utf8Error),
15
+
IOError(std::io::Error),
16
+
Serde(String),
17
+
InvalidData,
18
+
OutOfMemory,
19
+
Todo,
20
+
Timeout,
21
+
Eof,
22
+
}
23
+
24
+
impl std::fmt::Display for Error {
25
+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26
+
std::fmt::Debug::fmt(self, f)
27
+
}
28
+
}
29
+
30
+
impl std::error::Error for Error {}
31
+
impl serde::ser::Error for Error {
32
+
fn custom<T: std::fmt::Display>(msg: T) -> Self {
33
+
Error::Serde(msg.to_string())
34
+
}
35
+
}
36
+
impl serde::de::Error for Error {
37
+
fn custom<T: std::fmt::Display>(msg: T) -> Self {
38
+
Error::Serde(msg.to_string())
39
+
}
40
+
}
41
+
impl From<std::io::Error> for Error {
42
+
fn from(v: std::io::Error) -> Self {
43
+
Error::IOError(v)
44
+
}
45
+
}
46
+
impl From<std::str::Utf8Error> for Error {
47
+
fn from(v: std::str::Utf8Error) -> Self {
48
+
Error::Utf8Error(v)
49
+
}
50
+
}
51
+
impl From<std::collections::TryReserveError> for Error {
52
+
fn from(v: std::collections::TryReserveError) -> Self {
53
+
error!("failed to allocate {} bytes", v);
54
+
Error::OutOfMemory
55
+
}
56
+
}
57
+
58
+
fn get_code_maxlen(code: u8) -> usize {
59
+
match code {
60
+
0x0e => 50 * 1024 * 1024, // PullMD: 50 MiB
61
+
0x10 => 200 * 1024 * 1024, // PushMD: 200 MiB
62
+
_ => 1024 * 50, // otherwise 50K
63
+
}
64
+
}
65
+
66
+
pub async fn read_packet<R: AsyncRead + Unpin>(mut reader: R) -> Result<Vec<u8>, Error> {
67
+
let mut head = [0u8; 5];
68
+
match reader.read_exact(&mut head).await {
69
+
Ok(_) => {},
70
+
Err(e) if e.kind() == std::io::ErrorKind::UnexpectedEof => return Err(Error::Eof), // client decided to disconnect...
71
+
Err(e) => return Err(e.into()),
72
+
}
73
+
let code = head[4];
74
+
let mut buf_len = [0u8; 4];
75
+
buf_len.copy_from_slice(&head[..4]);
76
+
77
+
let buf_len = u32::from_be_bytes(buf_len) as usize;
78
+
if buf_len < 4 {
79
+
return Err(std::io::Error::new(
80
+
std::io::ErrorKind::InvalidData,
81
+
"payload size is too small",
82
+
)
83
+
.into());
84
+
}
85
+
86
+
let max_len = get_code_maxlen(code);
87
+
88
+
if buf_len > max_len {
89
+
info!("maxium size exceeded: code={}: max={}; req={}", code, max_len, buf_len);
90
+
return Err(std::io::Error::new(
91
+
std::io::ErrorKind::InvalidData,
92
+
"request length exceeded maximum limit",
93
+
)
94
+
.into());
95
+
}
96
+
97
+
// the additional byte is for the RPC code
98
+
trace!("expecting {} bytes...", buf_len);
99
+
let buf_len = buf_len + 1;
100
+
101
+
let mut data = Vec::new();
102
+
data.try_reserve_exact(buf_len)?;
103
+
data.resize(buf_len, 0);
104
+
data[0] = code;
105
+
reader.read_exact(&mut data[1..]).await?;
106
+
107
+
Ok(data)
108
+
}
109
+
110
+
async fn write_packet<W: AsyncWrite + Unpin>(mut w: W, data: &[u8]) -> Result<(), std::io::Error> {
111
+
let buf_len: u32 = (data.len() - 1) as u32;
112
+
let buf_len = buf_len.to_be_bytes();
113
+
w.write_all(&buf_len).await?;
114
+
w.write_all(data).await?;
115
+
Ok(())
116
+
}
117
+
118
+
pub enum RpcMessage<'a> {
119
+
Ok(()),
120
+
Fail(RpcFail<'a>),
121
+
Notify(RpcNotify<'a>),
122
+
Hello(RpcHello<'a>, Option<Creds<'a>>),
123
+
PullMetadata(PullMetadata<'a>),
124
+
PullMetadataResult(PullMetadataResult<'a>),
125
+
PushMetadata(PushMetadata<'a>),
126
+
PushMetadataResult(PushMetadataResult<'a>),
127
+
DelHistory(DelHistory<'a>),
128
+
DelHistoryResult(DelHistoryResult),
129
+
GetFuncHistories(GetFuncHistories<'a>),
130
+
GetFuncHistoriesResult(GetFuncHistoriesResult<'a>),
131
+
HelloResult(HelloResult<'a>),
132
+
}
133
+
134
+
impl<'a> serde::Serialize for RpcMessage<'a> {
135
+
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
136
+
use serde::ser::SerializeTuple;
137
+
138
+
let code = self.get_code();
139
+
let mut tuple = serializer.serialize_tuple(2)?;
140
+
141
+
// u8 is pushed without further encoding...
142
+
tuple.serialize_element(&code)?;
143
+
144
+
match self {
145
+
RpcMessage::Ok(msg) => tuple.serialize_element(msg)?,
146
+
RpcMessage::Fail(msg) => tuple.serialize_element(msg)?,
147
+
RpcMessage::Notify(msg) => tuple.serialize_element(msg)?,
148
+
RpcMessage::Hello(msg, _) => tuple.serialize_element(msg)?,
149
+
RpcMessage::PullMetadata(msg) => tuple.serialize_element(msg)?,
150
+
RpcMessage::PullMetadataResult(msg) => tuple.serialize_element(msg)?,
151
+
RpcMessage::PushMetadata(msg) => tuple.serialize_element(msg)?,
152
+
RpcMessage::PushMetadataResult(msg) => tuple.serialize_element(msg)?,
153
+
RpcMessage::DelHistory(msg) => tuple.serialize_element(msg)?,
154
+
RpcMessage::DelHistoryResult(msg) => tuple.serialize_element(msg)?,
155
+
RpcMessage::GetFuncHistories(msg) => tuple.serialize_element(msg)?,
156
+
RpcMessage::GetFuncHistoriesResult(msg) => tuple.serialize_element(msg)?,
157
+
RpcMessage::HelloResult(msg) => tuple.serialize_element(msg)?,
158
+
}
159
+
160
+
tuple.end()
161
+
}
162
+
}
163
+
164
+
impl<'a> RpcMessage<'a> {
165
+
fn deserialize_check<T: serde::Deserialize<'a>>(payload: &'a [u8]) -> Result<T, Error> {
166
+
let v = de::from_slice(payload)?;
167
+
if v.1 != payload.len() {
168
+
let bytes_remaining = crate::make_pretty_hex(&payload[v.1..]);
169
+
trace!(
170
+
"{} remaining bytes after deserializing {}\n{bytes_remaining}",
171
+
payload.len() - v.1,
172
+
std::any::type_name::<T>()
173
+
);
174
+
}
175
+
Ok(v.0)
176
+
}
177
+
178
+
pub fn deserialize(payload: &'a [u8]) -> Result<RpcMessage<'a>, Error> {
179
+
let msg_type = payload[0];
180
+
let payload = &payload[1..];
181
+
182
+
let res = match msg_type {
183
+
0x0a => {
184
+
if !payload.is_empty() {
185
+
trace!(
186
+
"Ok message with additional data: {} bytes: {payload:02x?}",
187
+
payload.len()
188
+
);
189
+
}
190
+
RpcMessage::Ok(())
191
+
},
192
+
0x0b => RpcMessage::Fail(Self::deserialize_check(payload)?),
193
+
0x0c => RpcMessage::Notify(Self::deserialize_check(payload)?),
194
+
0x0d => {
195
+
let (hello, consumed) = de::from_slice::<messages::RpcHello>(payload)?;
196
+
let creds = if payload.len() > consumed && hello.protocol_version > 2 {
197
+
let payload = &payload[consumed..];
198
+
let (creds, consumed) = de::from_slice::<Creds>(payload)?;
199
+
if payload.len() != consumed {
200
+
trace!("bytes remaining after HelloV2: {payload:02x?}");
201
+
}
202
+
Some(creds)
203
+
} else {
204
+
if hello.protocol_version > 2 || payload.len() != consumed {
205
+
trace!("Unexpected Hello msg: {payload:02x?}");
206
+
}
207
+
None
208
+
};
209
+
RpcMessage::Hello(hello, creds)
210
+
},
211
+
0x0e => RpcMessage::PullMetadata(Self::deserialize_check(payload)?),
212
+
0x0f => RpcMessage::PullMetadataResult(Self::deserialize_check(payload)?),
213
+
0x10 => RpcMessage::PushMetadata(Self::deserialize_check(payload)?),
214
+
0x11 => RpcMessage::PushMetadataResult(Self::deserialize_check(payload)?),
215
+
0x18 => RpcMessage::DelHistory(Self::deserialize_check(payload)?),
216
+
0x19 => RpcMessage::DelHistoryResult(Self::deserialize_check(payload)?),
217
+
0x2f => RpcMessage::GetFuncHistories(Self::deserialize_check(payload)?),
218
+
0x30 => RpcMessage::GetFuncHistoriesResult(Self::deserialize_check(payload)?),
219
+
0x31 => RpcMessage::HelloResult(Self::deserialize_check(payload)?),
220
+
_ => {
221
+
trace!("got invalid message type '{:02x}'", msg_type);
222
+
return Err(Error::InvalidData);
223
+
},
224
+
};
225
+
226
+
Ok(res)
227
+
}
228
+
229
+
pub async fn async_write<W: AsyncWrite + Unpin>(&self, w: W) -> Result<(), Error> {
230
+
let mut output = Vec::with_capacity(32);
231
+
ser::to_writer(self, &mut output)?;
232
+
233
+
write_packet(w, &output).await?;
234
+
235
+
Ok(())
236
+
}
237
+
238
+
fn get_code(&self) -> u8 {
239
+
use RpcMessage::*;
240
+
241
+
match self {
242
+
Ok(_) => 0x0a,
243
+
Fail(_) => 0x0b,
244
+
Notify(_) => 0x0c,
245
+
Hello(..) => 0x0d,
246
+
PullMetadata(_) => 0x0e,
247
+
PullMetadataResult(_) => 0x0f,
248
+
PushMetadata(_) => 0x10,
249
+
PushMetadataResult(_) => 0x11,
250
+
DelHistory(_) => 0x18,
251
+
DelHistoryResult(_) => 0x19,
252
+
GetFuncHistories(_) => 0x2f,
253
+
GetFuncHistoriesResult(_) => 0x30,
254
+
HelloResult(_) => 0x31,
255
+
}
256
+
}
257
+
}
+111
-104
common/src/rpc/packing.rs
+111
-104
common/src/rpc/packing.rs
···
1
-
/// packs a dd into `buf` returning amout of bytes written.
2
-
/// Returns 0 if buffer is too small
3
-
pub fn pack_dd(v: u32, buf: &mut [u8]) -> usize {
4
-
let bytes = v.to_le_bytes();
5
-
match v {
6
-
0..=0x7f => { // 0..0XXXXXXX (7 bits)
7
-
if buf.is_empty() {
8
-
return 0;
9
-
}
10
-
buf[0] = bytes[0];
11
-
1
12
-
},
13
-
0x80..=0x3fff => { // 10AAAAAA..BBBBBBBB (14 bits)
14
-
if buf.len() < 2 {
15
-
return 0;
16
-
}
17
-
buf[0] = 0x80 | bytes[1];
18
-
buf[1] = bytes[0];
19
-
2
20
-
},
21
-
0x4000..=0x1fffff => { // 11000000_AAAAAAAA_BBBBBBBB_CCCCCCCC (24 bits)
22
-
if buf.len() < 3 {
23
-
return 0;
24
-
}
25
-
buf[0] = 0xc0;
26
-
buf[1] = bytes[2];
27
-
buf[2] = bytes[1];
28
-
buf[3] = bytes[0];
29
-
4
30
-
},
31
-
0x200000..=u32::MAX => { // 11111111_AAAAAAAA_BBBBBBBB_CCCCCCCC_DDDDDDDD (32 bits)
32
-
if buf.len() < 5 {
33
-
return 0;
34
-
}
35
-
buf[0] = 0xff;
36
-
buf[1] = bytes[3];
37
-
buf[2] = bytes[2];
38
-
buf[3] = bytes[1];
39
-
buf[4] = bytes[0];
40
-
5
41
-
}
42
-
}
43
-
}
44
-
45
-
/// unpacks a dd from `buf`, returning the amount (value, byte consumed)
46
-
pub fn unpack_dd(buf: &[u8]) -> (u32, usize) {
47
-
if buf.is_empty() {
48
-
return (0, 0);
49
-
}
50
-
51
-
let msb = buf[0];
52
-
let mut val = [0u8; 4];
53
-
54
-
if msb & 0x80 == 0 { // 0......
55
-
val[0] = msb;
56
-
return (u32::from_le_bytes(val), 1);
57
-
}
58
-
if msb & 0x40 == 0 { // 10....../0x80
59
-
if buf.len() < 2 {
60
-
return (0, 0);
61
-
}
62
-
val[1] = msb & 0x3f;
63
-
val[0] = buf[1];
64
-
return (u32::from_le_bytes(val), 2);
65
-
}
66
-
if msb & 0x20 == 0 { // 110...../0xC0
67
-
if buf.len() < 4 {
68
-
return (0, 0);
69
-
}
70
-
val[3] = msb & 0x1f;
71
-
val[2] = buf[1];
72
-
val[1] = buf[2];
73
-
val[0] = buf[3];
74
-
return (u32::from_le_bytes(val), 4);
75
-
}
76
-
77
-
if buf.len() < 5 {
78
-
return (0, 0);
79
-
}
80
-
81
-
val[3] = buf[1];
82
-
val[2] = buf[2];
83
-
val[1] = buf[3];
84
-
val[0] = buf[4];
85
-
86
-
(u32::from_le_bytes(val), 5)
87
-
}
88
-
89
-
#[cfg(test)]
90
-
mod tests {
91
-
#[test]
92
-
#[ignore = "this is a very time consuming test, it should be run in release/profiling mode"]
93
-
fn pack_all_nums() {
94
-
for num in 0..=u32::MAX {
95
-
let mut buf = [0u8; 5];
96
-
let rlen = super::pack_dd(num, &mut buf);
97
-
assert!(rlen > 0);
98
-
99
-
let unpacked = super::unpack_dd(&buf[..rlen]);
100
-
assert_eq!(unpacked.1, rlen, "bad unpack size");
101
-
assert_eq!(unpacked.0, num, "values don't match");
102
-
}
103
-
}
104
-
}
1
+
/// packs a dd into `buf` returning amout of bytes written.
2
+
/// Returns 0 if buffer is too small
3
+
pub fn pack_dd(v: u32, buf: &mut [u8]) -> usize {
4
+
let bytes = v.to_le_bytes();
5
+
match v {
6
+
0..=0x7f => {
7
+
// 0..0XXXXXXX (7 bits)
8
+
if buf.is_empty() {
9
+
return 0;
10
+
}
11
+
buf[0] = bytes[0];
12
+
1
13
+
},
14
+
0x80..=0x3fff => {
15
+
// 10AAAAAA..BBBBBBBB (14 bits)
16
+
if buf.len() < 2 {
17
+
return 0;
18
+
}
19
+
buf[0] = 0x80 | bytes[1];
20
+
buf[1] = bytes[0];
21
+
2
22
+
},
23
+
0x4000..=0x1fffff => {
24
+
// 11000000_AAAAAAAA_BBBBBBBB_CCCCCCCC (24 bits)
25
+
if buf.len() < 3 {
26
+
return 0;
27
+
}
28
+
buf[0] = 0xc0;
29
+
buf[1] = bytes[2];
30
+
buf[2] = bytes[1];
31
+
buf[3] = bytes[0];
32
+
4
33
+
},
34
+
0x200000..=u32::MAX => {
35
+
// 11111111_AAAAAAAA_BBBBBBBB_CCCCCCCC_DDDDDDDD (32 bits)
36
+
if buf.len() < 5 {
37
+
return 0;
38
+
}
39
+
buf[0] = 0xff;
40
+
buf[1] = bytes[3];
41
+
buf[2] = bytes[2];
42
+
buf[3] = bytes[1];
43
+
buf[4] = bytes[0];
44
+
5
45
+
},
46
+
}
47
+
}
48
+
49
+
/// unpacks a dd from `buf`, returning the amount (value, byte consumed)
50
+
pub fn unpack_dd(buf: &[u8]) -> (u32, usize) {
51
+
if buf.is_empty() {
52
+
return (0, 0);
53
+
}
54
+
55
+
let msb = buf[0];
56
+
let mut val = [0u8; 4];
57
+
58
+
if msb & 0x80 == 0 {
59
+
// 0......
60
+
val[0] = msb;
61
+
return (u32::from_le_bytes(val), 1);
62
+
}
63
+
if msb & 0x40 == 0 {
64
+
// 10....../0x80
65
+
if buf.len() < 2 {
66
+
return (0, 0);
67
+
}
68
+
val[1] = msb & 0x3f;
69
+
val[0] = buf[1];
70
+
return (u32::from_le_bytes(val), 2);
71
+
}
72
+
if msb & 0x20 == 0 {
73
+
// 110...../0xC0
74
+
if buf.len() < 4 {
75
+
return (0, 0);
76
+
}
77
+
val[3] = msb & 0x1f;
78
+
val[2] = buf[1];
79
+
val[1] = buf[2];
80
+
val[0] = buf[3];
81
+
return (u32::from_le_bytes(val), 4);
82
+
}
83
+
84
+
if buf.len() < 5 {
85
+
return (0, 0);
86
+
}
87
+
88
+
val[3] = buf[1];
89
+
val[2] = buf[2];
90
+
val[1] = buf[3];
91
+
val[0] = buf[4];
92
+
93
+
(u32::from_le_bytes(val), 5)
94
+
}
95
+
96
+
#[cfg(test)]
97
+
mod tests {
98
+
#[test]
99
+
#[ignore = "this is a very time consuming test, it should be run in release/profiling mode"]
100
+
fn pack_all_nums() {
101
+
for num in 0..=u32::MAX {
102
+
let mut buf = [0u8; 5];
103
+
let rlen = super::pack_dd(num, &mut buf);
104
+
assert!(rlen > 0);
105
+
106
+
let unpacked = super::unpack_dd(&buf[..rlen]);
107
+
assert_eq!(unpacked.1, rlen, "bad unpack size");
108
+
assert_eq!(unpacked.0, num, "values don't match");
109
+
}
110
+
}
111
+
}
+255
-241
common/src/rpc/ser.rs
+255
-241
common/src/rpc/ser.rs
···
1
-
use std::io::Write;
2
-
use serde::{ser, Serialize, ser::Impossible};
3
-
use super::Error;
4
-
5
-
struct Serializer<W: Write> {
6
-
output: W,
7
-
}
8
-
9
-
pub fn to_writer<T: Serialize, W: Write>(v: &T, w: W) -> Result<(), Error> {
10
-
let mut serializer = Serializer {
11
-
output: w,
12
-
};
13
-
v.serialize(&mut serializer)?;
14
-
Ok(())
15
-
}
16
-
17
-
#[allow(dead_code)]
18
-
pub fn to_vec<T: Serialize>(v: &T) -> Result<Vec<u8>, Error> {
19
-
let mut buf = vec![];
20
-
to_writer(v, &mut buf)?;
21
-
Ok(buf)
22
-
}
23
-
24
-
impl<W: Write> Serializer<W> {
25
-
fn pack_dd(&mut self, num: u32) -> Result<(), Error> {
26
-
let mut buf = [0u8; 5];
27
-
let bytes = super::packing::pack_dd(num, &mut buf);
28
-
self.output.write_all(&buf[..bytes])?;
29
-
Ok(())
30
-
}
31
-
32
-
fn pack_str(&mut self, s: &str) -> Result<(), Error> {
33
-
self.output.write_all(s.as_bytes())?;
34
-
self.output.write_all(&[0])?;
35
-
Ok(())
36
-
}
37
-
38
-
fn pack_bytes(&mut self, b: &[u8]) -> Result<(), Error> {
39
-
self.pack_dd(b.len() as u32)?;
40
-
self.output.write_all(b)?;
41
-
Ok(())
42
-
}
43
-
}
44
-
45
-
impl<'a, W: Write> ser::Serializer for &'a mut Serializer<W> {
46
-
type Ok = ();
47
-
type Error = Error;
48
-
49
-
type SerializeSeq = Self;
50
-
type SerializeTuple = Self;
51
-
type SerializeTupleStruct = Impossible<(), Self::Error>;
52
-
type SerializeTupleVariant = Impossible<(), Self::Error>;
53
-
type SerializeMap = Impossible<(), Self::Error>;
54
-
type SerializeStruct = Self;
55
-
type SerializeStructVariant = Impossible<(), Self::Error>;
56
-
57
-
fn serialize_bool(self, _v: bool) -> Result<Self::Ok, Self::Error> {
58
-
unreachable!()
59
-
}
60
-
61
-
fn serialize_i8(self, _v: i8) -> Result<Self::Ok, Self::Error> {
62
-
unreachable!()
63
-
}
64
-
65
-
fn serialize_i16(self, _v: i16) -> Result<Self::Ok, Self::Error> {
66
-
unreachable!()
67
-
}
68
-
69
-
fn serialize_i32(self, _v: i32) -> Result<Self::Ok, Self::Error> {
70
-
unreachable!()
71
-
}
72
-
73
-
fn serialize_i64(self, _v: i64) -> Result<Self::Ok, Self::Error> {
74
-
unreachable!()
75
-
}
76
-
77
-
fn serialize_u8(self, v: u8) -> Result<Self::Ok, Self::Error> {
78
-
self.output.write_all(&[v])?;
79
-
Ok(())
80
-
}
81
-
82
-
fn serialize_u16(self, _v: u16) -> Result<Self::Ok, Self::Error> {
83
-
unreachable!()
84
-
}
85
-
86
-
fn serialize_u32(self, v: u32) -> Result<Self::Ok, Self::Error> {
87
-
self.pack_dd(v)
88
-
}
89
-
90
-
fn serialize_u64(self, v: u64) -> Result<Self::Ok, Self::Error> {
91
-
let high = (v >> 32) & 0xffffffff;
92
-
let low = v & 0xffffffff;
93
-
self.pack_dd(high as u32)?;
94
-
self.pack_dd(low as u32)?;
95
-
Ok(())
96
-
}
97
-
98
-
fn serialize_f32(self, _v: f32) -> Result<Self::Ok, Self::Error> {
99
-
unreachable!()
100
-
}
101
-
102
-
fn serialize_f64(self, _v: f64) -> Result<Self::Ok, Self::Error> {
103
-
unreachable!()
104
-
}
105
-
106
-
fn serialize_char(self, _v: char) -> Result<Self::Ok, Self::Error> {
107
-
unreachable!()
108
-
}
109
-
110
-
fn serialize_str(self, v: &str) -> Result<Self::Ok, Self::Error> {
111
-
self.pack_str(v)
112
-
}
113
-
114
-
fn serialize_bytes(self, v: &[u8]) -> Result<Self::Ok, Self::Error> {
115
-
self.pack_bytes(v)
116
-
}
117
-
118
-
fn serialize_none(self) -> Result<Self::Ok, Self::Error> {
119
-
unreachable!()
120
-
}
121
-
122
-
fn serialize_some<T: ?Sized + Serialize>(self, _value: &T) -> Result<Self::Ok, Self::Error> {
123
-
unreachable!()
124
-
}
125
-
126
-
fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
127
-
// unit contains no information...
128
-
Ok(())
129
-
}
130
-
131
-
fn serialize_unit_struct(self, _name: &'static str) -> Result<Self::Ok, Self::Error> {
132
-
unreachable!()
133
-
}
134
-
135
-
fn serialize_unit_variant(self, _name: &'static str, _variant_index: u32, _variant: &'static str) -> Result<Self::Ok, Self::Error> {
136
-
unreachable!()
137
-
}
138
-
139
-
fn serialize_newtype_struct<T: ?Sized + Serialize>(self, _name: &'static str, _value: &T) -> Result<Self::Ok, Self::Error> {
140
-
unreachable!()
141
-
}
142
-
143
-
fn serialize_newtype_variant<T: ?Sized + Serialize>(self, _name: &'static str, _variant_index: u32, _variant: &'static str, _value: &T) -> Result<Self::Ok, Self::Error> {
144
-
unreachable!()
145
-
}
146
-
147
-
fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> {
148
-
let len = len.unwrap();
149
-
self.pack_dd(len as u32)?;
150
-
Ok(self)
151
-
}
152
-
153
-
fn serialize_tuple(self, _len: usize) -> Result<Self::SerializeTuple, Self::Error> {
154
-
Ok(self)
155
-
}
156
-
157
-
fn serialize_tuple_struct(self, _name: &'static str, _len: usize) -> Result<Self::SerializeTupleStruct, Self::Error> {
158
-
unreachable!();
159
-
}
160
-
161
-
fn serialize_tuple_variant(self, _name: &'static str, _variant_index: u32, _variant: &'static str, _len: usize) -> Result<Self::SerializeTupleVariant, Self::Error> {
162
-
unreachable!()
163
-
}
164
-
165
-
fn serialize_map(self, _len: Option<usize>) -> Result<Self::SerializeMap, Self::Error> {
166
-
unreachable!()
167
-
}
168
-
169
-
fn serialize_struct(self, _name: &'static str, _len: usize) -> Result<Self::SerializeStruct, Self::Error> {
170
-
// structs will simply be flattened
171
-
Ok(self)
172
-
}
173
-
174
-
fn serialize_struct_variant(self, _name: &'static str, _variant_index: u32, _variant: &'static str, _len: usize) -> Result<Self::SerializeStructVariant, Self::Error> {
175
-
unreachable!()
176
-
}
177
-
}
178
-
179
-
impl<'a, W: Write> ser::SerializeSeq for &'a mut Serializer<W> {
180
-
type Ok = ();
181
-
type Error = Error;
182
-
183
-
fn serialize_element<T: ?Sized + Serialize>(&mut self, value: &T) -> Result<(), Self::Error> {
184
-
value.serialize(&mut **self)
185
-
}
186
-
187
-
fn end(self) -> Result<Self::Ok, Self::Error> {
188
-
Ok(())
189
-
}
190
-
}
191
-
192
-
impl<'a, W: Write> ser::SerializeTuple for &'a mut Serializer<W> {
193
-
type Ok = ();
194
-
type Error = Error;
195
-
196
-
fn serialize_element<T: ?Sized + Serialize>(&mut self, value: &T) -> Result<(), Self::Error> {
197
-
value.serialize(&mut **self)
198
-
}
199
-
200
-
fn end(self) -> Result<Self::Ok, Self::Error> {
201
-
Ok(())
202
-
}
203
-
}
204
-
205
-
impl<'a, W: Write> ser::SerializeStruct for &'a mut Serializer<W> {
206
-
type Ok = ();
207
-
type Error = Error;
208
-
209
-
fn serialize_field<T: ?Sized + Serialize>(&mut self, _key: &'static str, value: &T) -> Result<(), Self::Error> {
210
-
// struct names have no meaning
211
-
value.serialize(&mut **self)
212
-
}
213
-
214
-
fn end(self) -> Result<Self::Ok, Self::Error> {
215
-
Ok(())
216
-
}
217
-
}
218
-
219
-
#[cfg(test)]
220
-
mod tests {
221
-
#[test]
222
-
fn ser_hello() {
223
-
#[derive(serde::Serialize)]
224
-
struct Test<'a> {
225
-
arr: [u8; 16],
226
-
s: &'a str,
227
-
b: &'a [u8],
228
-
i: u32,
229
-
q: u64,
230
-
}
231
-
let v = Test {
232
-
arr: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
233
-
s: "somestring",
234
-
b: b"bytes",
235
-
i: 0x20,
236
-
q: 0x20,
237
-
};
238
-
let v = super::to_vec(&v).expect("failed to serialize dummy");
239
-
assert_eq!(v, b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10somestring\x00\x05bytes\x20\x00\x20");
240
-
}
241
-
}
1
+
use super::Error;
2
+
use serde::{ser, ser::Impossible, Serialize};
3
+
use std::io::Write;
4
+
5
+
struct Serializer<W: Write> {
6
+
output: W,
7
+
}
8
+
9
+
pub fn to_writer<T: Serialize, W: Write>(v: &T, w: W) -> Result<(), Error> {
10
+
let mut serializer = Serializer { output: w };
11
+
v.serialize(&mut serializer)?;
12
+
Ok(())
13
+
}
14
+
15
+
#[allow(dead_code)]
16
+
pub fn to_vec<T: Serialize>(v: &T) -> Result<Vec<u8>, Error> {
17
+
let mut buf = vec![];
18
+
to_writer(v, &mut buf)?;
19
+
Ok(buf)
20
+
}
21
+
22
+
impl<W: Write> Serializer<W> {
23
+
fn pack_dd(&mut self, num: u32) -> Result<(), Error> {
24
+
let mut buf = [0u8; 5];
25
+
let bytes = super::packing::pack_dd(num, &mut buf);
26
+
self.output.write_all(&buf[..bytes])?;
27
+
Ok(())
28
+
}
29
+
30
+
fn pack_str(&mut self, s: &str) -> Result<(), Error> {
31
+
self.output.write_all(s.as_bytes())?;
32
+
self.output.write_all(&[0])?;
33
+
Ok(())
34
+
}
35
+
36
+
fn pack_bytes(&mut self, b: &[u8]) -> Result<(), Error> {
37
+
self.pack_dd(b.len() as u32)?;
38
+
self.output.write_all(b)?;
39
+
Ok(())
40
+
}
41
+
}
42
+
43
+
impl<'a, W: Write> ser::Serializer for &'a mut Serializer<W> {
44
+
type Ok = ();
45
+
type Error = Error;
46
+
47
+
type SerializeSeq = Self;
48
+
type SerializeTuple = Self;
49
+
type SerializeTupleStruct = Impossible<(), Self::Error>;
50
+
type SerializeTupleVariant = Impossible<(), Self::Error>;
51
+
type SerializeMap = Impossible<(), Self::Error>;
52
+
type SerializeStruct = Self;
53
+
type SerializeStructVariant = Impossible<(), Self::Error>;
54
+
55
+
fn serialize_bool(self, _v: bool) -> Result<Self::Ok, Self::Error> {
56
+
unreachable!()
57
+
}
58
+
59
+
fn serialize_i8(self, _v: i8) -> Result<Self::Ok, Self::Error> {
60
+
unreachable!()
61
+
}
62
+
63
+
fn serialize_i16(self, _v: i16) -> Result<Self::Ok, Self::Error> {
64
+
unreachable!()
65
+
}
66
+
67
+
fn serialize_i32(self, _v: i32) -> Result<Self::Ok, Self::Error> {
68
+
unreachable!()
69
+
}
70
+
71
+
fn serialize_i64(self, _v: i64) -> Result<Self::Ok, Self::Error> {
72
+
unreachable!()
73
+
}
74
+
75
+
fn serialize_u8(self, v: u8) -> Result<Self::Ok, Self::Error> {
76
+
self.output.write_all(&[v])?;
77
+
Ok(())
78
+
}
79
+
80
+
fn serialize_u16(self, _v: u16) -> Result<Self::Ok, Self::Error> {
81
+
unreachable!()
82
+
}
83
+
84
+
fn serialize_u32(self, v: u32) -> Result<Self::Ok, Self::Error> {
85
+
self.pack_dd(v)
86
+
}
87
+
88
+
fn serialize_u64(self, v: u64) -> Result<Self::Ok, Self::Error> {
89
+
let high = (v >> 32) & 0xffffffff;
90
+
let low = v & 0xffffffff;
91
+
self.pack_dd(high as u32)?;
92
+
self.pack_dd(low as u32)?;
93
+
Ok(())
94
+
}
95
+
96
+
fn serialize_f32(self, _v: f32) -> Result<Self::Ok, Self::Error> {
97
+
unreachable!()
98
+
}
99
+
100
+
fn serialize_f64(self, _v: f64) -> Result<Self::Ok, Self::Error> {
101
+
unreachable!()
102
+
}
103
+
104
+
fn serialize_char(self, _v: char) -> Result<Self::Ok, Self::Error> {
105
+
unreachable!()
106
+
}
107
+
108
+
fn serialize_str(self, v: &str) -> Result<Self::Ok, Self::Error> {
109
+
self.pack_str(v)
110
+
}
111
+
112
+
fn serialize_bytes(self, v: &[u8]) -> Result<Self::Ok, Self::Error> {
113
+
self.pack_bytes(v)
114
+
}
115
+
116
+
fn serialize_none(self) -> Result<Self::Ok, Self::Error> {
117
+
unreachable!()
118
+
}
119
+
120
+
fn serialize_some<T: ?Sized + Serialize>(self, _value: &T) -> Result<Self::Ok, Self::Error> {
121
+
unreachable!()
122
+
}
123
+
124
+
fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
125
+
// unit contains no information...
126
+
Ok(())
127
+
}
128
+
129
+
fn serialize_unit_struct(self, _name: &'static str) -> Result<Self::Ok, Self::Error> {
130
+
unreachable!()
131
+
}
132
+
133
+
fn serialize_unit_variant(
134
+
self, _name: &'static str, _variant_index: u32, _variant: &'static str,
135
+
) -> Result<Self::Ok, Self::Error> {
136
+
unreachable!()
137
+
}
138
+
139
+
fn serialize_newtype_struct<T: ?Sized + Serialize>(
140
+
self, _name: &'static str, _value: &T,
141
+
) -> Result<Self::Ok, Self::Error> {
142
+
unreachable!()
143
+
}
144
+
145
+
fn serialize_newtype_variant<T: ?Sized + Serialize>(
146
+
self, _name: &'static str, _variant_index: u32, _variant: &'static str, _value: &T,
147
+
) -> Result<Self::Ok, Self::Error> {
148
+
unreachable!()
149
+
}
150
+
151
+
fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> {
152
+
let len = len.unwrap();
153
+
self.pack_dd(len as u32)?;
154
+
Ok(self)
155
+
}
156
+
157
+
fn serialize_tuple(self, _len: usize) -> Result<Self::SerializeTuple, Self::Error> {
158
+
Ok(self)
159
+
}
160
+
161
+
fn serialize_tuple_struct(
162
+
self, _name: &'static str, _len: usize,
163
+
) -> Result<Self::SerializeTupleStruct, Self::Error> {
164
+
unreachable!();
165
+
}
166
+
167
+
fn serialize_tuple_variant(
168
+
self, _name: &'static str, _variant_index: u32, _variant: &'static str, _len: usize,
169
+
) -> Result<Self::SerializeTupleVariant, Self::Error> {
170
+
unreachable!()
171
+
}
172
+
173
+
fn serialize_map(self, _len: Option<usize>) -> Result<Self::SerializeMap, Self::Error> {
174
+
unreachable!()
175
+
}
176
+
177
+
fn serialize_struct(
178
+
self, _name: &'static str, _len: usize,
179
+
) -> Result<Self::SerializeStruct, Self::Error> {
180
+
// structs will simply be flattened
181
+
Ok(self)
182
+
}
183
+
184
+
fn serialize_struct_variant(
185
+
self, _name: &'static str, _variant_index: u32, _variant: &'static str, _len: usize,
186
+
) -> Result<Self::SerializeStructVariant, Self::Error> {
187
+
unreachable!()
188
+
}
189
+
}
190
+
191
+
impl<'a, W: Write> ser::SerializeSeq for &'a mut Serializer<W> {
192
+
type Ok = ();
193
+
type Error = Error;
194
+
195
+
fn serialize_element<T: ?Sized + Serialize>(&mut self, value: &T) -> Result<(), Self::Error> {
196
+
value.serialize(&mut **self)
197
+
}
198
+
199
+
fn end(self) -> Result<Self::Ok, Self::Error> {
200
+
Ok(())
201
+
}
202
+
}
203
+
204
+
impl<'a, W: Write> ser::SerializeTuple for &'a mut Serializer<W> {
205
+
type Ok = ();
206
+
type Error = Error;
207
+
208
+
fn serialize_element<T: ?Sized + Serialize>(&mut self, value: &T) -> Result<(), Self::Error> {
209
+
value.serialize(&mut **self)
210
+
}
211
+
212
+
fn end(self) -> Result<Self::Ok, Self::Error> {
213
+
Ok(())
214
+
}
215
+
}
216
+
217
+
impl<'a, W: Write> ser::SerializeStruct for &'a mut Serializer<W> {
218
+
type Ok = ();
219
+
type Error = Error;
220
+
221
+
fn serialize_field<T: ?Sized + Serialize>(
222
+
&mut self, _key: &'static str, value: &T,
223
+
) -> Result<(), Self::Error> {
224
+
// struct names have no meaning
225
+
value.serialize(&mut **self)
226
+
}
227
+
228
+
fn end(self) -> Result<Self::Ok, Self::Error> {
229
+
Ok(())
230
+
}
231
+
}
232
+
233
+
#[cfg(test)]
234
+
mod tests {
235
+
#[test]
236
+
fn ser_hello() {
237
+
#[derive(serde::Serialize)]
238
+
struct Test<'a> {
239
+
arr: [u8; 16],
240
+
s: &'a str,
241
+
b: &'a [u8],
242
+
i: u32,
243
+
q: u64,
244
+
}
245
+
let v = Test {
246
+
arr: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
247
+
s: "somestring",
248
+
b: b"bytes",
249
+
i: 0x20,
250
+
q: 0x20,
251
+
};
252
+
let v = super::to_vec(&v).expect("failed to serialize dummy");
253
+
assert_eq!(v, b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10somestring\x00\x05bytes\x20\x00\x20");
254
+
}
255
+
}
+192
-229
common/src/web/api.rs
+192
-229
common/src/web/api.rs
···
1
-
use std::borrow::Cow;
2
-
use log::*;
3
-
use warp::{Filter, Reply, Rejection};
4
-
use crate::{db::DbStats};
5
-
use serde::Serialize;
6
-
7
-
use super::SharedState;
8
-
9
-
struct Md5([u8; 16]);
10
-
impl std::str::FromStr for Md5 {
11
-
type Err = &'static str;
12
-
fn from_str(s: &str) -> Result<Md5, Self::Err> {
13
-
let mut res = [0u8; 16];
14
-
let s = s.trim();
15
-
if s.len() != 32 {
16
-
return Err("bad md5 length");
17
-
}
18
-
binascii::hex2bin(s.as_bytes(), &mut res)
19
-
.map_err(|_| "bad md5")?;
20
-
Ok(Md5(res))
21
-
}
22
-
}
23
-
24
-
#[derive(Serialize)]
25
-
struct Error<'a> {
26
-
error: &'a str,
27
-
}
28
-
29
-
impl std::fmt::Display for Md5 {
30
-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31
-
let mut out = [0u8; 32];
32
-
binascii::bin2hex(&self.0, &mut out).unwrap();
33
-
let out = std::str::from_utf8(&out).unwrap();
34
-
write!(f, "{}", &out)
35
-
}
36
-
}
37
-
38
-
impl Serialize for Md5 {
39
-
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
40
-
serializer.serialize_str(&format!("{}", &self))
41
-
}
42
-
}
43
-
44
-
pub fn api_root(state: SharedState) -> impl Filter<Extract = (impl Reply + 'static, ), Error=Rejection> + Clone {
45
-
let view_file = warp::get()
46
-
.and(warp::path("files"))
47
-
.and(super::with_state(state.clone()))
48
-
.and(warp::filters::path::param::<Md5>())
49
-
.and_then(view_file_by_hash);
50
-
let view_func = warp::get()
51
-
.and(warp::path("funcs"))
52
-
.and(super::with_state(state.clone()))
53
-
.and(warp::filters::path::param::<Md5>())
54
-
.and_then(view_func_by_hash);
55
-
let view_status = warp::get()
56
-
.and(warp::path("status"))
57
-
.and(super::with_state(state))
58
-
.and_then(view_status);
59
-
60
-
view_file
61
-
.or(view_func)
62
-
.or(view_status)
63
-
}
64
-
65
-
// GET server/api/files/:md5
66
-
async fn view_file_by_hash(state: SharedState, md5: Md5) -> Result<impl Reply, Rejection> {
67
-
#[derive(Serialize)]
68
-
struct FileFunc {
69
-
hash: Md5,
70
-
len: u32,
71
-
name: String,
72
-
}
73
-
74
-
let v = match state.db.get_file_funcs(&md5.0[..], 0, 10_000).await {
75
-
Ok(v) => v,
76
-
Err(err) => {
77
-
error!("failed to get file's funcs {}: {}", &md5, err);
78
-
return Ok(warp::reply::json(&Error{error: "internal server error"}));
79
-
},
80
-
};
81
-
let v: Vec<_> = v.into_iter()
82
-
.map(|v| {
83
-
FileFunc {
84
-
name: v.0,
85
-
len: v.1,
86
-
hash: Md5(v.2),
87
-
}
88
-
})
89
-
.collect();
90
-
91
-
Result::<_, Rejection>::Ok(warp::reply::json(&v))
92
-
}
93
-
94
-
// GET server/api/funcs/:md5
95
-
async fn view_func_by_hash(state: SharedState, md5: Md5) -> Result<impl Reply, Rejection> {
96
-
#[derive(Serialize)]
97
-
enum CommentType {
98
-
Posterior,
99
-
Anterior,
100
-
Function{ repeatable: bool },
101
-
Byte { repeatable: bool },
102
-
}
103
-
104
-
#[derive(Serialize)]
105
-
struct Comment<'a> {
106
-
#[serde(skip_serializing_if = "Option::is_none")]
107
-
offset: Option<u32>,
108
-
#[serde(rename = "type")]
109
-
type_: CommentType,
110
-
comment: Cow<'a, str>,
111
-
}
112
-
113
-
#[derive(Serialize)]
114
-
struct FuncInfo<'a> {
115
-
name: &'a str,
116
-
comments: Vec<Comment<'a>>,
117
-
length: u32,
118
-
in_files: &'a [Md5],
119
-
}
120
-
121
-
let funcs = [crate::rpc::PullMetadataFunc {
122
-
unk0: 1,
123
-
mb_hash: &md5.0
124
-
}];
125
-
126
-
let files_with = state.db.get_files_with_func(&md5.0[..]);
127
-
let files_info = state.db.get_funcs(&funcs);
128
-
129
-
let (files_with, files_info) = match futures_util::try_join!(files_with, files_info) {
130
-
Ok(v) => v,
131
-
Err(err) => {
132
-
error!("failed to execute db queries: {}", err);
133
-
return Ok(warp::reply::json(&Error {error: "internal server error"}));
134
-
}
135
-
};
136
-
137
-
let files_with: Vec<Md5> = files_with.into_iter().map(Md5).collect();
138
-
139
-
let v = files_info;
140
-
let v: Vec<FuncInfo> = v
141
-
.iter()
142
-
.take(1)
143
-
.filter_map(|v| v.as_ref())
144
-
.filter_map(|v| {
145
-
let md = match crate::md::parse_metadata(&v.data) {
146
-
Ok(v) => v,
147
-
Err(e) => {
148
-
error!("error parsing metadata for {}: {}", &md5, e);
149
-
return None;
150
-
}
151
-
};
152
-
let comments: Vec<Comment> = md.into_iter()
153
-
.filter_map(|md| {
154
-
match md {
155
-
crate::md::FunctionMetadata::ByteComment(c) => {
156
-
Some(vec![Comment {
157
-
offset: Some(c.offset),
158
-
type_: CommentType::Byte{ repeatable: c.is_repeatable },
159
-
comment: c.comment.into(),
160
-
}])
161
-
},
162
-
crate::md::FunctionMetadata::FunctionComment(c) => {
163
-
Some(vec![Comment {
164
-
offset: None,
165
-
type_: CommentType::Function{ repeatable: c.is_repeatable },
166
-
comment: c.comment.into(),
167
-
}])
168
-
},
169
-
crate::md::FunctionMetadata::ExtraComment(c) => {
170
-
let mut res = vec![];
171
-
if !c.anterior.is_empty() {
172
-
res.push(Comment {
173
-
offset: Some(c.offset),
174
-
type_: CommentType::Anterior,
175
-
comment: c.anterior.into(),
176
-
});
177
-
}
178
-
if !c.posterior.is_empty() {
179
-
res.push(Comment {
180
-
offset: Some(c.offset),
181
-
type_: CommentType::Posterior,
182
-
comment: c.posterior.into(),
183
-
});
184
-
}
185
-
if !res.is_empty() {
186
-
Some(res)
187
-
} else {
188
-
None
189
-
}
190
-
},
191
-
}
192
-
})
193
-
.flatten()
194
-
.collect();
195
-
Some(FuncInfo {
196
-
name: &v.name,
197
-
length: v.len,
198
-
comments,
199
-
in_files: &files_with,
200
-
})
201
-
}).collect();
202
-
203
-
Result::<_, Rejection>::Ok(warp::reply::json(&v))
204
-
}
205
-
206
-
// GET /api/status
207
-
async fn view_status(state: SharedState) -> Result<impl Reply, Rejection> {
208
-
#[derive(Serialize)]
209
-
enum DbStatus {
210
-
Stats(DbStats),
211
-
Error(String),
212
-
}
213
-
214
-
#[derive(Serialize)]
215
-
struct Response {
216
-
db_online: bool,
217
-
stats: DbStatus,
218
-
}
219
-
220
-
let stats = match state.db.get_stats().await {
221
-
Ok(stats) => DbStatus::Stats(stats),
222
-
Err(err) => DbStatus::Error(format!("{}", err)),
223
-
};
224
-
225
-
Result::<_, Rejection>::Ok(warp::reply::json(&Response {
226
-
db_online: state.db.is_online().await,
227
-
stats,
228
-
}))
229
-
}
1
+
use log::*;
2
+
use serde::Serialize;
3
+
use std::borrow::Cow;
4
+
use warp::{Filter, Rejection, Reply};
5
+
6
+
use super::SharedState;
7
+
8
+
struct Md5([u8; 16]);
9
+
impl std::str::FromStr for Md5 {
10
+
type Err = &'static str;
11
+
fn from_str(s: &str) -> Result<Md5, Self::Err> {
12
+
let mut res = [0u8; 16];
13
+
let s = s.trim();
14
+
if s.len() != 32 {
15
+
return Err("bad md5 length");
16
+
}
17
+
binascii::hex2bin(s.as_bytes(), &mut res).map_err(|_| "bad md5")?;
18
+
Ok(Md5(res))
19
+
}
20
+
}
21
+
22
+
#[derive(Serialize)]
23
+
struct Error<'a> {
24
+
error: &'a str,
25
+
}
26
+
27
+
impl std::fmt::Display for Md5 {
28
+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29
+
let mut out = [0u8; 32];
30
+
binascii::bin2hex(&self.0, &mut out).unwrap();
31
+
let out = std::str::from_utf8(&out).unwrap();
32
+
write!(f, "{}", &out)
33
+
}
34
+
}
35
+
36
+
impl Serialize for Md5 {
37
+
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
38
+
serializer.serialize_str(&format!("{}", &self))
39
+
}
40
+
}
41
+
42
+
pub fn api_root(
43
+
state: SharedState,
44
+
) -> impl Filter<Extract = (impl Reply + 'static,), Error = Rejection> + Clone {
45
+
let view_file = warp::get()
46
+
.and(warp::path("files"))
47
+
.and(super::with_state(state.clone()))
48
+
.and(warp::filters::path::param::<Md5>())
49
+
.and_then(view_file_by_hash);
50
+
let view_func = warp::get()
51
+
.and(warp::path("funcs"))
52
+
.and(super::with_state(state))
53
+
.and(warp::filters::path::param::<Md5>())
54
+
.and_then(view_func_by_hash);
55
+
56
+
view_file.or(view_func)
57
+
}
58
+
59
+
// GET server/api/files/:md5
60
+
async fn view_file_by_hash(state: SharedState, md5: Md5) -> Result<impl Reply, Rejection> {
61
+
#[derive(Serialize)]
62
+
struct FileFunc {
63
+
hash: Md5,
64
+
len: u32,
65
+
name: String,
66
+
}
67
+
68
+
let v = match state.db.get_file_funcs(&md5.0[..], 0, 10_000).await {
69
+
Ok(v) => v,
70
+
Err(err) => {
71
+
error!("failed to get file's funcs {}: {}", &md5, err);
72
+
return Ok(warp::reply::json(&Error { error: "internal server error" }));
73
+
},
74
+
};
75
+
let v: Vec<_> = v
76
+
.into_iter()
77
+
.map(|v| {
78
+
let mut hash = [0u8; 16];
79
+
hash.copy_from_slice(&v.2);
80
+
FileFunc { name: v.0, len: v.1 as u32, hash: Md5(hash) }
81
+
})
82
+
.collect();
83
+
84
+
Result::<_, Rejection>::Ok(warp::reply::json(&v))
85
+
}
86
+
87
+
// GET server/api/funcs/:md5
88
+
async fn view_func_by_hash(state: SharedState, md5: Md5) -> Result<impl Reply, Rejection> {
89
+
#[derive(Serialize)]
90
+
enum CommentType {
91
+
Posterior,
92
+
Anterior,
93
+
Function { repeatable: bool },
94
+
Byte { repeatable: bool },
95
+
}
96
+
97
+
#[derive(Serialize)]
98
+
struct Comment<'a> {
99
+
#[serde(skip_serializing_if = "Option::is_none")]
100
+
offset: Option<u32>,
101
+
#[serde(rename = "type")]
102
+
type_: CommentType,
103
+
comment: Cow<'a, str>,
104
+
}
105
+
106
+
#[derive(Serialize)]
107
+
struct FuncInfo<'a> {
108
+
name: &'a str,
109
+
comments: Vec<Comment<'a>>,
110
+
length: u32,
111
+
in_files: &'a [Md5],
112
+
}
113
+
114
+
let funcs = [crate::rpc::PullMetadataFunc { unk0: 1, mb_hash: &md5.0 }];
115
+
116
+
let files_with = state.db.get_files_with_func(&md5.0[..]);
117
+
let files_info = state.db.get_funcs(&funcs);
118
+
119
+
let (files_with, files_info) = match futures_util::try_join!(files_with, files_info) {
120
+
Ok(v) => v,
121
+
Err(err) => {
122
+
error!("failed to execute db queries: {}", err);
123
+
return Ok(warp::reply::json(&Error { error: "internal server error" }));
124
+
},
125
+
};
126
+
127
+
let files_with: Vec<Md5> = files_with
128
+
.into_iter()
129
+
.map(|v| {
130
+
let mut md5 = [0u8; 16];
131
+
md5.copy_from_slice(&v);
132
+
Md5(md5)
133
+
})
134
+
.collect();
135
+
136
+
let v = files_info;
137
+
let v: Vec<FuncInfo> = v
138
+
.iter()
139
+
.take(1)
140
+
.filter_map(|v| v.as_ref())
141
+
.filter_map(|v| {
142
+
let md = match crate::md::parse_metadata(&v.data) {
143
+
Ok(v) => v,
144
+
Err(e) => {
145
+
error!("error parsing metadata for {}: {}", &md5, e);
146
+
return None;
147
+
},
148
+
};
149
+
let comments: Vec<Comment> = md
150
+
.into_iter()
151
+
.filter_map(|md| match md {
152
+
crate::md::FunctionMetadata::ByteComment(c) => Some(vec![Comment {
153
+
offset: Some(c.offset),
154
+
type_: CommentType::Byte { repeatable: c.is_repeatable },
155
+
comment: c.comment.into(),
156
+
}]),
157
+
crate::md::FunctionMetadata::FunctionComment(c) => Some(vec![Comment {
158
+
offset: None,
159
+
type_: CommentType::Function { repeatable: c.is_repeatable },
160
+
comment: c.comment.into(),
161
+
}]),
162
+
crate::md::FunctionMetadata::ExtraComment(c) => {
163
+
let mut res = vec![];
164
+
if !c.anterior.is_empty() {
165
+
res.push(Comment {
166
+
offset: Some(c.offset),
167
+
type_: CommentType::Anterior,
168
+
comment: c.anterior.into(),
169
+
});
170
+
}
171
+
if !c.posterior.is_empty() {
172
+
res.push(Comment {
173
+
offset: Some(c.offset),
174
+
type_: CommentType::Posterior,
175
+
comment: c.posterior.into(),
176
+
});
177
+
}
178
+
if !res.is_empty() {
179
+
Some(res)
180
+
} else {
181
+
None
182
+
}
183
+
},
184
+
})
185
+
.flatten()
186
+
.collect();
187
+
Some(FuncInfo { name: &v.name, length: v.len, comments, in_files: &files_with })
188
+
})
189
+
.collect();
190
+
191
+
Result::<_, Rejection>::Ok(warp::reply::json(&v))
192
+
}
+10
-8
common/src/web.rs
+10
-8
common/src/web.rs
···
1
-
use crate::SharedState;
2
-
use warp::Filter;
3
-
4
-
pub mod api;
5
-
6
-
pub fn with_state(state: SharedState) -> impl Filter<Extract=(SharedState,), Error= std::convert::Infallible> + Clone {
7
-
warp::any().map(move || state.clone())
8
-
}
1
+
use crate::SharedState;
2
+
use warp::Filter;
3
+
4
+
pub mod api;
5
+
6
+
pub fn with_state(
7
+
state: SharedState,
8
+
) -> impl Filter<Extract = (SharedState,), Error = std::convert::Infallible> + Clone {
9
+
warp::any().map(move || state.clone())
10
+
}
+6
-1
config-example.toml
+6
-1
config-example.toml
···
6
6
# server display name; appears in IDA output window
7
7
server_name = "lumen"
8
8
9
+
# Allow clients to delete metadata from the database?
10
+
allow_deletes = false
11
+
# How many function histories should we return? 0=Disabled.
12
+
get_history_limit = 50
13
+
9
14
# only required when `use_tls` is set to true.
10
15
[lumina.tls]
11
16
# Specify the server's certificate.
···
15
20
16
21
[database]
17
22
# Specifies a postgresql connection string. All variables can be found here: https://docs.rs/tokio-postgres/0.6.0/tokio_postgres/config/struct.Config.html
18
-
connection_info = "host=127.0.0.1 port=49153 user=postgres password=1"
23
+
connection_info = "postgres://postgres:1@127.0.0.1/postgres"
19
24
# Sets if the database connection should be made using TLS.
20
25
use_tls = false
21
26
# If the database requires a secure connection, paths to server-ca and client-id certificates can be set here:
+37
-29
docker-compose.yml
+37
-29
docker-compose.yml
···
1
-
version: '3.7'
1
+
name: lumen
2
+
volumes:
3
+
postgres_data:
2
4
3
-
volumes:
4
-
postgres_data:
5
5
services:
6
-
db:
7
-
image: postgres:13-alpine
8
-
container_name: lumina-postgres
9
-
environment:
10
-
POSTGRES_USER: lumina
11
-
POSTGRES_DB: lumina
12
-
POSTGRES_PASSWORD: 1
13
-
expose:
14
-
- "5432"
15
-
volumes:
16
-
- postgres_data:/var/lib/postgresql
17
-
- ./schema.sql:/docker-entrypoint-initdb.d/schema.sql:ro
18
-
lumina:
19
-
build: .
20
-
command: sh -c 'while ! nc -vv -z db 5432; do sleep 1; done; /lumen/docker-init.sh'
21
-
depends_on:
22
-
- db
23
-
ports:
24
-
- 1234:1234
25
-
- 8082:8082
26
-
environment:
27
-
PKCSPASSWD: $PKCSPASSWD
28
-
volumes:
29
-
- ./dockershare:/dockershare
30
-
links:
31
-
- db
6
+
db:
7
+
image: postgres:15.1-alpine
8
+
container_name: lumina-postgres
9
+
healthcheck:
10
+
test: ["CMD", "pg_isready", "-U", "lumina"]
11
+
interval: 5s
12
+
retries: 10
13
+
timeout: 5s
14
+
environment:
15
+
POSTGRES_USER: lumina
16
+
POSTGRES_DB: lumina
17
+
POSTGRES_PASSWORD: 1
18
+
expose:
19
+
- "5432"
20
+
volumes:
21
+
- postgres_data:/var/lib/postgresql
22
+
mem_swappiness: 0
23
+
24
+
lumina:
25
+
build: .
26
+
image: ghcr.io/naim94a/lumen:master
27
+
depends_on:
28
+
db:
29
+
condition: service_healthy
30
+
ports:
31
+
- 1234:1234
32
+
- 8082:8082
33
+
environment:
34
+
PKCSPASSWD: $PKCSPASSWD
35
+
DATABASE_URL: postgres://lumina:1@db/lumina
36
+
volumes:
37
+
- ./dockershare:/dockershare
38
+
links:
39
+
- db
+5
-2
docker-init.sh
+5
-2
docker-init.sh
···
5
5
echo "Exiting due to error: $@" && exit 1
6
6
}
7
7
do_config_fixup(){
8
-
sed -i -e "s,connection_info.*,connection_info = \"host=db port=5432 user=lumina password=1\"," \
8
+
sed -i -e "s,connection_info.*,connection_info = \"${DATABASE_URL}\"," \
9
9
/lumen/config.toml
10
10
}
11
11
use_default_config(){
···
66
66
67
67
setup_config ;
68
68
do_config_fixup ;
69
-
lumen -c /lumen/config.toml || die "Launching lumen";
69
+
echo Running DB migrations...
70
+
diesel --config-file /usr/lib/lumen/diesel.toml migration run
71
+
echo Migrations done.
72
+
exec lumen -c /lumen/config.toml
+8
-7
lumen/Cargo.toml
+8
-7
lumen/Cargo.toml
···
3
3
description = "lumen server"
4
4
version = "0.2.0"
5
5
authors = ["Naim A. <naim@abda.nl>"]
6
-
edition = "2018"
6
+
edition = "2021"
7
7
publish = false
8
8
9
9
[dependencies]
10
-
common = {path = "../common"}
11
-
tokio = {version = "1.21", features = ["full"]}
12
-
log = {version = "0.4", features = ["release_max_level_debug"]}
13
-
pretty_env_logger = "0.4"
14
-
clap = "4.0"
10
+
common = { path = "../common" }
11
+
tokio = { version = "1.39", features = ["full"] }
12
+
log = { version = "0.4", features = ["release_max_level_debug"] }
13
+
pretty_env_logger = "0.5"
14
+
clap = "4.5"
15
15
tokio-native-tls = "0.3"
16
-
native-tls = {version = "0.2"}
16
+
native-tls = { version = "0.2" }
17
17
warp = "0.3"
18
+
prometheus-client = "0.22"
+11
-355
lumen/src/main.rs
+11
-355
lumen/src/main.rs
···
4
4
#![warn(unused_crate_dependencies)]
5
5
#![deny(clippy::all)]
6
6
7
-
use common::rpc::{RpcHello, RpcFail};
8
-
use native_tls::Identity;
9
7
use clap::Arg;
10
8
use log::*;
11
-
use tokio::time::timeout;
12
-
use std::mem::discriminant;
13
-
use std::sync::atomic::{AtomicU32, Ordering};
14
-
use std::time::{Duration, Instant};
15
-
use std::{borrow::Cow, sync::Arc};
16
-
use tokio::{net::TcpListener, io::AsyncWrite, io::AsyncRead};
17
-
use std::process::exit;
18
-
use common::{SharedState, SharedState_};
9
+
use server::do_lumen;
10
+
use std::sync::Arc;
19
11
12
+
mod server;
20
13
mod web;
21
14
22
-
use common::{config, make_pretty_hex, md, rpc::{self, Error}};
23
-
use common::db::Database;
24
-
use rpc::RpcMessage;
15
+
use common::config;
25
16
26
17
fn setup_logger() {
27
18
if std::env::var("RUST_LOG").is_err() {
···
30
21
pretty_env_logger::init_timed();
31
22
}
32
23
33
-
async fn handle_transaction<'a, S: AsyncRead + AsyncWrite + Unpin>(state: &SharedState, user: &'a RpcHello<'a>, mut stream: S) -> Result<(), Error> {
34
-
let db = &state.db;
35
-
let server_name = state.server_name.as_str();
36
-
37
-
trace!("waiting for command..");
38
-
let req = match timeout(Duration::from_secs(3600), rpc::read_packet(&mut stream)).await {
39
-
Ok(res) => match res {
40
-
Ok(v) => v,
41
-
Err(e) => return Err(e),
42
-
},
43
-
Err(_) => {
44
-
_ = RpcMessage::Fail(RpcFail {
45
-
code: 0,
46
-
message: &format!("{server_name} client idle for too long.\n"),
47
-
}).async_write(&mut stream).await;
48
-
return Err(Error::Timeout);
49
-
},
50
-
};
51
-
trace!("got command!");
52
-
let req = match RpcMessage::deserialize(&req) {
53
-
Ok(v) => v,
54
-
Err(err) => {
55
-
warn!("bad message: \n{}\n", make_pretty_hex(&req));
56
-
error!("failed to process rpc message: {}", err);
57
-
let resp = rpc::RpcFail{ code: 0, message: &format!("{server_name}: error: invalid data.\n")};
58
-
let resp = RpcMessage::Fail(resp);
59
-
resp.async_write(&mut stream).await?;
60
-
61
-
return Ok(());
62
-
},
63
-
};
64
-
match req {
65
-
RpcMessage::PullMetadata(md) => {
66
-
let start = Instant::now();
67
-
let funcs = match timeout(Duration::from_secs(60 * 60), db.get_funcs(&md.funcs)).await {
68
-
Ok(r) => match r {
69
-
Ok(v) => v,
70
-
Err(e) => {
71
-
error!("pull failed, db: {}", e);
72
-
rpc::RpcMessage::Fail(rpc::RpcFail {
73
-
code: 0,
74
-
message: &format!("{server_name}: db error; please try again later..\n")
75
-
}).async_write(&mut stream).await?;
76
-
return Ok(());
77
-
},
78
-
},
79
-
Err(_) => {
80
-
RpcMessage::Fail(RpcFail {
81
-
code: 0,
82
-
message: &format!("{server_name}: query took too long to execute.\n"),
83
-
}).async_write(&mut stream).await?;
84
-
debug!("pull query timeout");
85
-
return Err(Error::Timeout);
86
-
}
87
-
};
88
-
debug!("pull {} funcs ended after {:?}", funcs.len(), start.elapsed());
89
-
90
-
let statuses: Vec<u32> = funcs.iter().map(|v| if v.is_none() { 1 } else {0}).collect();
91
-
let found = funcs
92
-
.into_iter()
93
-
.flatten()
94
-
.map(|v| {
95
-
rpc::PullMetadataResultFunc {
96
-
popularity: v.popularity,
97
-
len: v.len,
98
-
name: Cow::Owned(v.name),
99
-
mb_data: Cow::Owned(v.data),
100
-
}
101
-
}).collect();
102
-
103
-
RpcMessage::PullMetadataResult(rpc::PullMetadataResult{
104
-
unk0: Cow::Owned(statuses),
105
-
funcs: Cow::Owned(found),
106
-
}).async_write(&mut stream).await?;
107
-
},
108
-
RpcMessage::PushMetadata(mds) => {
109
-
// parse the function's metadata
110
-
let start = Instant::now();
111
-
let scores: Vec<u32> = mds.funcs.iter()
112
-
.map(md::get_score)
113
-
.collect();
114
-
115
-
let status = match db.push_funcs(user, &mds, &scores).await {
116
-
Ok(v) => {
117
-
v.into_iter().map(|v| if v {1} else {0}).collect::<Vec<u32>>()
118
-
},
119
-
Err(err) => {
120
-
log::error!("push failed, db: {}", err);
121
-
rpc::RpcMessage::Fail(rpc::RpcFail {
122
-
code: 0,
123
-
message: &format!("{server_name}: db error; please try again later.\n")
124
-
}).async_write(&mut stream).await?;
125
-
return Ok(());
126
-
}
127
-
};
128
-
debug!("push {} funcs ended after {:?}", status.len(), start.elapsed());
129
-
130
-
RpcMessage::PushMetadataResult(rpc::PushMetadataResult {
131
-
status: Cow::Owned(status),
132
-
}).async_write(&mut stream).await?;
133
-
},
134
-
_ => {
135
-
RpcMessage::Fail(rpc::RpcFail{code: 0, message: &format!("{server_name}: invalid data.\n")}).async_write(&mut stream).await?;
136
-
}
137
-
}
138
-
Ok(())
139
-
}
140
-
141
-
async fn handle_client<S: AsyncRead + AsyncWrite + Unpin>(state: &SharedState, mut stream: S) -> Result<(), rpc::Error> {
142
-
let server_name = &state.server_name;
143
-
let hello = match timeout(Duration::from_secs(15), rpc::read_packet(&mut stream)).await {
144
-
Ok(v) => v?,
145
-
Err(_) => {
146
-
debug!("didn't get hello in time.");
147
-
return Ok(());
148
-
},
149
-
};
150
-
151
-
let (hello, creds) = match RpcMessage::deserialize(&hello) {
152
-
Ok(RpcMessage::Hello(v, creds)) => {
153
-
debug!("hello protocol={}, login creds: {creds:?}", v.protocol_version);
154
-
(v, creds)
155
-
},
156
-
_ => {
157
-
// send error
158
-
error!("got bad hello message");
159
-
160
-
let resp = rpc::RpcFail{ code: 0, message: &format!("{}: bad sequence.\n", server_name) };
161
-
let resp = rpc::RpcMessage::Fail(resp);
162
-
resp.async_write(&mut stream).await?;
163
-
164
-
return Ok(());
165
-
}
166
-
};
167
-
168
-
if let Some(ref creds) = creds {
169
-
if creds.username != "guest" {
170
-
// Only allow "guest" to connect for now.
171
-
rpc::RpcMessage::Fail(rpc::RpcFail {
172
-
code: 1,
173
-
message: &format!("{server_name}: invalid username or password. Try logging in with `guest` instead."),
174
-
}).async_write(&mut stream).await?;
175
-
return Ok(());
176
-
}
177
-
}
178
-
179
-
let resp = rpc::RpcMessage::Ok(());
180
-
resp.async_write(&mut stream).await?;
181
-
182
-
loop {
183
-
handle_transaction(state, &hello, &mut stream).await?;
184
-
}
185
-
}
186
-
187
-
async fn handle_connection<S: AsyncRead + AsyncWrite + Unpin>(state: &SharedState, s: S) {
188
-
if let Err(err) = handle_client(state, s).await {
189
-
if discriminant(&err) != discriminant(&Error::Eof) {
190
-
warn!("err: {}", err);
191
-
}
192
-
}
193
-
}
194
-
195
-
async fn serve(listener: TcpListener, accpt: Option<tokio_native_tls::TlsAcceptor>, state: SharedState) {
196
-
static COUNTER: AtomicU32 = AtomicU32::new(0);
197
-
let accpt = accpt.map(Arc::new);
198
-
199
-
loop {
200
-
let (client, addr) = match listener.accept().await {
201
-
Ok(v) => v,
202
-
Err(err) => {
203
-
warn!("failed to accept(): {}", err);
204
-
continue;
205
-
}
206
-
};
207
-
let start = Instant::now();
208
-
209
-
let state = state.clone();
210
-
let accpt = accpt.clone();
211
-
tokio::spawn(async move {
212
-
let count = {
213
-
COUNTER.fetch_add(1, Ordering::Relaxed) + 1
214
-
};
215
-
let protocol = if accpt.is_some() {" [TLS]"} else {""};
216
-
debug!("Connection from {:?}{}: {} active connections", &addr, protocol, count);
217
-
match accpt {
218
-
Some(accpt) => {
219
-
match timeout(Duration::from_secs(10), accpt.accept(client)).await {
220
-
Ok(r) => match r {
221
-
Ok(s) => {
222
-
handle_connection(&state, s).await;
223
-
},
224
-
Err(err) => debug!("tls accept ({}): {}", &addr, err),
225
-
},
226
-
Err(_) => {
227
-
debug!("client {} didn't complete ssl handshake in time.", &addr);
228
-
},
229
-
};
230
-
},
231
-
None => handle_connection(&state, client).await,
232
-
}
233
-
234
-
let count = {
235
-
COUNTER.fetch_sub(1, Ordering::Relaxed) - 1
236
-
};
237
-
debug!("connection with {:?} ended after {:?}; {} active connections", addr, start.elapsed(), count);
238
-
});
239
-
}
240
-
}
241
-
242
-
async fn maintenance(state: std::sync::Weak<SharedState_>) {
243
-
let mut timer = tokio::time::interval(std::time::Duration::from_secs(10));
244
-
245
-
loop {
246
-
timer.tick().await;
247
-
248
-
if let Some(state) = state.upgrade() {
249
-
250
-
if !state.db.is_online().await {
251
-
warn!("db is offline; attempting to reconnect...");
252
-
match state.db.reconnect().await {
253
-
Ok(_) => info!("reconnected."),
254
-
Err(err) => error!("failed to reconnect: {}", err),
255
-
}
256
-
}
257
-
258
-
} else {
259
-
warn!("shared state is not available");
260
-
break;
261
-
}
262
-
}
263
-
}
264
-
265
-
fn main() {
24
+
#[tokio::main]
25
+
async fn main() {
266
26
setup_logger();
267
27
let matches = clap::Command::new("lumen")
268
28
.version(env!("CARGO_PKG_VERSION"))
···
271
31
.arg(
272
32
Arg::new("config")
273
33
.short('c')
274
-
.required(true)
275
34
.default_value("config.toml")
276
35
.help("Configuration file path")
277
36
)
278
37
.get_matches();
279
38
280
39
let config = {
281
-
config::load_config(std::fs::File::open(matches.get_one::<String>("config").unwrap()).expect("failed to read config"))
40
+
config::load_config(
41
+
std::fs::File::open(matches.get_one::<String>("config").unwrap())
42
+
.expect("failed to read config"),
43
+
)
282
44
};
283
45
let config = Arc::new(config);
284
46
285
-
info!("starting private lumen server...");
286
-
287
-
let rt = match tokio::runtime::Builder::new_multi_thread()
288
-
.enable_all()
289
-
.thread_stack_size(8 * 1024)
290
-
.build() {
291
-
Ok(v) => v,
292
-
Err(err) => {
293
-
error!("failed to create tokio runtime: {}", err);
294
-
exit(1);
295
-
},
296
-
};
297
-
298
-
let db = rt.block_on(async {
299
-
match Database::open(config.clone()).await {
300
-
Ok(v) => v,
301
-
Err(err) => {
302
-
error!("failed to open database: {}", err);
303
-
exit(1);
304
-
}
305
-
}
306
-
});
307
-
308
-
let server_name = config.lumina.server_name.clone().unwrap_or_else(|| String::from("lumen"));
309
-
310
-
let state = Arc::new(SharedState_{
311
-
db,
312
-
config,
313
-
server_name,
314
-
});
315
-
316
-
rt.spawn(maintenance(Arc::downgrade(&state)));
317
-
318
-
let tls_acceptor;
319
-
320
-
if state.config.lumina.use_tls.unwrap_or_default() {
321
-
let cert_path = &state.config.lumina.tls.as_ref().expect("tls section is missing").server_cert;
322
-
let mut crt = match std::fs::read(cert_path) {
323
-
Ok(v) => v,
324
-
Err(err) => {
325
-
error!("failed to read certificate file: {}", err);
326
-
exit(1);
327
-
}
328
-
};
329
-
let pkcs_passwd = std::env::var("PKCSPASSWD").unwrap_or_default();
330
-
let id = match Identity::from_pkcs12(&crt, &pkcs_passwd) {
331
-
Ok(v) => v,
332
-
Err(err) => {
333
-
error!("failed to parse tls certificate: {}", err);
334
-
exit(1);
335
-
}
336
-
};
337
-
let _ = pkcs_passwd;
338
-
crt.iter_mut().for_each(|v| *v = 0);
339
-
let _ = crt;
340
-
let mut accpt = native_tls::TlsAcceptor::builder(id);
341
-
accpt.min_protocol_version(Some(native_tls::Protocol::Sslv3));
342
-
let accpt = match accpt.build() {
343
-
Ok(v) => v,
344
-
Err(err) => {
345
-
error!("failed to build tls acceptor: {}", err);
346
-
exit(1);
347
-
},
348
-
};
349
-
let accpt = tokio_native_tls::TlsAcceptor::from(accpt);
350
-
tls_acceptor = Some(accpt);
351
-
} else {
352
-
tls_acceptor = None;
353
-
}
354
-
355
-
if let Some(ref webcfg) = state.config.api_server {
356
-
let bind_addr = webcfg.bind_addr;
357
-
let state = state.clone();
358
-
info!("starting http api server on {:?}", &bind_addr);
359
-
rt.spawn(async move {
360
-
web::start_webserver(bind_addr, state).await;
361
-
});
362
-
}
363
-
364
-
let async_server = async {
365
-
let server = match TcpListener::bind(state.config.lumina.bind_addr).await {
366
-
Ok(v) => v,
367
-
Err(err) => {
368
-
error!("failed to bind server port: {}", err);
369
-
exit(1);
370
-
},
371
-
};
372
-
373
-
info!("listening on {:?} secure={}", server.local_addr().unwrap(), tls_acceptor.is_some());
374
-
375
-
serve(server, tls_acceptor, state.clone()).await;
376
-
};
377
-
378
-
let ctrlc = tokio::signal::ctrl_c();
379
-
380
-
let racey = async move {
381
-
tokio::select! {
382
-
_ = async_server => {
383
-
error!("server decided to quit. this is impossible.");
384
-
},
385
-
_ = ctrlc => {
386
-
info!("process was signaled. Shutting down...");
387
-
},
388
-
}
389
-
};
390
-
391
-
rt.block_on(racey);
47
+
do_lumen(config).await;
392
48
}
+513
lumen/src/server.rs
+513
lumen/src/server.rs
···
1
+
use std::{
2
+
borrow::Cow,
3
+
collections::HashMap,
4
+
mem::discriminant,
5
+
process::exit,
6
+
sync::Arc,
7
+
time::{Duration, Instant},
8
+
};
9
+
10
+
use common::{
11
+
async_drop::AsyncDropper,
12
+
config::Config,
13
+
db::Database,
14
+
make_pretty_hex, md,
15
+
metrics::LuminaVersion,
16
+
rpc::{self, Error, HelloResult, RpcFail, RpcHello, RpcMessage},
17
+
SharedState, SharedState_,
18
+
};
19
+
use log::{debug, error, info, trace, warn};
20
+
use native_tls::Identity;
21
+
use tokio::{
22
+
io::{AsyncRead, AsyncWrite},
23
+
net::TcpListener,
24
+
time::timeout,
25
+
};
26
+
27
+
use crate::web;
28
+
29
+
async fn handle_transaction<'a, S: AsyncRead + AsyncWrite + Unpin>(
30
+
state: &SharedState, user: &'a RpcHello<'a>, mut stream: S,
31
+
) -> Result<(), Error> {
32
+
let db = &state.db;
33
+
let server_name = state.server_name.as_str();
34
+
35
+
trace!("waiting for command..");
36
+
let req = match timeout(Duration::from_secs(3600), rpc::read_packet(&mut stream)).await {
37
+
Ok(res) => match res {
38
+
Ok(v) => v,
39
+
Err(e) => return Err(e),
40
+
},
41
+
Err(_) => {
42
+
_ = RpcMessage::Fail(RpcFail {
43
+
code: 0,
44
+
message: &format!("{server_name} client idle for too long.\n"),
45
+
})
46
+
.async_write(&mut stream)
47
+
.await;
48
+
return Err(Error::Timeout);
49
+
},
50
+
};
51
+
trace!("got command!");
52
+
let req = match RpcMessage::deserialize(&req) {
53
+
Ok(v) => v,
54
+
Err(err) => {
55
+
warn!("bad message: \n{}\n", make_pretty_hex(&req));
56
+
error!("failed to process rpc message: {}", err);
57
+
let resp = rpc::RpcFail {
58
+
code: 0,
59
+
message: &format!("{server_name}: error: invalid data.\n"),
60
+
};
61
+
let resp = RpcMessage::Fail(resp);
62
+
resp.async_write(&mut stream).await?;
63
+
64
+
return Ok(());
65
+
},
66
+
};
67
+
match req {
68
+
RpcMessage::PullMetadata(md) => {
69
+
let start = Instant::now();
70
+
let funcs = match timeout(Duration::from_secs(4 * 60), db.get_funcs(&md.funcs)).await {
71
+
Ok(r) => match r {
72
+
Ok(v) => v,
73
+
Err(e) => {
74
+
error!("pull failed, db: {}", e);
75
+
rpc::RpcMessage::Fail(rpc::RpcFail {
76
+
code: 0,
77
+
message: &format!(
78
+
"{server_name}: db error; please try again later..\n"
79
+
),
80
+
})
81
+
.async_write(&mut stream)
82
+
.await?;
83
+
return Ok(());
84
+
},
85
+
},
86
+
Err(_) => {
87
+
RpcMessage::Fail(RpcFail {
88
+
code: 0,
89
+
message: &format!("{server_name}: query took too long to execute.\n"),
90
+
})
91
+
.async_write(&mut stream)
92
+
.await?;
93
+
debug!("pull query timeout");
94
+
return Err(Error::Timeout);
95
+
},
96
+
};
97
+
let pulled_funcs = funcs.iter().filter(|v| v.is_some()).count();
98
+
state.metrics.pulls.inc_by(pulled_funcs as _);
99
+
state.metrics.queried_funcs.inc_by(md.funcs.len() as _);
100
+
debug!(
101
+
"pull {pulled_funcs}/{} funcs ended after {:?}",
102
+
md.funcs.len(),
103
+
start.elapsed()
104
+
);
105
+
106
+
let statuses: Vec<u32> = funcs.iter().map(|v| u32::from(v.is_none())).collect();
107
+
let found = funcs
108
+
.into_iter()
109
+
.flatten()
110
+
.map(|v| rpc::PullMetadataResultFunc {
111
+
popularity: v.popularity,
112
+
len: v.len,
113
+
name: Cow::Owned(v.name),
114
+
mb_data: Cow::Owned(v.data),
115
+
})
116
+
.collect();
117
+
118
+
RpcMessage::PullMetadataResult(rpc::PullMetadataResult {
119
+
unk0: Cow::Owned(statuses),
120
+
funcs: Cow::Owned(found),
121
+
})
122
+
.async_write(&mut stream)
123
+
.await?;
124
+
},
125
+
RpcMessage::PushMetadata(mds) => {
126
+
// parse the function's metadata
127
+
let start = Instant::now();
128
+
let scores: Vec<u32> = mds.funcs.iter().map(md::get_score).collect();
129
+
130
+
let status = match db.push_funcs(user, &mds, &scores).await {
131
+
Ok(v) => v.into_iter().map(u32::from).collect::<Vec<u32>>(),
132
+
Err(err) => {
133
+
log::error!("push failed, db: {}", err);
134
+
rpc::RpcMessage::Fail(rpc::RpcFail {
135
+
code: 0,
136
+
message: &format!("{server_name}: db error; please try again later.\n"),
137
+
})
138
+
.async_write(&mut stream)
139
+
.await?;
140
+
return Ok(());
141
+
},
142
+
};
143
+
state.metrics.pushes.inc_by(status.len() as _);
144
+
let new_funcs =
145
+
status.iter().fold(0u64, |counter, &v| if v > 0 { counter + 1 } else { counter });
146
+
state.metrics.new_funcs.inc_by(new_funcs);
147
+
debug!(
148
+
"push {} funcs ended after {:?} ({new_funcs} new)",
149
+
status.len(),
150
+
start.elapsed()
151
+
);
152
+
153
+
RpcMessage::PushMetadataResult(rpc::PushMetadataResult { status: Cow::Owned(status) })
154
+
.async_write(&mut stream)
155
+
.await?;
156
+
},
157
+
RpcMessage::DelHistory(req) => {
158
+
let is_delete_allowed = state.config.lumina.allow_deletes.unwrap_or(false);
159
+
if !is_delete_allowed {
160
+
RpcMessage::Fail(rpc::RpcFail {
161
+
code: 2,
162
+
message: &format!("{server_name}: Delete command is disabled on this server."),
163
+
})
164
+
.async_write(&mut stream)
165
+
.await?;
166
+
} else {
167
+
if let Err(err) = db.delete_metadata(&req).await {
168
+
error!("delete failed. db: {err}");
169
+
RpcMessage::Fail(rpc::RpcFail {
170
+
code: 3,
171
+
message: &format!("{server_name}: db error, please try again later."),
172
+
})
173
+
.async_write(&mut stream)
174
+
.await?;
175
+
return Ok(());
176
+
}
177
+
RpcMessage::DelHistoryResult(rpc::DelHistoryResult {
178
+
deleted_mds: req.funcs.len() as u32,
179
+
})
180
+
.async_write(&mut stream)
181
+
.await?;
182
+
}
183
+
},
184
+
RpcMessage::GetFuncHistories(req) => {
185
+
let limit = state.config.lumina.get_history_limit.unwrap_or(0);
186
+
187
+
if limit == 0 {
188
+
RpcMessage::Fail(rpc::RpcFail {
189
+
code: 4,
190
+
message: &format!(
191
+
"{server_name}: function histories are disabled on this server."
192
+
),
193
+
})
194
+
.async_write(&mut stream)
195
+
.await?;
196
+
return Ok(());
197
+
}
198
+
199
+
let mut statuses = vec![];
200
+
let mut res = vec![];
201
+
for chksum in req.funcs.iter().map(|v| v.mb_hash) {
202
+
let history = match db.get_func_histories(chksum, limit).await {
203
+
Ok(v) => v,
204
+
Err(err) => {
205
+
error!("failed to get function histories: {err:?}");
206
+
RpcMessage::Fail(rpc::RpcFail {
207
+
code: 3,
208
+
message: &format!("{server_name}: db error, please try again later."),
209
+
})
210
+
.async_write(&mut stream)
211
+
.await?;
212
+
return Ok(());
213
+
},
214
+
};
215
+
let status = !history.is_empty() as u32;
216
+
statuses.push(status);
217
+
if history.is_empty() {
218
+
continue;
219
+
}
220
+
let log = history
221
+
.into_iter()
222
+
.map(|(updated, name, metadata)| rpc::FunctionHistory {
223
+
unk0: 0,
224
+
unk1: 0,
225
+
name: Cow::Owned(name),
226
+
metadata: Cow::Owned(metadata),
227
+
timestamp: updated.unix_timestamp() as u64,
228
+
author_idx: 0,
229
+
idb_path_idx: 0,
230
+
})
231
+
.collect::<Vec<_>>();
232
+
res.push(rpc::FunctionHistories { log: Cow::Owned(log) });
233
+
}
234
+
235
+
trace!("returning {} histories", res.len());
236
+
237
+
RpcMessage::GetFuncHistoriesResult(rpc::GetFuncHistoriesResult {
238
+
status: statuses.into(),
239
+
funcs: Cow::Owned(res),
240
+
users: vec![].into(),
241
+
dbs: vec![].into(),
242
+
})
243
+
.async_write(&mut stream)
244
+
.await?;
245
+
},
246
+
_ => {
247
+
RpcMessage::Fail(rpc::RpcFail {
248
+
code: 0,
249
+
message: &format!("{server_name}: invalid data.\n"),
250
+
})
251
+
.async_write(&mut stream)
252
+
.await?;
253
+
},
254
+
}
255
+
Ok(())
256
+
}
257
+
258
+
async fn handle_client<S: AsyncRead + AsyncWrite + Unpin>(
259
+
state: &SharedState, mut stream: S,
260
+
) -> Result<(), rpc::Error> {
261
+
let server_name = &state.server_name;
262
+
let hello = match timeout(Duration::from_secs(15), rpc::read_packet(&mut stream)).await {
263
+
Ok(v) => v?,
264
+
Err(_) => {
265
+
debug!("didn't get hello in time.");
266
+
return Ok(());
267
+
},
268
+
};
269
+
270
+
let (hello, creds) = match RpcMessage::deserialize(&hello) {
271
+
Ok(RpcMessage::Hello(v, creds)) => {
272
+
debug!("hello protocol={}, login creds: {creds:?}", v.protocol_version);
273
+
(v, creds)
274
+
},
275
+
_ => {
276
+
// send error
277
+
error!("got bad hello message");
278
+
279
+
let resp = rpc::RpcFail { code: 0, message: &format!("{server_name}: bad sequence.") };
280
+
let resp = rpc::RpcMessage::Fail(resp);
281
+
resp.async_write(&mut stream).await?;
282
+
283
+
return Ok(());
284
+
},
285
+
};
286
+
state
287
+
.metrics
288
+
.lumina_version
289
+
.get_or_create(&LuminaVersion { protocol_version: hello.protocol_version })
290
+
.inc();
291
+
292
+
if let Some(ref creds) = creds {
293
+
if creds.username != "guest" {
294
+
// Only allow "guest" to connect for now.
295
+
rpc::RpcMessage::Fail(rpc::RpcFail {
296
+
code: 1,
297
+
message: &format!("{server_name}: invalid username or password. Try logging in with `guest` instead."),
298
+
}).async_write(&mut stream).await?;
299
+
return Ok(());
300
+
}
301
+
}
302
+
303
+
let resp = match hello.protocol_version {
304
+
0..=4 => rpc::RpcMessage::Ok(()),
305
+
306
+
// starting IDA 8.3
307
+
5.. => {
308
+
let mut features = 0;
309
+
310
+
if state.config.lumina.allow_deletes.unwrap_or(false) {
311
+
features |= 0x02;
312
+
}
313
+
314
+
rpc::RpcMessage::HelloResult(HelloResult { features, ..Default::default() })
315
+
},
316
+
};
317
+
resp.async_write(&mut stream).await?;
318
+
319
+
loop {
320
+
handle_transaction(state, &hello, &mut stream).await?;
321
+
}
322
+
}
323
+
324
+
async fn handle_connection<S: AsyncRead + AsyncWrite + Unpin>(state: &SharedState, s: S) {
325
+
if let Err(err) = handle_client(state, s).await {
326
+
if discriminant(&err) != discriminant(&Error::Eof) {
327
+
warn!("err: {}", err);
328
+
}
329
+
}
330
+
}
331
+
332
+
async fn serve(
333
+
listener: TcpListener, accpt: Option<tokio_native_tls::TlsAcceptor>, state: SharedState,
334
+
mut shutdown_signal: tokio::sync::oneshot::Receiver<()>,
335
+
) {
336
+
let accpt = accpt.map(Arc::new);
337
+
338
+
let (async_drop, worker) = AsyncDropper::new();
339
+
tokio::task::spawn(worker);
340
+
341
+
let connections = Arc::new(tokio::sync::Mutex::new(HashMap::<
342
+
std::net::SocketAddr,
343
+
tokio::task::JoinHandle<()>,
344
+
>::new()));
345
+
346
+
loop {
347
+
let (client, addr) = tokio::select! {
348
+
_ = &mut shutdown_signal => {
349
+
drop(state);
350
+
info!("shutting down...");
351
+
let m = connections.lock().await;
352
+
m.iter().for_each(|(k, v)| {
353
+
debug!("aborting task for {k}...");
354
+
v.abort();
355
+
});
356
+
return;
357
+
},
358
+
res = listener.accept() => match res {
359
+
Ok(v) => v,
360
+
Err(err) => {
361
+
warn!("failed to accept(): {}", err);
362
+
continue;
363
+
}
364
+
},
365
+
};
366
+
367
+
let start = Instant::now();
368
+
369
+
let state = state.clone();
370
+
let accpt = accpt.clone();
371
+
372
+
let conns2 = connections.clone();
373
+
let counter = state.metrics.active_connections.clone();
374
+
let guard = async_drop.defer(async move {
375
+
let count = counter.dec() - 1;
376
+
debug!(
377
+
"connection with {:?} ended after {:?}; {} active connections",
378
+
addr,
379
+
start.elapsed(),
380
+
count
381
+
);
382
+
383
+
let mut guard = conns2.lock().await;
384
+
if guard.remove(&addr).is_none() {
385
+
error!("Couldn't remove connection from set {addr}");
386
+
}
387
+
});
388
+
389
+
let counter = state.metrics.active_connections.clone();
390
+
let handle = tokio::spawn(async move {
391
+
let _guard = guard;
392
+
let count = { counter.inc() + 1 };
393
+
let protocol = if accpt.is_some() { " [TLS]" } else { "" };
394
+
debug!("Connection from {:?}{}: {} active connections", &addr, protocol, count);
395
+
match accpt {
396
+
Some(accpt) => {
397
+
match timeout(Duration::from_secs(10), accpt.accept(client)).await {
398
+
Ok(r) => match r {
399
+
Ok(s) => {
400
+
handle_connection(&state, s).await;
401
+
},
402
+
Err(err) => debug!("tls accept ({}): {}", &addr, err),
403
+
},
404
+
Err(_) => {
405
+
debug!("client {} didn't complete ssl handshake in time.", &addr);
406
+
},
407
+
};
408
+
},
409
+
None => handle_connection(&state, client).await,
410
+
}
411
+
});
412
+
413
+
let mut guard = connections.lock().await;
414
+
guard.insert(addr, handle);
415
+
}
416
+
}
417
+
418
+
pub(crate) async fn do_lumen(config: Arc<Config>) {
419
+
info!("starting private lumen server...");
420
+
421
+
let db = match Database::open(&config.database).await {
422
+
Ok(v) => v,
423
+
Err(err) => {
424
+
error!("failed to open database: {}", err);
425
+
exit(1);
426
+
},
427
+
};
428
+
429
+
let server_name = config.lumina.server_name.clone().unwrap_or_else(|| String::from("lumen"));
430
+
431
+
let state = Arc::new(SharedState_ {
432
+
db,
433
+
config,
434
+
server_name,
435
+
metrics: common::metrics::Metrics::default(),
436
+
});
437
+
438
+
let tls_acceptor;
439
+
440
+
if state.config.lumina.use_tls.unwrap_or_default() {
441
+
let cert_path =
442
+
&state.config.lumina.tls.as_ref().expect("tls section is missing").server_cert;
443
+
let mut crt = match std::fs::read(cert_path) {
444
+
Ok(v) => v,
445
+
Err(err) => {
446
+
error!("failed to read certificate file: {}", err);
447
+
exit(1);
448
+
},
449
+
};
450
+
let pkcs_passwd = std::env::var("PKCSPASSWD").unwrap_or_default();
451
+
let id = match Identity::from_pkcs12(&crt, &pkcs_passwd) {
452
+
Ok(v) => v,
453
+
Err(err) => {
454
+
error!("failed to parse tls certificate: {}", err);
455
+
exit(1);
456
+
},
457
+
};
458
+
let _ = pkcs_passwd;
459
+
crt.iter_mut().for_each(|v| *v = 0);
460
+
let _ = crt;
461
+
let mut accpt = native_tls::TlsAcceptor::builder(id);
462
+
accpt.min_protocol_version(Some(native_tls::Protocol::Sslv3));
463
+
let accpt = match accpt.build() {
464
+
Ok(v) => v,
465
+
Err(err) => {
466
+
error!("failed to build tls acceptor: {}", err);
467
+
exit(1);
468
+
},
469
+
};
470
+
let accpt = tokio_native_tls::TlsAcceptor::from(accpt);
471
+
tls_acceptor = Some(accpt);
472
+
} else {
473
+
tls_acceptor = None;
474
+
}
475
+
476
+
let web_handle = if let Some(ref webcfg) = state.config.api_server {
477
+
let bind_addr = webcfg.bind_addr;
478
+
let state = state.clone();
479
+
info!("starting http api server on {:?}", &bind_addr);
480
+
Some(tokio::spawn(async move {
481
+
web::start_webserver(bind_addr, state).await;
482
+
}))
483
+
} else {
484
+
None
485
+
};
486
+
487
+
let (exit_signal_tx, exit_signal_rx) = tokio::sync::oneshot::channel::<()>();
488
+
489
+
let async_server = async move {
490
+
let server = match TcpListener::bind(state.config.lumina.bind_addr).await {
491
+
Ok(v) => v,
492
+
Err(err) => {
493
+
error!("failed to bind server port: {}", err);
494
+
exit(1);
495
+
},
496
+
};
497
+
498
+
info!("listening on {:?} secure={}", server.local_addr().unwrap(), tls_acceptor.is_some());
499
+
500
+
serve(server, tls_acceptor, state, exit_signal_rx).await;
501
+
};
502
+
503
+
let server_handle = tokio::task::spawn(async_server);
504
+
tokio::signal::ctrl_c().await.unwrap();
505
+
debug!("CTRL-C; exiting...");
506
+
if let Some(handle) = web_handle {
507
+
handle.abort();
508
+
}
509
+
exit_signal_tx.send(()).unwrap();
510
+
server_handle.await.unwrap();
511
+
512
+
info!("Goodbye.");
513
+
}
+33
-19
lumen/src/web.rs
+33
-19
lumen/src/web.rs
···
1
-
use std::net::SocketAddr;
2
-
3
-
use warp::{self, Filter};
4
-
use common::{SharedState, web::api::api_root};
5
-
6
-
pub async fn start_webserver<A: Into<SocketAddr> + 'static>(bind_addr: A, shared_state: SharedState) {
7
-
let root = warp::get()
8
-
.and(warp::path::end())
9
-
.map(|| warp::reply::html(include_str!("home.html")));
10
-
11
-
let api = warp::path("api")
12
-
.and(api_root(shared_state));
13
-
14
-
let routes = root
15
-
.or(api);
16
-
17
-
warp::serve(routes)
18
-
.run(bind_addr).await;
19
-
}
1
+
use std::net::SocketAddr;
2
+
3
+
use common::{web::api::api_root, SharedState};
4
+
use log::error;
5
+
use warp::{hyper::StatusCode, reply::Response, Filter};
6
+
7
+
pub async fn start_webserver<A: Into<SocketAddr> + 'static>(
8
+
bind_addr: A, shared_state: SharedState,
9
+
) {
10
+
let root =
11
+
warp::get().and(warp::path::end()).map(|| warp::reply::html(include_str!("home.html")));
12
+
13
+
let shared_state1 = shared_state.clone();
14
+
let api = warp::path("api").and(api_root(shared_state1));
15
+
16
+
let metrics = warp::get().and(warp::path("metrics")).and(warp::path::end()).map(move || {
17
+
let mut res = String::new();
18
+
if let Err(err) =
19
+
prometheus_client::encoding::text::encode(&mut res, &shared_state.metrics.registry)
20
+
{
21
+
error!("failed to encode metrics: {err}");
22
+
let mut r = Response::default();
23
+
*r.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
24
+
r
25
+
} else {
26
+
warp::reply::Response::new(res.into())
27
+
}
28
+
});
29
+
30
+
let routes = root.or(api).or(metrics);
31
+
32
+
warp::serve(routes).run(bind_addr).await;
33
+
}
+5
rustfmt.toml
+5
rustfmt.toml
-39
schema.sql
-39
schema.sql
···
1
-
CREATE TABLE users (
2
-
id SERIAL PRIMARY KEY,
3
-
lic_id bytea,
4
-
lic_data bytea,
5
-
hostname VARCHAR(260),
6
-
first_seen TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
7
-
);
8
-
CREATE UNIQUE INDEX user_rec ON users(lic_id,lic_data,hostname);
9
-
CREATE UNIQUE INDEX user_hn_null ON users (lic_id,lic_data, (hostname IS NULL)) WHERE hostname is NULL;
10
-
11
-
CREATE TABLE files (
12
-
id SERIAL PRIMARY KEY,
13
-
chksum bytea UNIQUE /* file chksum */
14
-
);
15
-
16
-
CREATE TABLE dbs (
17
-
id SERIAL PRIMARY KEY,
18
-
file_path VARCHAR(260),
19
-
idb_path VARCHAR(260),
20
-
file_id INTEGER REFERENCES files(id),
21
-
user_id INTEGER REFERENCES users(id)
22
-
);
23
-
CREATE UNIQUE INDEX db_paths ON dbs(file_id, user_id, idb_path);
24
-
25
-
CREATE TABLE funcs (
26
-
id SERIAL PRIMARY KEY,
27
-
name TEXT NOT NULL,
28
-
len INTEGER NOT NULL,
29
-
db_id INTEGER REFERENCES dbs(id) NOT NULL,
30
-
chksum bytea, /* function chksum */
31
-
metadata bytea,
32
-
rank INTEGER,
33
-
34
-
push_dt TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
35
-
update_dt TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
36
-
);
37
-
CREATE UNIQUE INDEX funcs_db ON funcs(chksum, db_id);
38
-
CREATE INDEX funcs_ranking ON funcs(chksum,rank);
39
-
CREATE INDEX func_chksum ON funcs(chksum);