Skip to content

Commit ef914d3

Browse files
bertllllBertkauri-hero
authored
GH-597: correct AutomapProtocol db storage (#120)
* GH-597: code and tests established; some new features or work style used: no_share_test wider use * GH-597: little corrections and formatting * GH-597: auto review * GH-597: cosmetics, added a few places with logs * GH-597: A rookie mistake :) not running and so forgetting integration tests * update Practice with reference to version & QA * update practice with version release info * DRAFT: Update docs/branch (#133) * Update node top level README add list of component README files for easy navigation * Added reference to UI-Interface-Interface Added reference to UI-Interface-Interface document that lives in the Node repo main folder * Update README.md * Delete SHRD-faucet This is no longer usable and is not connected to the MASQ token contracts * Update to blockchain service details Update to blockchain service details about Polygon, testnets, Alchemy also removed old images * wording and formattting * update LICENSE updated with corrected copyright for MASQ, and added info regarding previous codebase being removed from GitHub and original repo disappeared * Update Practice with QA blurb Thanks Stew * adjust copyright * remove old DNS doc * remove old DNS doc * remove old DNS doc * delete old faucet info * updated with component readmes * remove old logo * remove old logo2 * Create brand-guidelines.md * add masq logos * remove to move logos * add masq logos * added masq logo to readme * GH-597: backup; closely before finishing / fixed an old issue with annoying 'Send' requirement; introducet a new concept of an arbitrary_id_stamp for testing specific situations * GH-597: finished the concept of ArbitraryIdStamp * GH-597: updated github yml files; the release one is now more optimized * GH-597: last polishing before another review * GH-597: second review addressed * update from reviews * update and copyright bump * copyright bump [skip ci] [skip ci] * copyright bump [skip ci] * copyright bump [skip ci] * copyright bump [skip ci] * copyright bump [skip ci] * copyright bump [skip ci] * copyright bump [skip ci] * copyright bump [skip ci] * copyright bump [skip ci] * copyright bump [skip ci] * copyright bump [skip ci] * docs/contributing-plus-cleanup: last polishment * GH-597: a little correction in docs * GH-597: fixed a labile test in WebsocketSuperwisor and added an explanation of an unclear solution around there too * GH-597: removing unknown extern crate usage * GH-597: trying to get the release build for Node working properly * GH-597: removing an optimized build script because of an issue on Mac; we don't know how to fix that at the moment Co-authored-by: Bert <[email protected]> Co-authored-by: KauriHero <[email protected]>
1 parent 5de5095 commit ef914d3

22 files changed

+965
-595
lines changed

PRACTICE.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,16 @@ In the future, the team may determine that individual components within the code
203203

204204
### Steps for Creating and Tagging the Next Version
205205

206-
Currently, the tag is expected to be just a lightweight tag following semver format.
207-
208206
The developer should follow these steps to complete the git tag before a repo admin is to merge into `master`
209207

210208
- [ ] First acquire an agreement from the Product Owner that your branch (in your open PR) is going to enclose the current, pending release.
211209
- [ ] Your code in your branch should appear errorless in Actions (it's passed all checks) and also it's satisfied all reviews, so is approved by the reviewer.
212210
- [ ] Create a tag to the HEAD commit of your branch with the previously agreed version number. If you do that locally on your machine you may want to use e.g.:
213211
```
214-
git tag v0.6.1
215-
212+
git tag v0.6.1 -m ""
213+
```
214+
_Currently, we prefer the style with an empty annotation instead of the so-called lightweight tag because this way we can prevent the message of the last commit to be displayed together with the tag. It's possible that the message would be quite irrelevant to the complete release itself. We may decide to implement a release changelog that could fill that empty space by a good description in the future._
215+
```
216216
git push origin v0.6.1
217217
```
218218
- [ ] The last step should cause a new trigger of a run in Actions, this time with a different workflow than usual, producing official release binaries.

automap/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ path = "src/main.rs"
2727
[lib]
2828
name = "automap_lib"
2929
path = "src/lib.rs"
30+
31+
[features]
32+
no_test_share = []

automap/src/comm_layer/igdp.rs

-5
Original file line numberDiff line numberDiff line change
@@ -580,20 +580,15 @@ impl MappingAdderReal {
580580
#[cfg(test)]
581581
mod tests {
582582
use super::*;
583-
use crate::control_layer::automap_control::AutomapChange;
584583
use crate::mocks::LocalIpFinderMock;
585584
use core::ptr::addr_of;
586-
use crossbeam_channel::unbounded;
587585
use igd::RequestError;
588586
use masq_lib::test_utils::logging::{init_test_logging, TestLogHandler};
589-
use masq_lib::utils::AutomapProtocol;
590587
use std::cell::RefCell;
591588
use std::net::Ipv6Addr;
592589
use std::ops::Sub;
593590
use std::str::FromStr;
594591
use std::sync::{Arc, Mutex};
595-
use std::thread;
596-
use std::time::Duration;
597592

598593
fn clone_get_external_ip_error(error: &GetExternalIpError) -> GetExternalIpError {
599594
match error {

automap/src/control_layer/automap_control.rs

+18-229
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ impl AutomapControlReal {
232232
) -> Result<ProtocolInfo<T>, AutomapError> {
233233
let mut transactors_ref_mut = self.transactors.borrow_mut();
234234
if let Some(usual_protocol) = self.usual_protocol_opt {
235+
debug!(
236+
self.logger,
237+
"Trying a predetermined protocol: {}", usual_protocol
238+
);
235239
let transactor = transactors_ref_mut
236240
.iter_mut()
237241
.find(|t| t.protocol() == usual_protocol)
@@ -332,234 +336,31 @@ impl AutomapControlReal {
332336
}
333337
}
334338

339+
#[cfg(any(test, not(feature = "no_test_share")))]
340+
pub fn replace_transactor(
341+
subject: AutomapControlReal,
342+
transactor: Box<dyn Transactor>,
343+
) -> AutomapControlReal {
344+
let idx = AutomapControlReal::find_transactor_index(
345+
subject.transactors.borrow_mut(),
346+
transactor.protocol(),
347+
);
348+
subject.transactors.borrow_mut()[idx] = transactor;
349+
subject
350+
}
351+
335352
#[cfg(test)]
336353
mod tests {
337354
use super::*;
338355
use crate::comm_layer::Transactor;
356+
use crate::mocks::{TransactorMock, PUBLIC_IP, ROUTER_IP};
339357
use crossbeam_channel::{unbounded, TryRecvError};
340-
use lazy_static::lazy_static;
341-
use std::any::Any;
342358
use std::cell::RefCell;
343359
use std::net::IpAddr;
344360
use std::ptr::addr_of;
345361
use std::str::FromStr;
346362
use std::sync::{Arc, Mutex};
347363

348-
lazy_static! {
349-
static ref ROUTER_IP: IpAddr = IpAddr::from_str("1.2.3.4").unwrap();
350-
static ref PUBLIC_IP: IpAddr = IpAddr::from_str("2.3.4.5").unwrap();
351-
}
352-
353-
struct TransactorMock {
354-
housekeeping_thread_started: bool,
355-
protocol: AutomapProtocol,
356-
find_routers_results: RefCell<Vec<Result<Vec<IpAddr>, AutomapError>>>,
357-
get_public_ip_params: Arc<Mutex<Vec<IpAddr>>>,
358-
get_public_ip_results: RefCell<Vec<Result<IpAddr, AutomapError>>>,
359-
add_mapping_params: Arc<Mutex<Vec<(IpAddr, u16, u32)>>>,
360-
add_mapping_results: RefCell<Vec<Result<u32, AutomapError>>>,
361-
add_permanent_mapping_params: Arc<Mutex<Vec<(IpAddr, u16)>>>,
362-
add_permanent_mapping_results: RefCell<Vec<Result<u32, AutomapError>>>,
363-
delete_mapping_params: Arc<Mutex<Vec<(IpAddr, u16)>>>,
364-
delete_mapping_results: RefCell<Vec<Result<(), AutomapError>>>,
365-
start_housekeeping_thread_params: Arc<Mutex<Vec<(ChangeHandler, IpAddr)>>>,
366-
start_housekeeping_thread_results:
367-
RefCell<Vec<Result<Sender<HousekeepingThreadCommand>, AutomapError>>>,
368-
stop_housekeeping_thread_params: Arc<Mutex<Vec<()>>>,
369-
stop_housekeeping_thread_results: RefCell<Vec<Result<ChangeHandler, AutomapError>>>,
370-
}
371-
372-
impl Transactor for TransactorMock {
373-
fn find_routers(&self) -> Result<Vec<IpAddr>, AutomapError> {
374-
self.find_routers_results.borrow_mut().remove(0)
375-
}
376-
377-
fn get_public_ip(&self, router_ip: IpAddr) -> Result<IpAddr, AutomapError> {
378-
if !self.housekeeping_thread_started {
379-
panic!("Housekeeping thread must be started before get_public_ip()")
380-
}
381-
self.get_public_ip_params.lock().unwrap().push(router_ip);
382-
self.get_public_ip_results.borrow_mut().remove(0)
383-
}
384-
385-
fn add_mapping(
386-
&self,
387-
router_ip: IpAddr,
388-
hole_port: u16,
389-
lifetime: u32,
390-
) -> Result<u32, AutomapError> {
391-
if !self.housekeeping_thread_started {
392-
panic!("Housekeeping thread must be started before add_mapping()")
393-
}
394-
self.add_mapping_params
395-
.lock()
396-
.unwrap()
397-
.push((router_ip, hole_port, lifetime));
398-
self.add_mapping_results.borrow_mut().remove(0)
399-
}
400-
401-
fn add_permanent_mapping(
402-
&self,
403-
router_ip: IpAddr,
404-
hole_port: u16,
405-
) -> Result<u32, AutomapError> {
406-
if !self.housekeeping_thread_started {
407-
panic!("Housekeeping thread must be started before add_permanent_mapping()")
408-
}
409-
self.add_permanent_mapping_params
410-
.lock()
411-
.unwrap()
412-
.push((router_ip, hole_port));
413-
self.add_permanent_mapping_results.borrow_mut().remove(0)
414-
}
415-
416-
fn delete_mapping(&self, router_ip: IpAddr, hole_port: u16) -> Result<(), AutomapError> {
417-
self.delete_mapping_params
418-
.lock()
419-
.unwrap()
420-
.push((router_ip, hole_port));
421-
self.delete_mapping_results.borrow_mut().remove(0)
422-
}
423-
424-
fn protocol(&self) -> AutomapProtocol {
425-
self.protocol
426-
}
427-
428-
fn start_housekeeping_thread(
429-
&mut self,
430-
change_handler: ChangeHandler,
431-
router_ip: IpAddr,
432-
) -> Result<Sender<HousekeepingThreadCommand>, AutomapError> {
433-
self.start_housekeeping_thread_params
434-
.lock()
435-
.unwrap()
436-
.push((change_handler, router_ip));
437-
let result = self
438-
.start_housekeeping_thread_results
439-
.borrow_mut()
440-
.remove(0);
441-
self.housekeeping_thread_started = true;
442-
result
443-
}
444-
445-
fn stop_housekeeping_thread(&mut self) -> Result<ChangeHandler, AutomapError> {
446-
self.stop_housekeeping_thread_params
447-
.lock()
448-
.unwrap()
449-
.push(());
450-
let result = self.stop_housekeeping_thread_results.borrow_mut().remove(0);
451-
self.housekeeping_thread_started = false;
452-
result
453-
}
454-
455-
fn as_any(&self) -> &dyn Any {
456-
self
457-
}
458-
}
459-
460-
impl TransactorMock {
461-
pub fn new(protocol: AutomapProtocol) -> Self {
462-
Self {
463-
housekeeping_thread_started: false,
464-
protocol,
465-
find_routers_results: RefCell::new(vec![]),
466-
get_public_ip_params: Arc::new(Mutex::new(vec![])),
467-
get_public_ip_results: RefCell::new(vec![]),
468-
add_mapping_params: Arc::new(Mutex::new(vec![])),
469-
add_mapping_results: RefCell::new(vec![]),
470-
add_permanent_mapping_params: Arc::new(Mutex::new(vec![])),
471-
add_permanent_mapping_results: RefCell::new(vec![]),
472-
delete_mapping_params: Arc::new(Mutex::new(vec![])),
473-
delete_mapping_results: RefCell::new(vec![]),
474-
start_housekeeping_thread_params: Arc::new(Mutex::new(vec![])),
475-
start_housekeeping_thread_results: RefCell::new(vec![]),
476-
stop_housekeeping_thread_params: Arc::new(Mutex::new(vec![])),
477-
stop_housekeeping_thread_results: RefCell::new(vec![]),
478-
}
479-
}
480-
481-
pub fn find_routers_result(self, result: Result<Vec<IpAddr>, AutomapError>) -> Self {
482-
self.find_routers_results.borrow_mut().push(result);
483-
self
484-
}
485-
486-
pub fn get_public_ip_params(mut self, params: &Arc<Mutex<Vec<IpAddr>>>) -> Self {
487-
self.get_public_ip_params = params.clone();
488-
self
489-
}
490-
491-
pub fn get_public_ip_result(self, result: Result<IpAddr, AutomapError>) -> Self {
492-
self.get_public_ip_results.borrow_mut().push(result);
493-
self
494-
}
495-
496-
pub fn add_mapping_params(mut self, params: &Arc<Mutex<Vec<(IpAddr, u16, u32)>>>) -> Self {
497-
self.add_mapping_params = params.clone();
498-
self
499-
}
500-
501-
pub fn add_mapping_result(self, result: Result<u32, AutomapError>) -> Self {
502-
self.add_mapping_results.borrow_mut().push(result);
503-
self
504-
}
505-
506-
pub fn add_permanent_mapping_params(
507-
mut self,
508-
params: &Arc<Mutex<Vec<(IpAddr, u16)>>>,
509-
) -> Self {
510-
self.add_permanent_mapping_params = params.clone();
511-
self
512-
}
513-
514-
pub fn add_permanent_mapping_result(self, result: Result<u32, AutomapError>) -> Self {
515-
self.add_permanent_mapping_results.borrow_mut().push(result);
516-
self
517-
}
518-
519-
pub fn delete_mapping_params(mut self, params: &Arc<Mutex<Vec<(IpAddr, u16)>>>) -> Self {
520-
self.delete_mapping_params = params.clone();
521-
self
522-
}
523-
524-
pub fn delete_mapping_result(self, result: Result<(), AutomapError>) -> Self {
525-
self.delete_mapping_results.borrow_mut().push(result);
526-
self
527-
}
528-
529-
pub fn start_housekeeping_thread_result(
530-
self,
531-
result: Result<Sender<HousekeepingThreadCommand>, AutomapError>,
532-
) -> Self {
533-
self.start_housekeeping_thread_results
534-
.borrow_mut()
535-
.push(result);
536-
self
537-
}
538-
539-
pub fn start_housekeeping_thread_params(
540-
mut self,
541-
params: &Arc<Mutex<Vec<(ChangeHandler, IpAddr)>>>,
542-
) -> Self {
543-
self.start_housekeeping_thread_params = params.clone();
544-
self
545-
}
546-
547-
pub fn stop_housekeeping_thread_params(mut self, params: &Arc<Mutex<Vec<()>>>) -> Self {
548-
self.stop_housekeeping_thread_params = params.clone();
549-
self
550-
}
551-
552-
pub fn stop_housekeeping_thread_result(
553-
self,
554-
result: Result<ChangeHandler, AutomapError>,
555-
) -> Self {
556-
self.stop_housekeeping_thread_results
557-
.borrow_mut()
558-
.push(result);
559-
self
560-
}
561-
}
562-
563364
fn choose_working_protocol_works_for_success(protocol: AutomapProtocol) {
564365
let mut subject = make_multirouter_specific_success_subject(
565366
protocol,
@@ -1586,18 +1387,6 @@ mod tests {
15861387
subject
15871388
}
15881389

1589-
fn replace_transactor(
1590-
subject: AutomapControlReal,
1591-
transactor: Box<dyn Transactor>,
1592-
) -> AutomapControlReal {
1593-
let idx = AutomapControlReal::find_transactor_index(
1594-
subject.transactors.borrow_mut(),
1595-
transactor.protocol(),
1596-
);
1597-
subject.transactors.borrow_mut()[idx] = transactor;
1598-
subject
1599-
}
1600-
16011390
fn assert_all_protocols_failed<T: Debug + PartialEq>(
16021391
result: Result<T, AutomapError>,
16031392
pcp: AutomapError,

automap/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ pub mod logger;
77
pub mod probe_researcher;
88
pub mod protocols;
99

10-
#[cfg(test)]
1110
pub mod mocks;

0 commit comments

Comments
 (0)