Skip to content
Snippets Groups Projects
Commit 8465a34c authored by Éloïs's avatar Éloïs
Browse files

|enh] create endpoint v11 (ws2pv2)

parent 2d56ee1d
No related branches found
No related tags found
No related merge requests found
...@@ -319,6 +319,7 @@ dependencies = [ ...@@ -319,6 +319,7 @@ dependencies = [
name = "duniter-network" name = "duniter-network"
version = "0.1.0-a0.1" version = "0.1.0-a0.1"
dependencies = [ dependencies = [
"byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"duniter-crypto 0.2.0-a0.1", "duniter-crypto 0.2.0-a0.1",
"duniter-documents 0.8.0-a0.1", "duniter-documents 0.8.0-a0.1",
"duniter-module 0.1.0-a0.1", "duniter-module 0.1.0-a0.1",
......
...@@ -9,6 +9,7 @@ license = "AGPL-3.0" ...@@ -9,6 +9,7 @@ license = "AGPL-3.0"
path = "lib.rs" path = "lib.rs"
[dependencies] [dependencies]
byteorder = "1.2.3"
duniter-crypto = { path = "../crypto" } duniter-crypto = { path = "../crypto" }
duniter-documents = { path = "../documents" } duniter-documents = { path = "../documents" }
duniter-module = { path = "../module" } duniter-module = { path = "../module" }
......
...@@ -27,6 +27,7 @@ extern crate lazy_static; ...@@ -27,6 +27,7 @@ extern crate lazy_static;
#[macro_use] #[macro_use]
extern crate serde_derive; extern crate serde_derive;
extern crate byteorder;
extern crate crypto; extern crate crypto;
extern crate duniter_crypto; extern crate duniter_crypto;
extern crate duniter_documents; extern crate duniter_documents;
...@@ -337,8 +338,8 @@ mod tests { ...@@ -337,8 +338,8 @@ mod tests {
let node_id = NodeUUID(u32::from_str_radix("c1c39a0a", 16).unwrap()); let node_id = NodeUUID(u32::from_str_radix("c1c39a0a", 16).unwrap());
let full_id = NodeFullId(node_id, issuer); let full_id = NodeFullId(node_id, issuer);
assert_eq!( assert_eq!(
NetworkEndpoint::parse_from_raw("WS2P c1c39a0a i3.ifee.fr 80 /ws2p", issuer, 0, 0), NetworkEndpoint::parse_from_raw("WS2P c1c39a0a i3.ifee.fr 80 /ws2p", issuer, 0, 0, 1),
Some(NetworkEndpoint::V1(NetworkEndpointV1 { Ok(NetworkEndpoint::V10(NetworkEndpointV10 {
version: 1, version: 1,
issuer, issuer,
api: NetworkEndpointApi(String::from("WS2P")), api: NetworkEndpointApi(String::from("WS2P")),
...@@ -363,8 +364,8 @@ mod tests { ...@@ -363,8 +364,8 @@ mod tests {
let node_id = NodeUUID(u32::from_str_radix("cb06a19b", 16).unwrap()); let node_id = NodeUUID(u32::from_str_radix("cb06a19b", 16).unwrap());
let full_id = NodeFullId(node_id, issuer); let full_id = NodeFullId(node_id, issuer);
assert_eq!( assert_eq!(
NetworkEndpoint::parse_from_raw("WS2P cb06a19b g1.imirhil.fr 53012 /", issuer, 0, 0), NetworkEndpoint::parse_from_raw("WS2P cb06a19b g1.imirhil.fr 53012 /", issuer, 0, 0, 1),
Some(NetworkEndpoint::V1(NetworkEndpointV1 { Ok(NetworkEndpoint::V10(NetworkEndpointV10 {
version: 1, version: 1,
issuer, issuer,
api: NetworkEndpointApi(String::from("WS2P")), api: NetworkEndpointApi(String::from("WS2P")),
......
This diff is collapsed.
...@@ -104,6 +104,7 @@ impl Default for WS2PConf { ...@@ -104,6 +104,7 @@ impl Default for WS2PConf {
), ),
0, 0,
0, 0,
1u16,
).unwrap(), ).unwrap(),
NetworkEndpoint::parse_from_raw( NetworkEndpoint::parse_from_raw(
"WS2P b48824f0 g1.monnaielibreoccitanie.org 443 /ws2p", "WS2P b48824f0 g1.monnaielibreoccitanie.org 443 /ws2p",
...@@ -114,6 +115,7 @@ impl Default for WS2PConf { ...@@ -114,6 +115,7 @@ impl Default for WS2PConf {
), ),
0, 0,
0, 0,
1u16,
).unwrap(), ).unwrap(),
], ],
} }
...@@ -536,7 +538,8 @@ impl DuniterModule<DuRsConf, DuniterMessage> for WS2PModule { ...@@ -536,7 +538,8 @@ impl DuniterModule<DuRsConf, DuniterMessage> for WS2PModule {
*node_full_id, *node_full_id,
*conn_state as u32, *conn_state as u32,
uid_option.clone(), uid_option.clone(),
ep.get_url(false), ep.get_url(false, false)
.expect("Endpoint unreachable !"),
), ),
); );
} }
...@@ -577,7 +580,10 @@ impl DuniterModule<DuRsConf, DuniterMessage> for WS2PModule { ...@@ -577,7 +580,10 @@ impl DuniterModule<DuRsConf, DuniterMessage> for WS2PModule {
ws2p_full_id, ws2p_full_id,
WS2PConnectionState::Established as u32, WS2PConnectionState::Established as u32,
ws2p_module.uids_cache.get(&ws2p_full_id.1).cloned(), ws2p_module.uids_cache.get(&ws2p_full_id.1).cloned(),
ws2p_module.ws2p_endpoints[&ws2p_full_id].0.get_url(false), ws2p_module.ws2p_endpoints[&ws2p_full_id]
.0
.get_url(false, false)
.expect("Endpoint unreachable !"),
)); ));
} }
WS2PSignal::WSError(ws2p_full_id) => { WS2PSignal::WSError(ws2p_full_id) => {
...@@ -586,7 +592,10 @@ impl DuniterModule<DuRsConf, DuniterMessage> for WS2PModule { ...@@ -586,7 +592,10 @@ impl DuniterModule<DuRsConf, DuniterMessage> for WS2PModule {
ws2p_full_id, ws2p_full_id,
WS2PConnectionState::WSError as u32, WS2PConnectionState::WSError as u32,
ws2p_module.uids_cache.get(&ws2p_full_id.1).cloned(), ws2p_module.uids_cache.get(&ws2p_full_id.1).cloned(),
ws2p_module.ws2p_endpoints[&ws2p_full_id].0.get_url(false), ws2p_module.ws2p_endpoints[&ws2p_full_id]
.0
.get_url(false, false)
.expect("Endpoint unreachable !"),
)); ));
} }
WS2PSignal::NegociationTimeout(ws2p_full_id) => { WS2PSignal::NegociationTimeout(ws2p_full_id) => {
...@@ -595,7 +604,10 @@ impl DuniterModule<DuRsConf, DuniterMessage> for WS2PModule { ...@@ -595,7 +604,10 @@ impl DuniterModule<DuRsConf, DuniterMessage> for WS2PModule {
ws2p_full_id, ws2p_full_id,
WS2PConnectionState::Denial as u32, WS2PConnectionState::Denial as u32,
ws2p_module.uids_cache.get(&ws2p_full_id.1).cloned(), ws2p_module.uids_cache.get(&ws2p_full_id.1).cloned(),
ws2p_module.ws2p_endpoints[&ws2p_full_id].0.get_url(false), ws2p_module.ws2p_endpoints[&ws2p_full_id]
.0
.get_url(false, false)
.expect("Endpoint unreachable !"),
)); ));
} }
WS2PSignal::Timeout(ws2p_full_id) => { WS2PSignal::Timeout(ws2p_full_id) => {
...@@ -604,7 +616,10 @@ impl DuniterModule<DuRsConf, DuniterMessage> for WS2PModule { ...@@ -604,7 +616,10 @@ impl DuniterModule<DuRsConf, DuniterMessage> for WS2PModule {
ws2p_full_id, ws2p_full_id,
WS2PConnectionState::Close as u32, WS2PConnectionState::Close as u32,
ws2p_module.uids_cache.get(&ws2p_full_id.1).cloned(), ws2p_module.uids_cache.get(&ws2p_full_id.1).cloned(),
ws2p_module.ws2p_endpoints[&ws2p_full_id].0.get_url(false), ws2p_module.ws2p_endpoints[&ws2p_full_id]
.0
.get_url(false, false)
.expect("Endpoint unreachable !"),
)); ));
} }
WS2PSignal::PeerCard(_ws2p_full_id, _peer_card, ws2p_endpoints) => { WS2PSignal::PeerCard(_ws2p_full_id, _peer_card, ws2p_endpoints) => {
...@@ -1062,6 +1077,7 @@ mod tests { ...@@ -1062,6 +1077,7 @@ mod tests {
), ),
1, 1,
current_time.as_secs(), current_time.as_secs(),
1,
).expect("Failt to parse test endpoint !"); ).expect("Failt to parse test endpoint !");
ws2p_db::write_endpoint(&db, &endpoint, 1, current_time.as_secs()); ws2p_db::write_endpoint(&db, &endpoint, 1, current_time.as_secs());
......
...@@ -539,11 +539,12 @@ impl WS2PConnectionMetaDatas { ...@@ -539,11 +539,12 @@ impl WS2PConnectionMetaDatas {
Some(endpoints) => match endpoints.as_array() { Some(endpoints) => match endpoints.as_array() {
Some(array_endpoints) => { Some(array_endpoints) => {
for endpoint in array_endpoints { for endpoint in array_endpoints {
if let Some(ep) = NetworkEndpoint::parse_from_raw( if let Ok(ep) = NetworkEndpoint::parse_from_raw(
endpoint.as_str().unwrap_or(""), endpoint.as_str().unwrap_or(""),
PubKey::Ed25519(pubkey), PubKey::Ed25519(pubkey),
0, 0,
0, 0,
1u16,
) { ) {
if ep.api() == NetworkEndpointApi(String::from("WS2P")) if ep.api() == NetworkEndpointApi(String::from("WS2P"))
{ {
...@@ -597,7 +598,7 @@ pub fn connect_to_ws2p_endpoint( ...@@ -597,7 +598,7 @@ pub fn connect_to_ws2p_endpoint(
key_pair: KeyPairEnum, key_pair: KeyPairEnum,
) -> ws::Result<()> { ) -> ws::Result<()> {
// Get endpoint url // Get endpoint url
let ws_url = endpoint.get_url(true); let ws_url = endpoint.get_url(true, false).expect("Endpoint unreachable");
// Create WS2PConnectionMetaDatass // Create WS2PConnectionMetaDatass
let mut conn_meta_datas = WS2PConnectionMetaDatas::new( let mut conn_meta_datas = WS2PConnectionMetaDatas::new(
......
...@@ -76,9 +76,10 @@ pub fn get_endpoints_for_api( ...@@ -76,9 +76,10 @@ pub fn get_endpoints_for_api(
ep_issuer, ep_issuer,
row[1].as_integer().unwrap() as u32, row[1].as_integer().unwrap() as u32,
row[7].as_integer().unwrap() as u64, row[7].as_integer().unwrap() as u64,
1u16,
) { ) {
Some(ep) => ep, Ok(ep) => ep,
None => panic!(format!("Fail to parse endpoint : {}", raw_ep)), Err(_) => panic!(format!("Fail to parse endpoint : {}", raw_ep)),
}; };
ep.set_status(row[1].as_integer().unwrap() as u32); ep.set_status(row[1].as_integer().unwrap() as u32);
ep.set_last_check(row[7].as_integer().unwrap() as u64); ep.set_last_check(row[7].as_integer().unwrap() as u64);
...@@ -119,14 +120,14 @@ pub fn write_endpoint( ...@@ -119,14 +120,14 @@ pub fn write_endpoint(
hash_full_id hash_full_id
)).expect("Fail to parse SQL request update endpoint status !"); )).expect("Fail to parse SQL request update endpoint status !");
} }
} else if let NetworkEndpoint::V1(ref ep_v1) = *endpoint { } else if let NetworkEndpoint::V10(ref ep_v10) = *endpoint {
db db
.execute( .execute(
format!( format!(
"INSERT INTO endpoints (hash_full_id, status, node_id, pubkey, api, version, endpoint, last_check) VALUES ('{}', {}, {}, '{}', {}, {}, '{}', {});", "INSERT INTO endpoints (hash_full_id, status, node_id, pubkey, api, version, endpoint, last_check) VALUES ('{}', {}, {}, '{}', {}, {}, '{}', {});",
ep_v1.hash_full_id.expect("ep_v1.hash_full_id = None"), new_status, ep_v1.node_id.expect("ep_v1.node_id = None").0, ep_v10.hash_full_id.expect("ep_v10.hash_full_id = None"), new_status, ep_v10.node_id.expect("ep_v10.node_id = None").0,
ep_v1.issuer.to_string(), api_to_integer(&ep_v1.api), ep_v10.issuer.to_string(), api_to_integer(&ep_v10.api),
ep_v1.version, ep_v1.raw_endpoint, new_last_check ep_v10.version, ep_v10.raw_endpoint, new_last_check
) )
) )
.expect("Fail to parse SQL request INSERT endpoint !"); .expect("Fail to parse SQL request INSERT endpoint !");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment