Browse Source

Complete support for server processing

Samir Menon 2 years ago
parent
commit
82f72c64b1

+ 3 - 3
client/src/lib.rs

@@ -56,11 +56,11 @@ pub fn initialize(json_params: Option<String>) -> WrappedClient {
         'nu_1': 10,
         'nu_2': 6,
         'p': 512,
-        'q_prime_bits': 21,
+        'q2_bits': 21,
         's_e': 85.83255142749422,
-        't_GSW': 10,
+        't_gsw': 10,
         't_conv': 4,
-        't_exp': 16,
+        't_exp_left': 16,
         't_exp_right': 56,
         'instances': 11,
         'db_item_size': 100000 }

+ 661 - 6
spiral-rs/Cargo.lock

@@ -2,6 +2,205 @@
 # It is not intended for manual editing.
 version = 3
 
+[[package]]
+name = "actix-codec"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "57a7559404a7f3573127aab53c08ce37a6c6a315c374a31070f3c91cd1b4a7fe"
+dependencies = [
+ "bitflags",
+ "bytes",
+ "futures-core",
+ "futures-sink",
+ "log",
+ "memchr",
+ "pin-project-lite",
+ "tokio",
+ "tokio-util 0.7.1",
+]
+
+[[package]]
+name = "actix-http"
+version = "3.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a5885cb81a0d4d0d322864bea1bb6c2a8144626b4fdc625d4c51eba197e7797a"
+dependencies = [
+ "actix-codec",
+ "actix-rt",
+ "actix-service",
+ "actix-tls",
+ "actix-utils",
+ "ahash",
+ "base64",
+ "bitflags",
+ "brotli",
+ "bytes",
+ "bytestring",
+ "derive_more",
+ "encoding_rs",
+ "flate2",
+ "futures-core",
+ "h2",
+ "http",
+ "httparse",
+ "httpdate",
+ "itoa 1.0.1",
+ "language-tags",
+ "local-channel",
+ "log",
+ "mime",
+ "percent-encoding",
+ "pin-project-lite",
+ "rand",
+ "sha-1",
+ "smallvec",
+ "zstd",
+]
+
+[[package]]
+name = "actix-macros"
+version = "0.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "465a6172cf69b960917811022d8f29bc0b7fa1398bc4f78b3c466673db1213b6"
+dependencies = [
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "actix-router"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "eb60846b52c118f2f04a56cc90880a274271c489b2498623d58176f8ca21fa80"
+dependencies = [
+ "bytestring",
+ "firestorm",
+ "http",
+ "log",
+ "regex",
+ "serde",
+]
+
+[[package]]
+name = "actix-rt"
+version = "2.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7ea16c295198e958ef31930a6ef37d0fb64e9ca3b6116e6b93a8bdae96ee1000"
+dependencies = [
+ "futures-core",
+ "tokio",
+]
+
+[[package]]
+name = "actix-server"
+version = "2.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0da34f8e659ea1b077bb4637948b815cd3768ad5a188fdcd74ff4d84240cd824"
+dependencies = [
+ "actix-rt",
+ "actix-service",
+ "actix-utils",
+ "futures-core",
+ "futures-util",
+ "mio",
+ "num_cpus",
+ "socket2",
+ "tokio",
+ "tracing",
+]
+
+[[package]]
+name = "actix-service"
+version = "2.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3b894941f818cfdc7ccc4b9e60fa7e53b5042a2e8567270f9147d5591893373a"
+dependencies = [
+ "futures-core",
+ "paste",
+ "pin-project-lite",
+]
+
+[[package]]
+name = "actix-tls"
+version = "3.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9fde0cf292f7cdc7f070803cb9a0d45c018441321a78b1042ffbbb81ec333297"
+dependencies = [
+ "actix-codec",
+ "actix-rt",
+ "actix-service",
+ "actix-utils",
+ "futures-core",
+ "log",
+ "openssl",
+ "pin-project-lite",
+ "tokio-openssl",
+ "tokio-util 0.7.1",
+]
+
+[[package]]
+name = "actix-utils"
+version = "3.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e491cbaac2e7fc788dfff99ff48ef317e23b3cf63dbaf7aaab6418f40f92aa94"
+dependencies = [
+ "local-waker",
+ "pin-project-lite",
+]
+
+[[package]]
+name = "actix-web"
+version = "4.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f4e5ebffd51d50df56a3ae0de0e59487340ca456f05dd0b90c0a7a6dd6a74d31"
+dependencies = [
+ "actix-codec",
+ "actix-http",
+ "actix-macros",
+ "actix-router",
+ "actix-rt",
+ "actix-server",
+ "actix-service",
+ "actix-tls",
+ "actix-utils",
+ "actix-web-codegen",
+ "ahash",
+ "bytes",
+ "bytestring",
+ "cfg-if",
+ "cookie",
+ "derive_more",
+ "encoding_rs",
+ "futures-core",
+ "futures-util",
+ "itoa 1.0.1",
+ "language-tags",
+ "log",
+ "mime",
+ "once_cell",
+ "pin-project-lite",
+ "regex",
+ "serde",
+ "serde_json",
+ "serde_urlencoded",
+ "smallvec",
+ "socket2",
+ "time",
+ "url",
+]
+
+[[package]]
+name = "actix-web-codegen"
+version = "4.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7525bedf54704abb1d469e88d7e7e9226df73778798a69cea5022d53b2ae91bc"
+dependencies = [
+ "actix-router",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
 [[package]]
 name = "addr2line"
 version = "0.17.0"
@@ -28,6 +227,30 @@ dependencies = [
  "version_check",
 ]
 
+[[package]]
+name = "aho-corasick"
+version = "0.7.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
+dependencies = [
+ "memchr",
+]
+
+[[package]]
+name = "alloc-no-stdlib"
+version = "2.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "35ef4730490ad1c4eae5c4325b2a95f521d023e5c885853ff7aca0a6a1631db3"
+
+[[package]]
+name = "alloc-stdlib"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "697ed7edc0f1711de49ce108c541623a0af97c6c60b2f6e2b65229847ac843c2"
+dependencies = [
+ "alloc-no-stdlib",
+]
+
 [[package]]
 name = "arrayvec"
 version = "0.4.12"
@@ -64,7 +287,7 @@ dependencies = [
  "cc",
  "cfg-if",
  "libc",
- "miniz_oxide",
+ "miniz_oxide 0.4.4",
  "object",
  "rustc-demangle",
 ]
@@ -81,6 +304,36 @@ version = "1.2.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
 
+[[package]]
+name = "block-buffer"
+version = "0.10.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324"
+dependencies = [
+ "generic-array",
+]
+
+[[package]]
+name = "brotli"
+version = "3.3.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1a0b1dbcc8ae29329621f8d4f0d835787c1c38bb1401979b49d13b0b305ff68"
+dependencies = [
+ "alloc-no-stdlib",
+ "alloc-stdlib",
+ "brotli-decompressor",
+]
+
+[[package]]
+name = "brotli-decompressor"
+version = "2.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "59ad2d4653bf5ca36ae797b1f4bb4dbddb60ce49ca4aed8a2ce4829f60425b80"
+dependencies = [
+ "alloc-no-stdlib",
+ "alloc-stdlib",
+]
+
 [[package]]
 name = "bstr"
 version = "0.2.17"
@@ -111,6 +364,15 @@ version = "1.1.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8"
 
+[[package]]
+name = "bytestring"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "90706ba19e97b90786e19dc0d5e2abd80008d99d4c0c5d1ad0b5e72cec7c494d"
+dependencies = [
+ "bytes",
+]
+
 [[package]]
 name = "cast"
 version = "0.2.7"
@@ -125,6 +387,9 @@ name = "cc"
 version = "1.0.73"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
+dependencies = [
+ "jobserver",
+]
 
 [[package]]
 name = "cfg-if"
@@ -143,6 +408,23 @@ dependencies = [
  "unicode-width",
 ]
 
+[[package]]
+name = "convert_case"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
+
+[[package]]
+name = "cookie"
+version = "0.16.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "94d4706de1b0fa5b132270cddffa8585166037822e260a944fe161acd137ca05"
+dependencies = [
+ "percent-encoding",
+ "time",
+ "version_check",
+]
+
 [[package]]
 name = "core-foundation"
 version = "0.9.3"
@@ -168,6 +450,24 @@ dependencies = [
  "cfg-if",
 ]
 
+[[package]]
+name = "cpufeatures"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "crc32fast"
+version = "1.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
+dependencies = [
+ "cfg-if",
+]
+
 [[package]]
 name = "criterion"
 version = "0.3.5"
@@ -248,6 +548,16 @@ dependencies = [
  "lazy_static",
 ]
 
+[[package]]
+name = "crypto-common"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8"
+dependencies = [
+ "generic-array",
+ "typenum",
+]
+
 [[package]]
 name = "csv"
 version = "1.1.6"
@@ -276,7 +586,30 @@ version = "0.7.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "d6ee87af31d84ef885378aebca32be3d682b0e0dc119d5b4860a2c5bb5046730"
 dependencies = [
- "uuid",
+ "uuid 0.8.2",
+]
+
+[[package]]
+name = "derive_more"
+version = "0.99.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321"
+dependencies = [
+ "convert_case",
+ "proc-macro2",
+ "quote",
+ "rustc_version",
+ "syn",
+]
+
+[[package]]
+name = "digest"
+version = "0.10.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506"
+dependencies = [
+ "block-buffer",
+ "crypto-common",
 ]
 
 [[package]]
@@ -303,6 +636,24 @@ dependencies = [
  "instant",
 ]
 
+[[package]]
+name = "firestorm"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4d3d6188b8804df28032815ea256b6955c9625c24da7525f387a7af02fbb8f01"
+
+[[package]]
+name = "flate2"
+version = "1.0.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b39522e96686d38f4bc984b9198e3a0613264abaebaff2c5c918bfa6b6da09af"
+dependencies = [
+ "cfg-if",
+ "crc32fast",
+ "libc",
+ "miniz_oxide 0.5.1",
+]
+
 [[package]]
 name = "fnv"
 version = "1.0.7"
@@ -334,6 +685,21 @@ dependencies = [
  "percent-encoding",
 ]
 
+[[package]]
+name = "futures"
+version = "0.3.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f73fe65f54d1e12b726f517d3e2135ca3125a437b6d998caf1962961f7172d9e"
+dependencies = [
+ "futures-channel",
+ "futures-core",
+ "futures-executor",
+ "futures-io",
+ "futures-sink",
+ "futures-task",
+ "futures-util",
+]
+
 [[package]]
 name = "futures-channel"
 version = "0.3.21"
@@ -341,6 +707,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010"
 dependencies = [
  "futures-core",
+ "futures-sink",
 ]
 
 [[package]]
@@ -349,12 +716,34 @@ version = "0.3.21"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3"
 
+[[package]]
+name = "futures-executor"
+version = "0.3.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9420b90cfa29e327d0429f19be13e7ddb68fa1cccb09d65e5706b8c7a749b8a6"
+dependencies = [
+ "futures-core",
+ "futures-task",
+ "futures-util",
+]
+
 [[package]]
 name = "futures-io"
 version = "0.3.21"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b"
 
+[[package]]
+name = "futures-macro"
+version = "0.3.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
 [[package]]
 name = "futures-sink"
 version = "0.3.21"
@@ -373,8 +762,11 @@ version = "0.3.21"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a"
 dependencies = [
+ "futures-channel",
  "futures-core",
  "futures-io",
+ "futures-macro",
+ "futures-sink",
  "futures-task",
  "memchr",
  "pin-project-lite",
@@ -382,6 +774,16 @@ dependencies = [
  "slab",
 ]
 
+[[package]]
+name = "generic-array"
+version = "0.14.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803"
+dependencies = [
+ "typenum",
+ "version_check",
+]
+
 [[package]]
 name = "getrandom"
 version = "0.2.6"
@@ -416,7 +818,7 @@ dependencies = [
  "indexmap",
  "slab",
  "tokio",
- "tokio-util",
+ "tokio-util 0.6.9",
  "tracing",
 ]
 
@@ -587,6 +989,15 @@ version = "1.0.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
 
+[[package]]
+name = "jobserver"
+version = "0.1.24"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa"
+dependencies = [
+ "libc",
+]
+
 [[package]]
 name = "js-sys"
 version = "0.3.56"
@@ -596,6 +1007,12 @@ dependencies = [
  "wasm-bindgen",
 ]
 
+[[package]]
+name = "language-tags"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388"
+
 [[package]]
 name = "lazy_static"
 version = "1.4.0"
@@ -608,6 +1025,24 @@ version = "0.2.122"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "ec647867e2bf0772e28c8bcde4f0d19a9216916e890543b5a03ed8ef27b8f259"
 
+[[package]]
+name = "local-channel"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6246c68cf195087205a0512559c97e15eaf95198bf0e206d662092cdcb03fe9f"
+dependencies = [
+ "futures-core",
+ "futures-sink",
+ "futures-util",
+ "local-waker",
+]
+
+[[package]]
+name = "local-waker"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "902eb695eb0591864543cbfbf6d742510642a605a61fc5e97fe6ceb5a30ac4fb"
+
 [[package]]
 name = "lock_api"
 version = "0.4.7"
@@ -673,6 +1108,15 @@ dependencies = [
  "autocfg",
 ]
 
+[[package]]
+name = "miniz_oxide"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d2b29bd4bc3f33391105ebee3589c19197c4271e3e5a9ec9bfe8127eeff8f082"
+dependencies = [
+ "adler",
+]
+
 [[package]]
 name = "mio"
 version = "0.8.2"
@@ -771,6 +1215,15 @@ dependencies = [
  "libc",
 ]
 
+[[package]]
+name = "num_threads"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "aba1801fb138d8e85e11d0fc70baf4fe1cdfffda7c6cd34a854905df588e5ed0"
+dependencies = [
+ "libc",
+]
+
 [[package]]
 name = "object"
 version = "0.27.1"
@@ -833,7 +1286,17 @@ checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
 dependencies = [
  "instant",
  "lock_api",
- "parking_lot_core",
+ "parking_lot_core 0.8.5",
+]
+
+[[package]]
+name = "parking_lot"
+version = "0.12.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58"
+dependencies = [
+ "lock_api",
+ "parking_lot_core 0.9.2",
 ]
 
 [[package]]
@@ -850,6 +1313,25 @@ dependencies = [
  "winapi",
 ]
 
+[[package]]
+name = "parking_lot_core"
+version = "0.9.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "995f667a6c822200b0433ac218e05582f0e2efa1b922a3fd2fbaadc5f87bab37"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "redox_syscall",
+ "smallvec",
+ "windows-sys",
+]
+
+[[package]]
+name = "paste"
+version = "1.0.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0c520e05135d6e763148b6426a837e239041653ba7becd2e538c076c738025fc"
+
 [[package]]
 name = "percent-encoding"
 version = "2.1.0"
@@ -915,7 +1397,7 @@ dependencies = [
  "libc",
  "log",
  "nix",
- "parking_lot",
+ "parking_lot 0.11.2",
  "symbolic-demangle",
  "tempfile",
  "thiserror",
@@ -1024,6 +1506,8 @@ version = "1.5.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
 dependencies = [
+ "aho-corasick",
+ "memchr",
  "regex-syntax",
 ]
 
@@ -1218,6 +1702,26 @@ dependencies = [
  "serde",
 ]
 
+[[package]]
+name = "sha-1"
+version = "0.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f"
+dependencies = [
+ "cfg-if",
+ "cpufeatures",
+ "digest",
+]
+
+[[package]]
+name = "signal-hook-registry"
+version = "1.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0"
+dependencies = [
+ "libc",
+]
+
 [[package]]
 name = "slab"
 version = "0.4.5"
@@ -1244,12 +1748,16 @@ dependencies = [
 name = "spiral-rs"
 version = "0.1.0"
 dependencies = [
+ "actix-web",
  "criterion",
+ "futures",
  "getrandom",
+ "openssl",
  "pprof",
  "rand",
  "reqwest",
  "serde_json",
+ "uuid 1.0.0",
 ]
 
 [[package]]
@@ -1273,7 +1781,7 @@ dependencies = [
  "debugid",
  "memmap2",
  "stable_deref_trait",
- "uuid",
+ "uuid 0.8.2",
 ]
 
 [[package]]
@@ -1341,6 +1849,24 @@ dependencies = [
  "syn",
 ]
 
+[[package]]
+name = "time"
+version = "0.3.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c2702e08a7a860f005826c6815dcac101b19b5eb330c27fe4a5928fec1d20ddd"
+dependencies = [
+ "itoa 1.0.1",
+ "libc",
+ "num_threads",
+ "time-macros",
+]
+
+[[package]]
+name = "time-macros"
+version = "0.2.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "42657b1a6f4d817cda8e7a0ace261fe0cc946cf3a80314390b22cc61ae080792"
+
 [[package]]
 name = "tinytemplate"
 version = "1.2.1"
@@ -1377,7 +1903,10 @@ dependencies = [
  "memchr",
  "mio",
  "num_cpus",
+ "once_cell",
+ "parking_lot 0.12.0",
  "pin-project-lite",
+ "signal-hook-registry",
  "socket2",
  "winapi",
 ]
@@ -1392,6 +1921,18 @@ dependencies = [
  "tokio",
 ]
 
+[[package]]
+name = "tokio-openssl"
+version = "0.6.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c08f9ffb7809f1b20c1b398d92acf4cc719874b3b2b2d9ea2f09b4a80350878a"
+dependencies = [
+ "futures-util",
+ "openssl",
+ "openssl-sys",
+ "tokio",
+]
+
 [[package]]
 name = "tokio-util"
 version = "0.6.9"
@@ -1406,6 +1947,20 @@ dependencies = [
  "tokio",
 ]
 
+[[package]]
+name = "tokio-util"
+version = "0.7.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0edfdeb067411dba2044da6d1cb2df793dd35add7888d73c16e3381ded401764"
+dependencies = [
+ "bytes",
+ "futures-core",
+ "futures-sink",
+ "pin-project-lite",
+ "tokio",
+ "tracing",
+]
+
 [[package]]
 name = "tower-service"
 version = "0.3.1"
@@ -1419,10 +1974,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "4a1bdf54a7c28a2bbf701e1d2233f6c77f473486b94bee4f9678da5a148dca7f"
 dependencies = [
  "cfg-if",
+ "log",
  "pin-project-lite",
+ "tracing-attributes",
  "tracing-core",
 ]
 
+[[package]]
+name = "tracing-attributes"
+version = "0.1.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2e65ce065b4b5c53e73bb28912318cb8c9e9ad3921f1d669eb0e68b4c8143a2b"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
 [[package]]
 name = "tracing-core"
 version = "0.1.23"
@@ -1438,6 +2006,12 @@ version = "0.2.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
 
+[[package]]
+name = "typenum"
+version = "1.15.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
+
 [[package]]
 name = "unicode-bidi"
 version = "0.3.7"
@@ -1483,6 +2057,15 @@ version = "0.8.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
 
+[[package]]
+name = "uuid"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8cfcd319456c4d6ea10087ed423473267e1a071f3bc0aa89f80d60997843c6f0"
+dependencies = [
+ "getrandom",
+]
+
 [[package]]
 name = "vcpkg"
 version = "0.2.15"
@@ -1635,6 +2218,49 @@ version = "0.4.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
 
+[[package]]
+name = "windows-sys"
+version = "0.34.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5acdd78cb4ba54c0045ac14f62d8f94a03d10047904ae2a40afa1e99d8f70825"
+dependencies = [
+ "windows_aarch64_msvc",
+ "windows_i686_gnu",
+ "windows_i686_msvc",
+ "windows_x86_64_gnu",
+ "windows_x86_64_msvc",
+]
+
+[[package]]
+name = "windows_aarch64_msvc"
+version = "0.34.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "17cffbe740121affb56fad0fc0e421804adf0ae00891205213b5cecd30db881d"
+
+[[package]]
+name = "windows_i686_gnu"
+version = "0.34.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2564fde759adb79129d9b4f54be42b32c89970c18ebf93124ca8870a498688ed"
+
+[[package]]
+name = "windows_i686_msvc"
+version = "0.34.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9cd9d32ba70453522332c14d38814bceeb747d80b3958676007acadd7e166956"
+
+[[package]]
+name = "windows_x86_64_gnu"
+version = "0.34.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cfce6deae227ee8d356d19effc141a509cc503dfd1f850622ec4b0f84428e1f4"
+
+[[package]]
+name = "windows_x86_64_msvc"
+version = "0.34.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d19538ccc21819d01deaf88d6a17eae6596a12e9aafdbb97916fb49896d89de9"
+
 [[package]]
 name = "winreg"
 version = "0.10.1"
@@ -1643,3 +2269,32 @@ checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d"
 dependencies = [
  "winapi",
 ]
+
+[[package]]
+name = "zstd"
+version = "0.10.0+zstd.1.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3b1365becbe415f3f0fcd024e2f7b45bacfb5bdd055f0dc113571394114e7bdd"
+dependencies = [
+ "zstd-safe",
+]
+
+[[package]]
+name = "zstd-safe"
+version = "4.1.4+zstd.1.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2f7cd17c9af1a4d6c24beb1cc54b17e2ef7b593dc92f19e9d9acad8b182bbaee"
+dependencies = [
+ "libc",
+ "zstd-sys",
+]
+
+[[package]]
+name = "zstd-sys"
+version = "1.6.3+zstd.1.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fc49afa5c8d634e75761feda8c592051e7eeb4683ba827211eb0d731d3402ea8"
+dependencies = [
+ "cc",
+ "libc",
+]

+ 11 - 0
spiral-rs/Cargo.toml

@@ -3,11 +3,22 @@ name = "spiral-rs"
 version = "0.1.0"
 edition = "2021"
 
+[features]
+server = ["actix-web", "openssl", "futures", "uuid"]
+
+[[bin]]
+name = "server"
+required-features = ["server"]
+
 [dependencies]
 getrandom = { features = ["js"], version = "0.2.6" }
 rand = { version = "0.8.5", features = ["small_rng"] }
 reqwest = { version = "0.11", features = ["blocking"] }
 serde_json = "1.0"
+actix-web = { version = "4.0.1", features = ["openssl"], optional = true }
+openssl = { version = "0.10", features = ["v110"], optional = true }
+futures = { version = "0.3", optional = true }
+uuid = { version = "1.0.0", features = ["v4"], optional = true }
 
 [dev-dependencies]
 criterion = { version = "0.3", features = ["html_reports"] }

+ 15 - 0
spiral-rs/src/aligned_memory.rs

@@ -31,6 +31,18 @@ impl<const ALIGN: usize> AlignedMemory<{ ALIGN }> {
         }
     }
 
+    // pub fn from(data: &[u8]) -> Self {
+    //     let sz_u64 = (data.len() + size_of::<u64>() - 1) / size_of::<u64>();
+    //     let mut out = Self::new(sz_u64);
+    //     let out_slice = out.as_mut_slice();
+    //     let mut i = 0;
+    //     for chunk in data.chunks(size_of::<u64>()) {
+    //         out_slice[i] = u64::from_ne_bytes(chunk);
+    //         i += 1;
+    //     }
+    //     out
+    // }
+
     pub fn as_slice(&self) -> &[u64] {
         unsafe { from_raw_parts(self.p, self.sz_u64) }
     }
@@ -52,6 +64,9 @@ impl<const ALIGN: usize> AlignedMemory<{ ALIGN }> {
     }
 }
 
+unsafe impl<const ALIGN: usize> Send for AlignedMemory<{ ALIGN }> {}
+unsafe impl<const ALIGN: usize> Sync for AlignedMemory<{ ALIGN }> {}
+
 impl<const ALIGN: usize> Drop for AlignedMemory<{ ALIGN }> {
     fn drop(&mut self) {
         unsafe {

+ 21 - 26
spiral-rs/src/bin/client.rs

@@ -5,35 +5,29 @@ use spiral_rs::util::*;
 use std::env;
 use std::time::Instant;
 
-fn send_api_req_text(path: &str, data: Vec<u8>) -> Option<String> {
+fn send_api_req_text(api_url: &str, path: &str, data: Vec<u8>) -> Result<String, reqwest::Error> {
     let client = reqwest::blocking::Client::builder()
         .timeout(None)
         .build()
         .unwrap();
     client
-        .post(format!("https://spiralwiki.com:8088{}", path))
+        .post(format!("{}{}", api_url, path))
         .body(data)
-        .send()
-        .ok()?
+        .send()?
         .text()
-        .ok()
 }
 
-fn send_api_req_vec(path: &str, data: Vec<u8>) -> Option<Vec<u8>> {
+fn send_api_req_vec(api_url: &str, path: &str, data: Vec<u8>) -> Result<Vec<u8>, reqwest::Error> {
     let client = reqwest::blocking::Client::builder()
         .timeout(None)
         .build()
         .unwrap();
-    Some(
-        client
-            .post(format!("https://spiralwiki.com:8088{}", path))
-            .body(data)
-            .send()
-            .ok()?
-            .bytes()
-            .ok()?
-            .to_vec(),
-    )
+    Ok(client
+        .post(format!("{}{}", api_url, path))
+        .body(data)
+        .send()?
+        .bytes()?
+        .to_vec())
 }
 
 fn main() {
@@ -42,26 +36,26 @@ fn main() {
         'nu_1': 10,
         'nu_2': 6,
         'p': 512,
-        'q_prime_bits': 21,
+        'q2_bits': 21,
         's_e': 85.83255142749422,
-        't_GSW': 10,
+        't_gsw': 10,
         't_conv': 4,
-        't_exp': 16,
+        't_exp_left': 16,
         't_exp_right': 56,
         'instances': 11,
         'db_item_size': 100000 }
     "#;
     let _cfg_direct = r#"
-        {'kinda_direct_upload': 1,
+        {'direct_upload': 1,
         'n': 5,
         'nu_1': 11,
         'nu_2': 3,
         'p': 65536,
-        'q_prime_bits': 27,
+        'q2_bits': 27,
         's_e': 57.793748020122216,
-        't_GSW': 3,
+        't_gsw': 3,
         't_conv': 56,
-        't_exp': 56,
+        't_exp_left': 56,
         't_exp_right': 56}
     "#;
     let cfg = cfg_expand;
@@ -69,7 +63,8 @@ fn main() {
     let params = params_from_json(&cfg);
 
     let args: Vec<String> = env::args().collect();
-    let idx_target: usize = (&args[1]).parse().unwrap();
+    let api_url = &args[1];
+    let idx_target: usize = (&args[2]).parse().unwrap();
 
     println!("initializing client");
     let mut rng = thread_rng();
@@ -82,7 +77,7 @@ fn main() {
     let mut query_buf = query.serialize();
     println!("initial query size {}", query_buf.len());
 
-    let setup_resp_str = send_api_req_text("/setup", pub_params_buf).unwrap();
+    let setup_resp_str = send_api_req_text(api_url, "/setup", pub_params_buf).unwrap();
     println!("{}", setup_resp_str);
     let resp_json: Value = serde_json::from_str(&setup_resp_str).unwrap();
     let id = resp_json["id"].as_str().unwrap();
@@ -90,7 +85,7 @@ fn main() {
     full_query_buf.append(&mut query_buf);
 
     let now = Instant::now();
-    let query_resp = send_api_req_vec("/query", full_query_buf).unwrap();
+    let query_resp = send_api_req_vec(api_url, "/query", full_query_buf).unwrap();
     let duration = now.elapsed().as_millis();
     println!("duration of query processing is {} ms", duration);
     println!("query_resp len {}", query_resp.len());

+ 159 - 0
spiral-rs/src/bin/server.rs

@@ -0,0 +1,159 @@
+use actix_web::error::PayloadError;
+use futures::StreamExt;
+use spiral_rs::aligned_memory::*;
+use spiral_rs::client::*;
+use spiral_rs::params::*;
+use spiral_rs::server::*;
+use spiral_rs::util::*;
+use std::collections::HashMap;
+use std::env;
+use std::fs::File;
+use std::sync::Mutex;
+
+use actix_web::{get, http, post, web, App, HttpServer};
+use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
+
+const CERT_FNAME: &str = "/etc/letsencrypt/live/spiralwiki.com/fullchain.pem";
+const KEY_FNAME: &str = "/etc/letsencrypt/live/spiralwiki.com/privkey.pem";
+
+struct ServerState<'a> {
+    params: &'a Params,
+    db: AlignedMemory64,
+    pub_params_map: Mutex<HashMap<String, PublicParameters<'a>>>,
+}
+
+async fn get_request_bytes(
+    mut body: web::Payload,
+    sz_bytes: usize,
+) -> Result<Vec<u8>, http::Error> {
+    let mut bytes = web::BytesMut::new();
+    while let Some(item) = body.next().await {
+        bytes.extend_from_slice(&item?);
+        if bytes.len() > sz_bytes {
+            println!("too big! {}", sz_bytes);
+            return Err(PayloadError::Overflow.into());
+        }
+    }
+    Ok(bytes.to_vec())
+}
+
+fn get_other_io_err() -> PayloadError {
+    PayloadError::Io(std::io::Error::from(std::io::ErrorKind::Other))
+}
+
+fn other_io_err<T>(_: T) -> PayloadError {
+    get_other_io_err()
+}
+
+fn get_not_found_err() -> PayloadError {
+    PayloadError::Io(std::io::Error::from(std::io::ErrorKind::NotFound))
+}
+
+#[get("/")]
+async fn index<'a>(data: web::Data<ServerState<'a>>) -> String {
+    format!("Hello {} {}!", data.params.poly_len, data.db.as_slice()[5])
+}
+
+#[post("/setup")]
+async fn setup<'a>(
+    body: web::Payload,
+    data: web::Data<ServerState<'a>>,
+) -> Result<String, http::Error> {
+    println!("/setup");
+
+    // Parse the request
+    let request_bytes = get_request_bytes(body, data.params.setup_bytes()).await?;
+    let pub_params = PublicParameters::deserialize(data.params, request_bytes.as_slice());
+
+    // Generate a UUID and store it
+    let uuid = uuid::Uuid::new_v4();
+    let mut pub_params_map = data.pub_params_map.lock().map_err(other_io_err)?;
+    pub_params_map.insert(uuid.to_string(), pub_params);
+
+    Ok(format!("{{\"id\":\"{}\"}}", uuid.to_string()))
+}
+
+const UUID_V4_STR_BYTES: usize = 36;
+
+#[post("/query")]
+async fn query<'a>(
+    body: web::Payload,
+    data: web::Data<ServerState<'a>>,
+) -> Result<Vec<u8>, http::Error> {
+    println!("/query");
+
+    // Parse the UUID
+    let request_bytes =
+        get_request_bytes(body, UUID_V4_STR_BYTES + data.params.query_bytes()).await?;
+    let uuid_bytes = &request_bytes.as_slice()[..UUID_V4_STR_BYTES];
+    let data_bytes = &request_bytes.as_slice()[UUID_V4_STR_BYTES..];
+    let uuid =
+        uuid::Uuid::try_parse_ascii(uuid_bytes).map_err(|_| PayloadError::EncodingCorrupted)?;
+
+    // Look up UUID and get public parameters
+    let pub_params_map = data.pub_params_map.lock().map_err(other_io_err)?;
+    let pub_params = pub_params_map
+        .get(&uuid.to_string())
+        .ok_or(get_not_found_err())?;
+
+    // Parse the query
+    let query = Query::deserialize(data.params, data_bytes);
+
+    // Process the query
+    let result = process_query(data.params, pub_params, &query, data.db.as_slice());
+
+    Ok(result)
+}
+
+#[actix_web::main]
+async fn main() -> std::io::Result<()> {
+    let args: Vec<String> = env::args().collect();
+    let db_preprocessed_path = &args[1];
+
+    let cfg_expand = r#"
+        {'n': 2,
+        'nu_1': 10,
+        'nu_2': 6,
+        'p': 512,
+        'q2_bits': 21,
+        's_e': 85.83255142749422,
+        't_gsw': 10,
+        't_conv': 4,
+        't_exp_left': 16,
+        't_exp_right': 56,
+        'instances': 11,
+        'db_item_size': 100000 }
+    "#;
+    let box_params = Box::new(params_from_json(&cfg_expand.replace("'", "\"")));
+    let params: &'static Params = Box::leak(box_params);
+
+    let mut file = File::open(db_preprocessed_path).unwrap();
+    let db = load_preprocessed_db_from_file(params, &mut file);
+
+    let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap();
+    builder
+        .set_private_key_file(KEY_FNAME, SslFiletype::PEM)
+        .unwrap();
+    builder.set_certificate_chain_file(CERT_FNAME).unwrap();
+
+    let server_state = ServerState {
+        params: params,
+        db: db,
+        pub_params_map: Mutex::new(HashMap::new()),
+    };
+    let state = web::Data::new(server_state);
+
+    let res = HttpServer::new(move || {
+        App::new()
+            .app_data(state.clone())
+            .service(index)
+            .service(setup)
+            .service(query)
+    })
+    .bind_openssl("0.0.0.0:8088", builder)?
+    // .bind_openssl("127.0.0.1:7777", builder)?
+    .run()
+    .await;
+
+    res
+}

+ 147 - 11
spiral-rs/src/client.rs

@@ -2,7 +2,20 @@ use crate::{
     arith::*, discrete_gaussian::*, gadget::*, number_theory::*, params::*, poly::*, util::*,
 };
 use rand::Rng;
-use std::iter::once;
+use std::{iter::once, mem::size_of};
+
+fn new_vec_raw<'a>(
+    params: &'a Params,
+    num: usize,
+    rows: usize,
+    cols: usize,
+) -> Vec<PolyMatrixRaw<'a>> {
+    let mut v = Vec::with_capacity(num);
+    for _ in 0..num {
+        v.push(PolyMatrixRaw::zero(params, rows, cols));
+    }
+    v
+}
 
 fn serialize_polymatrix(vec: &mut Vec<u8>, a: &PolyMatrixRaw) {
     for i in 0..a.rows * a.cols * a.params.poly_len {
@@ -16,6 +29,26 @@ fn serialize_vec_polymatrix(vec: &mut Vec<u8>, a: &Vec<PolyMatrixRaw>) {
     }
 }
 
+fn mat_sz_bytes(a: &PolyMatrixRaw) -> usize {
+    a.rows * a.cols * a.params.poly_len * size_of::<u64>()
+}
+
+fn deserialize_polymatrix(a: &mut PolyMatrixRaw, data: &[u8]) -> usize {
+    for (i, chunk) in data.chunks(size_of::<u64>()).enumerate() {
+        a.data[i] = u64::from_ne_bytes(chunk.try_into().unwrap());
+    }
+    mat_sz_bytes(a)
+}
+
+fn deserialize_vec_polymatrix(a: &mut Vec<PolyMatrixRaw>, data: &[u8]) -> usize {
+    let mut chunks = data.chunks(mat_sz_bytes(&a[0]));
+    let mut bytes_read = 0;
+    for i in 0..a.len() {
+        bytes_read += deserialize_polymatrix(&mut a[i], chunks.next().unwrap());
+    }
+    bytes_read
+}
+
 pub struct PublicParameters<'a> {
     pub v_packing: Vec<PolyMatrixNTT<'a>>, // Ws
     pub v_expansion_left: Option<Vec<PolyMatrixNTT<'a>>>,
@@ -52,6 +85,10 @@ impl<'a> PublicParameters<'a> {
         Some(v.as_ref()?.iter().map(from_ntt_alloc).collect())
     }
 
+    fn to_ntt_alloc_vec(v: &Vec<PolyMatrixRaw<'a>>) -> Option<Vec<PolyMatrixNTT<'a>>> {
+        Some(v.iter().map(to_ntt_alloc).collect())
+    }
+
     pub fn to_raw(&self) -> Vec<Option<Vec<PolyMatrixRaw>>> {
         vec![
             Self::from_ntt_alloc_vec(&self.v_packing),
@@ -70,6 +107,41 @@ impl<'a> PublicParameters<'a> {
         }
         data
     }
+
+    pub fn deserialize(params: &'a Params, data: &[u8]) -> Self {
+        assert_eq!(params.setup_bytes(), data.len());
+
+        let mut idx = 0;
+
+        let mut v_packing = new_vec_raw(params, params.n, params.n + 1, params.t_conv);
+        idx += deserialize_vec_polymatrix(&mut v_packing, &data[idx..]);
+
+        if params.expand_queries {
+            let mut v_expansion_left = new_vec_raw(params, params.g(), 2, params.t_exp_left);
+            idx += deserialize_vec_polymatrix(&mut v_expansion_left, &data[idx..]);
+
+            let mut v_expansion_right =
+                new_vec_raw(params, params.stop_round() + 1, 2, params.t_exp_right);
+            idx += deserialize_vec_polymatrix(&mut v_expansion_right, &data[idx..]);
+
+            let mut v_conversion = new_vec_raw(params, 1, 2, 2 * params.t_conv);
+            _ = deserialize_vec_polymatrix(&mut v_conversion, &data[idx..]);
+
+            Self {
+                v_packing: Self::to_ntt_alloc_vec(&v_packing).unwrap(),
+                v_expansion_left: Self::to_ntt_alloc_vec(&v_expansion_left),
+                v_expansion_right: Self::to_ntt_alloc_vec(&v_expansion_right),
+                v_conversion: Self::to_ntt_alloc_vec(&v_conversion),
+            }
+        } else {
+            Self {
+                v_packing: Self::to_ntt_alloc_vec(&v_packing).unwrap(),
+                v_expansion_left: None,
+                v_expansion_right: None,
+                v_conversion: None,
+            }
+        }
+    }
 }
 
 pub struct Query<'a> {
@@ -105,6 +177,27 @@ impl<'a> Query<'a> {
         }
         data
     }
+
+    pub fn deserialize(params: &'a Params, data: &[u8]) -> Self {
+        let mut out = Query::empty();
+        if params.expand_queries {
+            let mut ct = PolyMatrixRaw::zero(params, 2, 1);
+            deserialize_polymatrix(&mut ct, data);
+            out.ct = Some(ct);
+        } else {
+            let v_buf_bytes = params.query_v_buf_bytes();
+            let v_buf = (&data[..v_buf_bytes])
+                .chunks(size_of::<u64>())
+                .map(|x| u64::from_ne_bytes(x.try_into().unwrap()))
+                .collect();
+            out.v_buf = Some(v_buf);
+
+            let mut v_ct = new_vec_raw(params, params.db_dim_2, 2, 2 * params.t_gsw);
+            deserialize_vec_polymatrix(&mut v_ct, &data[v_buf_bytes..]);
+            out.v_ct = Some(v_ct);
+        }
+        out
+    }
 }
 
 pub struct Client<'a, TRng: Rng> {
@@ -261,16 +354,15 @@ impl<'a, TRng: Rng> Client<'a, TRng> {
         self.sk_gsw_full = matrix_with_identity(&self.sk_gsw);
         self.sk_reg_full = matrix_with_identity(&self.sk_reg);
         let sk_reg_ntt = to_ntt_alloc(&self.sk_reg);
-        let m_conv = params.m_conv();
 
         let mut pp = PublicParameters::init(params);
 
         // Params for packing
-        let gadget_conv = build_gadget(params, 1, m_conv);
+        let gadget_conv = build_gadget(params, 1, params.t_conv);
         let gadget_conv_ntt = to_ntt_alloc(&gadget_conv);
         for i in 0..params.n {
             let scaled = scalar_multiply_alloc(&sk_reg_ntt, &gadget_conv_ntt);
-            let mut ag = PolyMatrixNTT::zero(params, params.n, m_conv);
+            let mut ag = PolyMatrixNTT::zero(params, params.n, params.t_conv);
             ag.copy_into(&scaled, i, 0);
             let w = self.encrypt_matrix_gsw(&ag);
             pp.v_packing.push(w);
@@ -278,21 +370,20 @@ impl<'a, TRng: Rng> Client<'a, TRng> {
 
         if params.expand_queries {
             // Params for expansion
-
             pp.v_expansion_left = Some(self.generate_expansion_params(self.g, params.t_exp_left));
             pp.v_expansion_right =
                 Some(self.generate_expansion_params(self.stop_round + 1, params.t_exp_right));
 
             // Params for converison
-            let g_conv = build_gadget(params, 2, 2 * m_conv);
+            let g_conv = build_gadget(params, 2, 2 * params.t_conv);
             let sk_reg_ntt = self.sk_reg.ntt();
             let sk_reg_squared_ntt = &sk_reg_ntt * &sk_reg_ntt;
             pp.v_conversion = Some(Vec::from_iter(once(PolyMatrixNTT::zero(
                 params,
                 2,
-                2 * m_conv,
+                2 * params.t_conv,
             ))));
-            for i in 0..2 * m_conv {
+            for i in 0..2 * params.t_conv {
                 let sigma;
                 if i % 2 == 0 {
                     let val = g_conv.get_poly(0, i)[0];
@@ -465,7 +556,6 @@ impl<'a, TRng: Rng> Client<'a, TRng> {
         let bytes_per_chunk = f64::ceil(params.db_item_size as f64 / chunks as f64) as usize;
         let logp = log2(params.pt_modulus);
         let modp_words_per_chunk = f64::ceil((bytes_per_chunk * 8) as f64 / logp as f64) as usize;
-        println!("modp_words_per_chunk {:?}", modp_words_per_chunk);
         result.to_vec(p_bits as usize, modp_words_per_chunk)
     }
 }
@@ -502,10 +592,10 @@ mod test {
         let mut seeded_rng = get_static_seeded_rng();
         let mut client = Client::init(&params, &mut seeded_rng);
 
-        let public_params = client.generate_keys();
+        let pub_params = client.generate_keys();
 
         assert_first8(
-            public_params.v_conversion.unwrap()[0].data.as_slice(),
+            pub_params.v_conversion.unwrap()[0].data.as_slice(),
             [
                 122680182, 165987256, 137892309, 95732358, 221787731, 13233184, 156136764,
                 259944211,
@@ -526,4 +616,50 @@ mod test {
             ],
         );
     }
+
+    fn public_parameters_serialization_is_correct_for_params(params: Params) {
+        let mut seeded_rng = get_static_seeded_rng();
+        let mut client = Client::init(&params, &mut seeded_rng);
+        let pub_params = client.generate_keys();
+        assert_eq!(client.stop_round, params.stop_round());
+
+        let serialized1 = pub_params.serialize();
+        let deserialized1 = PublicParameters::deserialize(&params, &serialized1);
+        let serialized2 = deserialized1.serialize();
+
+        assert_eq!(serialized1, serialized2);
+    }
+
+    #[test]
+    fn public_parameters_serialization_is_correct() {
+        public_parameters_serialization_is_correct_for_params(get_params())
+    }
+
+    #[test]
+    fn no_expansion_public_parameters_serialization_is_correct() {
+        public_parameters_serialization_is_correct_for_params(get_no_expansion_testing_params())
+    }
+
+    fn query_serialization_is_correct_for_params(params: Params) {
+        let mut seeded_rng = get_static_seeded_rng();
+        let mut client = Client::init(&params, &mut seeded_rng);
+        _ = client.generate_keys();
+        let query = client.generate_query(1);
+
+        let serialized1 = query.serialize();
+        let deserialized1 = Query::deserialize(&params, &serialized1);
+        let serialized2 = deserialized1.serialize();
+
+        assert_eq!(serialized1, serialized2);
+    }
+
+    #[test]
+    fn query_serialization_is_correct() {
+        query_serialization_is_correct_for_params(get_params())
+    }
+
+    #[test]
+    fn no_expansion_query_serialization_is_correct() {
+        query_serialization_is_correct_for_params(get_no_expansion_testing_params())
+    }
 }

+ 51 - 3
spiral-rs/src/params.rs

@@ -1,3 +1,5 @@
+use std::mem::size_of;
+
 use crate::{arith::*, ntt::*, number_theory::*, poly::*};
 
 pub const MAX_MODULI: usize = 4;
@@ -42,7 +44,7 @@ pub static Q2_VALUES: [u64; 37] = [
     68718428161,
 ];
 
-#[derive(Debug, PartialEq)]
+#[derive(Debug, PartialEq, Clone)]
 pub struct Params {
     pub poly_len: usize,
     pub poly_len_log2: usize,
@@ -108,8 +110,54 @@ impl Params {
         (1, 1)
     }
 
-    pub fn m_conv(&self) -> usize {
-        self.t_conv
+    pub fn num_expanded(&self) -> usize {
+        1 << self.db_dim_1
+    }
+
+    pub fn g(&self) -> usize {
+        let num_bits_to_gen = self.t_gsw * self.db_dim_2 + self.num_expanded();
+        log2_ceil_usize(num_bits_to_gen)
+    }
+
+    pub fn stop_round(&self) -> usize {
+        log2_ceil_usize(self.t_gsw * self.db_dim_2)
+    }
+
+    pub fn setup_bytes(&self) -> usize {
+        let mut sz_polys = 0;
+
+        let packing_sz = (self.n + 1) * self.t_conv;
+        sz_polys += self.n * packing_sz;
+
+        if self.expand_queries {
+            let expansion_left_sz = self.g() * 2 * self.t_exp_left;
+            let expansion_right_sz = (self.stop_round() + 1) * 2 * self.t_exp_right;
+            let conversion_sz = 2 * (2 * self.t_conv);
+
+            sz_polys += expansion_left_sz + expansion_right_sz + conversion_sz;
+        }
+
+        let sz_bytes = sz_polys * self.poly_len * size_of::<u64>();
+        sz_bytes
+    }
+
+    pub fn query_bytes(&self) -> usize {
+        let sz_polys;
+
+        if self.expand_queries {
+            sz_polys = 2;
+        } else {
+            let first_dimension_sz = self.num_expanded() * 2;
+            let further_dimension_sz = self.db_dim_2 * 2 * (2 * self.t_gsw);
+            sz_polys = first_dimension_sz + further_dimension_sz;
+        }
+
+        let sz_bytes = sz_polys * self.poly_len * size_of::<u64>();
+        sz_bytes
+    }
+
+    pub fn query_v_buf_bytes(&self) -> usize {
+        self.num_expanded() * 2 * self.poly_len * size_of::<u64>()
     }
 
     pub fn crt_compose_1(&self, x: u64) -> u64 {

+ 3 - 12
spiral-rs/src/server.rs

@@ -5,7 +5,6 @@ use std::io::BufReader;
 use std::io::Read;
 use std::io::Seek;
 use std::io::SeekFrom;
-use std::mem::size_of;
 
 use crate::aligned_memory::*;
 use crate::arith::*;
@@ -330,7 +329,6 @@ pub fn generate_random_db_and_get_item<'a>(
     let db_size_words = instances * trials * num_items * params.poly_len;
     let mut v = AlignedMemory64::new(db_size_words);
 
-    let mut tmp_item_ntt = PolyMatrixNTT::zero(params, 1, 1);
     let mut item = PolyMatrixRaw::zero(params, params.n, params.n);
 
     for instance in 0..instances {
@@ -379,9 +377,6 @@ pub fn load_item_from_file<'a>(
     let db_item_size = params.db_item_size;
     let instances = params.instances;
     let trials = params.n * params.n;
-    let dim0 = 1 << params.db_dim_1;
-    let num_per = 1 << params.db_dim_2;
-    let num_items = dim0 * num_per;
 
     let chunks = instances * trials;
     let bytes_per_chunk = f64::ceil(db_item_size as f64 / chunks as f64) as usize;
@@ -469,11 +464,11 @@ pub fn load_preprocessed_db_from_file(params: &Params, file: &mut File) -> Align
     let mut v = AlignedMemory64::new(db_size_words);
     let v_mut_slice = v.as_mut_slice();
 
-    let mut reader = BufReader::new(file);
+    let mut reader = BufReader::with_capacity(1 << 18, file);
     let mut buf = [0u8; 8];
     for i in 0..db_size_words {
         if i % 1000000000 == 0 {
-            println!("{} GB loaded", i);
+            println!("{} GB loaded", i / 1000000000);
         }
         reader.read(&mut buf).unwrap();
         v_mut_slice[i] = u64::from_ne_bytes(buf);
@@ -757,11 +752,7 @@ mod test {
     const TEST_PREPROCESSED_DB_PATH: &'static str = "/home/samir/wiki/enwiki-20220320.dbp";
 
     fn get_params() -> Params {
-        let mut params = get_expansion_testing_params();
-        params.db_dim_1 = 6;
-        params.db_dim_2 = 2;
-        params.t_exp_right = 8;
-        params
+        get_fast_expansion_testing_params()
     }
 
     fn dec_reg<'a>(

+ 50 - 20
spiral-rs/src/util.rs

@@ -7,11 +7,11 @@ pub const CFG_20_256: &'static str = r#"
         'nu_1': 9,
         'nu_2': 6,
         'p': 256,
-        'q_prime_bits': 20,
+        'q2_bits': 20,
         's_e': 87.62938774292914,
-        't_GSW': 8,
+        't_gsw': 8,
         't_conv': 4,
-        't_exp': 8,
+        't_exp_left': 8,
         't_exp_right': 56,
         'instances': 1,
         'db_item_size': 8192 }
@@ -21,11 +21,11 @@ pub const CFG_16_100000: &'static str = r#"
         'nu_1': 10,
         'nu_2': 6,
         'p': 512,
-        'q_prime_bits': 21,
+        'q2_bits': 21,
         's_e': 85.83255142749422,
-        't_GSW': 10,
+        't_gsw': 10,
         't_conv': 4,
-        't_exp': 16,
+        't_exp_left': 16,
         't_exp_right': 56,
         'instances': 11,
         'db_item_size': 100000 }
@@ -87,18 +87,48 @@ pub fn get_expansion_testing_params() -> Params {
         'nu_1': 9,
         'nu_2': 6,
         'p': 256,
-        'q_prime_bits': 20,
-        's_e': 87.62938774292914,
-        't_GSW': 8,
+        'q2_bits': 20,
+        't_gsw': 8,
         't_conv': 4,
-        't_exp': 8,
+        't_exp_left': 8,
         't_exp_right': 56,
         'instances': 1,
         'db_item_size': 8192 }
     "#;
-    let cfg = cfg.replace("'", "\"");
-    let b = params_from_json(&cfg);
-    b
+    params_from_json(&cfg.replace("'", "\""))
+}
+
+pub fn get_fast_expansion_testing_params() -> Params {
+    let cfg = r#"
+        {'n': 2,
+        'nu_1': 6,
+        'nu_2': 2,
+        'p': 256,
+        'q2_bits': 20,
+        't_gsw': 8,
+        't_conv': 4,
+        't_exp_left': 8,
+        't_exp_right': 8,
+        'instances': 1,
+        'db_item_size': 8192 }
+    "#;
+    params_from_json(&cfg.replace("'", "\""))
+}
+
+pub fn get_no_expansion_testing_params() -> Params {
+    let cfg = r#"
+        {'direct_upload': 1,
+        'n': 5,
+        'nu_1': 6,
+        'nu_2': 3,
+        'p': 65536,
+        'q2_bits': 27,
+        't_gsw': 3,
+        't_conv': 56,
+        't_exp_left': 56,
+        't_exp_right': 56}
+    "#;
+    params_from_json(&cfg.replace("'", "\""))
 }
 
 pub fn get_seed() -> [u8; 32] {
@@ -160,12 +190,12 @@ pub fn params_from_json(cfg: &str) -> Params {
     let instances = v["instances"].as_u64().unwrap_or(1) as usize;
     let db_item_size = v["db_item_size"].as_u64().unwrap_or(1) as usize;
     let p = v["p"].as_u64().unwrap();
-    let q2_bits = v["q_prime_bits"].as_u64().unwrap();
-    let t_gsw = v["t_GSW"].as_u64().unwrap() as usize;
+    let q2_bits = v["q2_bits"].as_u64().unwrap();
+    let t_gsw = v["t_gsw"].as_u64().unwrap() as usize;
     let t_conv = v["t_conv"].as_u64().unwrap() as usize;
-    let t_exp_left = v["t_exp"].as_u64().unwrap() as usize;
+    let t_exp_left = v["t_exp_left"].as_u64().unwrap() as usize;
     let t_exp_right = v["t_exp_right"].as_u64().unwrap() as usize;
-    let do_expansion = v.get("kinda_direct_upload").is_none();
+    let do_expansion = v.get("direct_upload").is_none();
     Params::init(
         2048,
         &vec![268369921u64, 249561089u64],
@@ -264,11 +294,11 @@ mod test {
             'nu_1': 9,
             'nu_2': 6,
             'p': 256,
-            'q_prime_bits': 20,
+            'q2_bits': 20,
             's_e': 87.62938774292914,
-            't_GSW': 8,
+            't_gsw': 8,
             't_conv': 4,
-            't_exp': 8,
+            't_exp_left': 8,
             't_exp_right': 56,
             'instances': 1,
             'db_item_size': 2048 }