Skip to content

Commit

Permalink
GH-597: correct AutomapProtocol db storage (#120)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored May 24, 2022
1 parent 5de5095 commit ef914d3
Show file tree
Hide file tree
Showing 22 changed files with 965 additions and 595 deletions.
8 changes: 4 additions & 4 deletions PRACTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,16 @@ In the future, the team may determine that individual components within the code

### Steps for Creating and Tagging the Next Version

Currently, the tag is expected to be just a lightweight tag following semver format.

The developer should follow these steps to complete the git tag before a repo admin is to merge into `master`

- [ ] First acquire an agreement from the Product Owner that your branch (in your open PR) is going to enclose the current, pending release.
- [ ] 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.
- [ ] 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.:
```
git tag v0.6.1
git tag v0.6.1 -m ""
```
_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._
```
git push origin v0.6.1
```
- [ ] 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.
Expand Down
3 changes: 3 additions & 0 deletions automap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ path = "src/main.rs"
[lib]
name = "automap_lib"
path = "src/lib.rs"

[features]
no_test_share = []
5 changes: 0 additions & 5 deletions automap/src/comm_layer/igdp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,20 +580,15 @@ impl MappingAdderReal {
#[cfg(test)]
mod tests {
use super::*;
use crate::control_layer::automap_control::AutomapChange;
use crate::mocks::LocalIpFinderMock;
use core::ptr::addr_of;
use crossbeam_channel::unbounded;
use igd::RequestError;
use masq_lib::test_utils::logging::{init_test_logging, TestLogHandler};
use masq_lib::utils::AutomapProtocol;
use std::cell::RefCell;
use std::net::Ipv6Addr;
use std::ops::Sub;
use std::str::FromStr;
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::Duration;

fn clone_get_external_ip_error(error: &GetExternalIpError) -> GetExternalIpError {
match error {
Expand Down
247 changes: 18 additions & 229 deletions automap/src/control_layer/automap_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ impl AutomapControlReal {
) -> Result<ProtocolInfo<T>, AutomapError> {
let mut transactors_ref_mut = self.transactors.borrow_mut();
if let Some(usual_protocol) = self.usual_protocol_opt {
debug!(
self.logger,
"Trying a predetermined protocol: {}", usual_protocol
);
let transactor = transactors_ref_mut
.iter_mut()
.find(|t| t.protocol() == usual_protocol)
Expand Down Expand Up @@ -332,234 +336,31 @@ impl AutomapControlReal {
}
}

#[cfg(any(test, not(feature = "no_test_share")))]
pub fn replace_transactor(
subject: AutomapControlReal,
transactor: Box<dyn Transactor>,
) -> AutomapControlReal {
let idx = AutomapControlReal::find_transactor_index(
subject.transactors.borrow_mut(),
transactor.protocol(),
);
subject.transactors.borrow_mut()[idx] = transactor;
subject
}

#[cfg(test)]
mod tests {
use super::*;
use crate::comm_layer::Transactor;
use crate::mocks::{TransactorMock, PUBLIC_IP, ROUTER_IP};
use crossbeam_channel::{unbounded, TryRecvError};
use lazy_static::lazy_static;
use std::any::Any;
use std::cell::RefCell;
use std::net::IpAddr;
use std::ptr::addr_of;
use std::str::FromStr;
use std::sync::{Arc, Mutex};

lazy_static! {
static ref ROUTER_IP: IpAddr = IpAddr::from_str("1.2.3.4").unwrap();
static ref PUBLIC_IP: IpAddr = IpAddr::from_str("2.3.4.5").unwrap();
}

struct TransactorMock {
housekeeping_thread_started: bool,
protocol: AutomapProtocol,
find_routers_results: RefCell<Vec<Result<Vec<IpAddr>, AutomapError>>>,
get_public_ip_params: Arc<Mutex<Vec<IpAddr>>>,
get_public_ip_results: RefCell<Vec<Result<IpAddr, AutomapError>>>,
add_mapping_params: Arc<Mutex<Vec<(IpAddr, u16, u32)>>>,
add_mapping_results: RefCell<Vec<Result<u32, AutomapError>>>,
add_permanent_mapping_params: Arc<Mutex<Vec<(IpAddr, u16)>>>,
add_permanent_mapping_results: RefCell<Vec<Result<u32, AutomapError>>>,
delete_mapping_params: Arc<Mutex<Vec<(IpAddr, u16)>>>,
delete_mapping_results: RefCell<Vec<Result<(), AutomapError>>>,
start_housekeeping_thread_params: Arc<Mutex<Vec<(ChangeHandler, IpAddr)>>>,
start_housekeeping_thread_results:
RefCell<Vec<Result<Sender<HousekeepingThreadCommand>, AutomapError>>>,
stop_housekeeping_thread_params: Arc<Mutex<Vec<()>>>,
stop_housekeeping_thread_results: RefCell<Vec<Result<ChangeHandler, AutomapError>>>,
}

impl Transactor for TransactorMock {
fn find_routers(&self) -> Result<Vec<IpAddr>, AutomapError> {
self.find_routers_results.borrow_mut().remove(0)
}

fn get_public_ip(&self, router_ip: IpAddr) -> Result<IpAddr, AutomapError> {
if !self.housekeeping_thread_started {
panic!("Housekeeping thread must be started before get_public_ip()")
}
self.get_public_ip_params.lock().unwrap().push(router_ip);
self.get_public_ip_results.borrow_mut().remove(0)
}

fn add_mapping(
&self,
router_ip: IpAddr,
hole_port: u16,
lifetime: u32,
) -> Result<u32, AutomapError> {
if !self.housekeeping_thread_started {
panic!("Housekeeping thread must be started before add_mapping()")
}
self.add_mapping_params
.lock()
.unwrap()
.push((router_ip, hole_port, lifetime));
self.add_mapping_results.borrow_mut().remove(0)
}

fn add_permanent_mapping(
&self,
router_ip: IpAddr,
hole_port: u16,
) -> Result<u32, AutomapError> {
if !self.housekeeping_thread_started {
panic!("Housekeeping thread must be started before add_permanent_mapping()")
}
self.add_permanent_mapping_params
.lock()
.unwrap()
.push((router_ip, hole_port));
self.add_permanent_mapping_results.borrow_mut().remove(0)
}

fn delete_mapping(&self, router_ip: IpAddr, hole_port: u16) -> Result<(), AutomapError> {
self.delete_mapping_params
.lock()
.unwrap()
.push((router_ip, hole_port));
self.delete_mapping_results.borrow_mut().remove(0)
}

fn protocol(&self) -> AutomapProtocol {
self.protocol
}

fn start_housekeeping_thread(
&mut self,
change_handler: ChangeHandler,
router_ip: IpAddr,
) -> Result<Sender<HousekeepingThreadCommand>, AutomapError> {
self.start_housekeeping_thread_params
.lock()
.unwrap()
.push((change_handler, router_ip));
let result = self
.start_housekeeping_thread_results
.borrow_mut()
.remove(0);
self.housekeeping_thread_started = true;
result
}

fn stop_housekeeping_thread(&mut self) -> Result<ChangeHandler, AutomapError> {
self.stop_housekeeping_thread_params
.lock()
.unwrap()
.push(());
let result = self.stop_housekeeping_thread_results.borrow_mut().remove(0);
self.housekeeping_thread_started = false;
result
}

fn as_any(&self) -> &dyn Any {
self
}
}

impl TransactorMock {
pub fn new(protocol: AutomapProtocol) -> Self {
Self {
housekeeping_thread_started: false,
protocol,
find_routers_results: RefCell::new(vec![]),
get_public_ip_params: Arc::new(Mutex::new(vec![])),
get_public_ip_results: RefCell::new(vec![]),
add_mapping_params: Arc::new(Mutex::new(vec![])),
add_mapping_results: RefCell::new(vec![]),
add_permanent_mapping_params: Arc::new(Mutex::new(vec![])),
add_permanent_mapping_results: RefCell::new(vec![]),
delete_mapping_params: Arc::new(Mutex::new(vec![])),
delete_mapping_results: RefCell::new(vec![]),
start_housekeeping_thread_params: Arc::new(Mutex::new(vec![])),
start_housekeeping_thread_results: RefCell::new(vec![]),
stop_housekeeping_thread_params: Arc::new(Mutex::new(vec![])),
stop_housekeeping_thread_results: RefCell::new(vec![]),
}
}

pub fn find_routers_result(self, result: Result<Vec<IpAddr>, AutomapError>) -> Self {
self.find_routers_results.borrow_mut().push(result);
self
}

pub fn get_public_ip_params(mut self, params: &Arc<Mutex<Vec<IpAddr>>>) -> Self {
self.get_public_ip_params = params.clone();
self
}

pub fn get_public_ip_result(self, result: Result<IpAddr, AutomapError>) -> Self {
self.get_public_ip_results.borrow_mut().push(result);
self
}

pub fn add_mapping_params(mut self, params: &Arc<Mutex<Vec<(IpAddr, u16, u32)>>>) -> Self {
self.add_mapping_params = params.clone();
self
}

pub fn add_mapping_result(self, result: Result<u32, AutomapError>) -> Self {
self.add_mapping_results.borrow_mut().push(result);
self
}

pub fn add_permanent_mapping_params(
mut self,
params: &Arc<Mutex<Vec<(IpAddr, u16)>>>,
) -> Self {
self.add_permanent_mapping_params = params.clone();
self
}

pub fn add_permanent_mapping_result(self, result: Result<u32, AutomapError>) -> Self {
self.add_permanent_mapping_results.borrow_mut().push(result);
self
}

pub fn delete_mapping_params(mut self, params: &Arc<Mutex<Vec<(IpAddr, u16)>>>) -> Self {
self.delete_mapping_params = params.clone();
self
}

pub fn delete_mapping_result(self, result: Result<(), AutomapError>) -> Self {
self.delete_mapping_results.borrow_mut().push(result);
self
}

pub fn start_housekeeping_thread_result(
self,
result: Result<Sender<HousekeepingThreadCommand>, AutomapError>,
) -> Self {
self.start_housekeeping_thread_results
.borrow_mut()
.push(result);
self
}

pub fn start_housekeeping_thread_params(
mut self,
params: &Arc<Mutex<Vec<(ChangeHandler, IpAddr)>>>,
) -> Self {
self.start_housekeeping_thread_params = params.clone();
self
}

pub fn stop_housekeeping_thread_params(mut self, params: &Arc<Mutex<Vec<()>>>) -> Self {
self.stop_housekeeping_thread_params = params.clone();
self
}

pub fn stop_housekeeping_thread_result(
self,
result: Result<ChangeHandler, AutomapError>,
) -> Self {
self.stop_housekeeping_thread_results
.borrow_mut()
.push(result);
self
}
}

fn choose_working_protocol_works_for_success(protocol: AutomapProtocol) {
let mut subject = make_multirouter_specific_success_subject(
protocol,
Expand Down Expand Up @@ -1586,18 +1387,6 @@ mod tests {
subject
}

fn replace_transactor(
subject: AutomapControlReal,
transactor: Box<dyn Transactor>,
) -> AutomapControlReal {
let idx = AutomapControlReal::find_transactor_index(
subject.transactors.borrow_mut(),
transactor.protocol(),
);
subject.transactors.borrow_mut()[idx] = transactor;
subject
}

fn assert_all_protocols_failed<T: Debug + PartialEq>(
result: Result<T, AutomapError>,
pcp: AutomapError,
Expand Down
1 change: 0 additions & 1 deletion automap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ pub mod logger;
pub mod probe_researcher;
pub mod protocols;

#[cfg(test)]
pub mod mocks;
Loading

0 comments on commit ef914d3

Please sign in to comment.