Commit 8465a34c authored by Éloïs's avatar Éloïs

|enh] create endpoint v11 (ws2pv2)

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