diff options
-rw-r--r-- | Cargo.lock | 41 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/db.rs | 14 | ||||
-rw-r--r-- | src/handlers.rs | 9 | ||||
-rw-r--r-- | src/student.rs | 7 |
5 files changed, 67 insertions, 5 deletions
@@ -194,6 +194,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
194 | checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" | 194 | checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" |
195 | 195 | ||
196 | [[package]] | 196 | [[package]] |
197 | name = "bstr" | ||
198 | version = "0.2.15" | ||
199 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
200 | checksum = "a40b47ad93e1a5404e6c18dec46b628214fee441c70f4ab5d6942142cc268a3d" | ||
201 | dependencies = [ | ||
202 | "lazy_static", | ||
203 | "memchr", | ||
204 | "regex-automata", | ||
205 | "serde", | ||
206 | ] | ||
207 | |||
208 | [[package]] | ||
197 | name = "buf_redux" | 209 | name = "buf_redux" |
198 | version = "0.8.4" | 210 | version = "0.8.4" |
199 | source = "registry+https://github.com/rust-lang/crates.io-index" | 211 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -294,6 +306,28 @@ dependencies = [ | |||
294 | ] | 306 | ] |
295 | 307 | ||
296 | [[package]] | 308 | [[package]] |
309 | name = "csv" | ||
310 | version = "1.1.6" | ||
311 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
312 | checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1" | ||
313 | dependencies = [ | ||
314 | "bstr", | ||
315 | "csv-core", | ||
316 | "itoa", | ||
317 | "ryu", | ||
318 | "serde", | ||
319 | ] | ||
320 | |||
321 | [[package]] | ||
322 | name = "csv-core" | ||
323 | version = "0.1.10" | ||
324 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
325 | checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" | ||
326 | dependencies = [ | ||
327 | "memchr", | ||
328 | ] | ||
329 | |||
330 | [[package]] | ||
297 | name = "ctor" | 331 | name = "ctor" |
298 | version = "0.1.20" | 332 | version = "0.1.20" |
299 | source = "registry+https://github.com/rust-lang/crates.io-index" | 333 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -477,6 +511,7 @@ dependencies = [ | |||
477 | "blake2", | 511 | "blake2", |
478 | "block-modes", | 512 | "block-modes", |
479 | "chrono", | 513 | "chrono", |
514 | "csv", | ||
480 | "hex-literal", | 515 | "hex-literal", |
481 | "jsonwebtoken", | 516 | "jsonwebtoken", |
482 | "lazy_static", | 517 | "lazy_static", |
@@ -1301,6 +1336,12 @@ dependencies = [ | |||
1301 | ] | 1336 | ] |
1302 | 1337 | ||
1303 | [[package]] | 1338 | [[package]] |
1339 | name = "regex-automata" | ||
1340 | version = "0.1.10" | ||
1341 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1342 | checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" | ||
1343 | |||
1344 | [[package]] | ||
1304 | name = "regex-syntax" | 1345 | name = "regex-syntax" |
1305 | version = "0.6.23" | 1346 | version = "0.6.23" |
1306 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1347 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -27,6 +27,7 @@ sha2 = "0.9.3" | |||
27 | block-modes = "0.7.0" | 27 | block-modes = "0.7.0" |
28 | aes = "0.6.0" | 28 | aes = "0.6.0" |
29 | askama = "0.10.5" | 29 | askama = "0.10.5" |
30 | csv = "1.1.6" | ||
30 | 31 | ||
31 | [dev-dependencies] | 32 | [dev-dependencies] |
32 | serde_test = "1.0.117" | 33 | serde_test = "1.0.117" |
@@ -19,6 +19,7 @@ pub struct Db { | |||
19 | pub blockchain: Arc<RwLock<Block>>, | 19 | pub blockchain: Arc<RwLock<Block>>, |
20 | pub pending_transactions: Arc<RwLock<HashMap<Id, Transaction>>>, | 20 | pub pending_transactions: Arc<RwLock<HashMap<Id, Transaction>>>, |
21 | pub users: Arc<RwLock<HashMap<Fingerprint, User>>>, | 21 | pub users: Arc<RwLock<HashMap<Fingerprint, User>>>, |
22 | approved_users: Vec<MetuId>, | ||
22 | // TODO: metu_ids or approved_users or something, metu_id struct <11-04-22, yigit> // | 23 | // TODO: metu_ids or approved_users or something, metu_id struct <11-04-22, yigit> // |
23 | } | 24 | } |
24 | 25 | ||
@@ -36,11 +37,13 @@ impl Db { | |||
36 | } | 37 | } |
37 | 38 | ||
38 | let users: HashMap<Fingerprint, User> = get_friendly_users(); | 39 | let users: HashMap<Fingerprint, User> = get_friendly_users(); |
40 | let approved_users = read_approved_users(); | ||
39 | 41 | ||
40 | Db { | 42 | Db { |
41 | blockchain: Arc::new(RwLock::new(Block::default())), | 43 | blockchain: Arc::new(RwLock::new(Block::default())), |
42 | pending_transactions: Arc::new(RwLock::new(HashMap::new())), | 44 | pending_transactions: Arc::new(RwLock::new(HashMap::new())), |
43 | users: Arc::new(RwLock::new(users)), | 45 | users: Arc::new(RwLock::new(users)), |
46 | approved_users, | ||
44 | } | 47 | } |
45 | } | 48 | } |
46 | 49 | ||
@@ -157,3 +160,14 @@ fn get_friendly_users() -> HashMap<Fingerprint, User> { | |||
157 | ); | 160 | ); |
158 | users | 161 | users |
159 | } | 162 | } |
163 | |||
164 | fn read_approved_users() -> Vec<MetuId> { | ||
165 | let mut approved_students: Vec<MetuId> = Vec::new(); | ||
166 | let contents = fs::read_to_string("students.csv").unwrap(); | ||
167 | let mut reader = csv::Reader::from_reader(contents.as_bytes()); | ||
168 | for student in reader.records() { | ||
169 | let student = student.unwrap(); | ||
170 | approved_students.push(MetuId::_new(student[0].to_owned(), student[1].to_owned())); | ||
171 | } | ||
172 | approved_students | ||
173 | } | ||
diff --git a/src/handlers.rs b/src/handlers.rs index a64c012..96001ce 100644 --- a/src/handlers.rs +++ b/src/handlers.rs | |||
@@ -27,13 +27,13 @@ use warp::{http::StatusCode, reply}; | |||
27 | use crate::PRIVATE_KEY; | 27 | use crate::PRIVATE_KEY; |
28 | 28 | ||
29 | // Valid blocks should have this many transactions | 29 | // Valid blocks should have this many transactions |
30 | const BLOCK_TRANSACTION_COUNT: u8 = 8; | 30 | const BLOCK_TRANSACTION_COUNT: u8 = 4; |
31 | // Inital registration bonus | 31 | // Inital registration bonus |
32 | const REGISTER_BONUS: u16 = 40; | 32 | const REGISTER_BONUS: u16 = 20; |
33 | // Coinbase reward | 33 | // Coinbase reward |
34 | const BLOCK_REWARD: u16 = 3; | 34 | const BLOCK_REWARD: u16 = 2; |
35 | // Transaction amount limit | 35 | // Transaction amount limit |
36 | const TX_UPPER_LIMIT: u16 = 10; | 36 | const TX_UPPER_LIMIT: u16 = 4; |
37 | const TX_LOWER_LIMIT: u16 = 1; | 37 | const TX_LOWER_LIMIT: u16 = 1; |
38 | // Transaction traffic reward | 38 | // Transaction traffic reward |
39 | const TX_TRAFFIC_REWARD: u16 = 1; | 39 | const TX_TRAFFIC_REWARD: u16 = 1; |
@@ -278,6 +278,7 @@ pub async fn authenticate_user( | |||
278 | }; | 278 | }; |
279 | 279 | ||
280 | // is the student in AuthRequest privileged? | 280 | // is the student in AuthRequest privileged? |
281 | // TODO: this is the only check for 'if metuid is approved' <15-04-22, yigit> // | ||
281 | let privileged_student_id = | 282 | let privileged_student_id = |
282 | if let Some(id) = MetuId::new(request.student_id.clone(), request.passwd.clone()) { | 283 | if let Some(id) = MetuId::new(request.student_id.clone(), request.passwd.clone()) { |
283 | id | 284 | id |
diff --git a/src/student.rs b/src/student.rs index 4b7acf1..711eeeb 100644 --- a/src/student.rs +++ b/src/student.rs | |||
@@ -26,6 +26,7 @@ pub struct User { | |||
26 | } | 26 | } |
27 | 27 | ||
28 | /// The values are hard coded in [`static@OUR_STUDENTS`] so `MetuId::new`() can accept/reject values based on that | 28 | /// The values are hard coded in [`static@OUR_STUDENTS`] so `MetuId::new`() can accept/reject values based on that |
29 | /// TODO update the statement above | ||
29 | #[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] | 30 | #[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] |
30 | pub struct MetuId { | 31 | pub struct MetuId { |
31 | id: String, | 32 | id: String, |
@@ -46,10 +47,14 @@ impl MetuId { | |||
46 | None | 47 | None |
47 | } | 48 | } |
48 | } | 49 | } |
50 | |||
51 | // TODO: replace the function above with this <15-04-22, yigit> // | ||
52 | pub fn _new(id: String, passwd: String) -> Self { | ||
53 | MetuId { id, passwd } | ||
54 | } | ||
49 | } | 55 | } |
50 | 56 | ||
51 | // TODO: remove this, read from a yaml or something, then MetuId::new gets a self <11-04-22, yigit> // | 57 | // TODO: remove this, read from a yaml or something, then MetuId::new gets a self <11-04-22, yigit> // |
52 | |||
53 | // Students who are authorized to have Gradecoin accounts | 58 | // Students who are authorized to have Gradecoin accounts |
54 | lazy_static! { | 59 | lazy_static! { |
55 | static ref OUR_STUDENTS: HashSet<(&'static str, &'static str)> = { | 60 | static ref OUR_STUDENTS: HashSet<(&'static str, &'static str)> = { |