Commit 4fd891dd authored by Éloïs's avatar Éloïs

[fix] regression merge publish_dup_crates

parent 5d663d1e
......@@ -35,14 +35,6 @@ extern crate durs_network_documents;
extern crate serde;
extern crate serde_json;
use dubp_documents::v10::block::BlockDocument;
use dubp_documents::v10::certification::CertificationDocument;
use dubp_documents::v10::identity::IdentityDocument;
use dubp_documents::v10::membership::MembershipDocument;
use dubp_documents::v10::revocation::RevocationDocument;
use dubp_documents::v10::transaction::TransactionDocument;
use dubp_documents::Document;
use dubp_documents::{blockstamp::Blockstamp, BlockHash, BlockId};
use duniter_module::*;
use durs_network_documents::network_endpoint::ApiFeatures;
use durs_network_documents::network_head::NetworkHead;
......
......@@ -935,7 +935,7 @@ mod tests {
use duniter_module::DuniterModule;
use duniter_network::documents::NetworkBlock;
use dup_crypto::keys::PublicKey;
use durs_network_documents::network_endpoint::{EndpointEnum, NetworkEndpointApi};
use durs_network_documents::network_endpoint::NetworkEndpointApi;
use std::fs;
use std::path::PathBuf;
use std::time::{SystemTime, UNIX_EPOCH};
......
......@@ -330,6 +330,7 @@ impl EndpointV2 {
let ip_v4 = self.ip_v4.unwrap();
format!("{}", ip_v4)
} else {
println!("DEBUG: endpoint_v2={:?}", self);
// Unreacheable endpoint
return None;
};
......@@ -565,6 +566,28 @@ mod tests {
test_parse_and_read_endpoint(str_endpoint, endpoint);
}
#[test]
fn test_parse_and_read_localhost_endpoint() {
let str_endpoint = "WS2P localhost 10900";
let endpoint = EndpointV2 {
api: NetworkEndpointApi(String::from("WS2P")),
api_version: 0,
network_features: EndpointV2NetworkFeatures(vec![]),
api_features: ApiFeatures(vec![]),
ip_v4: None,
ip_v6: None,
host: Some(String::from("localhost")),
port: 10900u16,
path: None,
};
test_parse_and_read_endpoint(str_endpoint, endpoint.clone());
// test get_url()
assert_eq!(
endpoint.get_url(true, false),
Some("ws://localhost:10900/".to_owned())
);
}
#[test]
fn test_parse_and_read_classic_v1_endpoint() {
let str_endpoint = "ES_CORE_API g1.data.duniter.fr 443";
......@@ -596,7 +619,12 @@ mod tests {
port: 443u16,
path: Some(String::from("ws2p")),
};
test_parse_and_read_endpoint(str_endpoint, endpoint);
test_parse_and_read_endpoint(str_endpoint, endpoint.clone());
// test get_url()
assert_eq!(
endpoint.get_url(true, false),
Some("wss://g1.durs.ifee.fr:443/ws2p".to_owned()),
);
}
#[test]
......
......@@ -15,7 +15,6 @@ dup-crypto = { path = "../crypto" }
dubp-documents= { path = "../documents" }
durs-network-documents = { path = "../network-documents" }
durs-ws2p-messages = { path = "../ws2p-messages" }
duniter-documents = { path = "../documents" }
duniter-message= { path = "../message" }
duniter-module = { path = "../module" }
duniter-network = { path = "../network" }
......
......@@ -15,14 +15,14 @@
//! Defined all network documents
use duniter_documents::v10::block::BlockDocument;
use duniter_documents::v10::certification::CertificationDocument;
use duniter_documents::v10::identity::IdentityDocument;
use duniter_documents::v10::membership::MembershipDocument;
use duniter_documents::v10::revocation::RevocationDocument;
use duniter_documents::v10::transaction::TransactionDocument;
use duniter_documents::Document;
use duniter_documents::{BlockHash, BlockId, Blockstamp};
use dubp_documents::v10::block::BlockDocument;
use dubp_documents::v10::certification::CertificationDocument;
use dubp_documents::v10::identity::IdentityDocument;
use dubp_documents::v10::membership::MembershipDocument;
use dubp_documents::v10::revocation::RevocationDocument;
use dubp_documents::v10::transaction::TransactionDocument;
use dubp_documents::Document;
use dubp_documents::{BlockHash, BlockId, Blockstamp};
use serde_json;
use std::ops::Deref;
......
......@@ -16,6 +16,7 @@
//! Defined network requests.
use documents::*;
use dubp_documents::Blockstamp;
use duniter_module::*;
use *;
......
......@@ -24,7 +24,7 @@ use controllers::ws::{util::Token, CloseCode, /*Frame,*/ Handler, Handshake, Mes
use controllers::*;
use services::*;
//use dup_crypto::keys::KeyPairEnum;
use duniter_documents::CurrencyName;
use dubp_documents::CurrencyName;
use durs_network_documents::NodeFullId;
//use durs_ws2p_messages::v2::api_features::WS2PFeatures;
use durs_ws2p_messages::v2::connect::generate_connect_message;
......
......@@ -15,7 +15,7 @@
//! WS2P incoming connections controllers.
use duniter_documents::CurrencyName;
use dubp_documents::CurrencyName;
//use duniter_module::ModuleReqId;
use controllers::handler::Ws2pConnectionHandler;
use controllers::ws::deflate::DeflateBuilder;
......
......@@ -19,7 +19,7 @@ extern crate ws;
//use constants::*;
use self::ws::Sender;
use duniter_documents::Blockstamp;
use dubp_documents::Blockstamp;
use dup_crypto::hashs::Hash;
//use dup_crypto::keys::*;
use durs_network_documents::network_peer::PeerCardV11;
......
......@@ -15,7 +15,7 @@
//! WS2P outgoing connections controllers.
use duniter_documents::CurrencyName;
use dubp_documents::CurrencyName;
//use duniter_module::ModuleReqId;
use controllers::handler::Ws2pConnectionHandler;
use controllers::ws::connect;
......
// Copyright (C) 2018 The Durs Project Developers.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Generate self peer card
use bincode;
use dubp_documents::{Blockstamp, CurrencyName};
use dup_crypto::keys::PubKey;
use durs_network_documents::network_endpoint::*;
use durs_network_documents::network_peer::*;
use durs_network_documents::*;
pub fn _self_peer_update_endpoints(
self_peer: PeerCardV11,
blockstamp: Blockstamp,
new_endpoints: Vec<EndpointEnum>,
) -> PeerCardV11 {
let max_eps = self_peer.endpoints.len() + self_peer.endpoints_str.len() + new_endpoints.len();
let apis: Vec<NetworkEndpointApi> = new_endpoints
.iter()
.filter(|ep| {
if let EndpointEnum::V2(_) = ep {
true
} else {
false
}
})
.map(|ep| ep.api())
.collect();
let mut new_endpoints_bin = Vec::with_capacity(max_eps);
let mut new_endpoints_str = Vec::with_capacity(max_eps);
for ep in self_peer.endpoints {
if !apis.contains(&ep.api) {
new_endpoints_bin.push(ep);
}
}
for ep in self_peer.endpoints_str {
let ep_clone = ep.clone();
let ep_fields: Vec<&str> = ep_clone.split(' ').collect();
if !apis.contains(&NetworkEndpointApi(ep_fields[0].to_owned())) {
new_endpoints_str.push(ep);
}
}
for ep in new_endpoints {
if let EndpointEnum::V2(ep_v2) = ep {
let bin_len = bincode::serialize(&ep_v2)
.unwrap_or_else(|_| {
panic!(
"Fail to update self peer : invalid endpoint : {:?} !",
ep_v2
)
})
.len();
let str_ep = ep_v2.to_string();
if str_ep.len() < bin_len {
new_endpoints_str.push(str_ep);
} else {
new_endpoints_bin.push(ep_v2);
}
}
}
PeerCardV11 {
currency_name: self_peer.currency_name,
issuer: self_peer.issuer,
node_id: self_peer.node_id,
blockstamp,
endpoints: new_endpoints_bin,
endpoints_str: new_endpoints_str,
sig: None,
}
}
pub fn _generate_self_peer(
currency_name: CurrencyName,
issuer: PubKey,
node_id: NodeId,
blockstamp: Blockstamp,
endpoints: Vec<EndpointEnum>,
) -> PeerCardV11 {
let mut endpoints_bin = Vec::with_capacity(endpoints.len());
let mut endpoints_str = Vec::with_capacity(endpoints.len());
for ep in endpoints {
if let EndpointEnum::V2(ep_v2) = ep {
let bin_len = bincode::serialize(&ep_v2)
.unwrap_or_else(|_| {
panic!(
"Fail to generate self peer : invalid endpoint : {:?} !",
ep_v2
)
})
.len();
let str_ep = ep_v2.to_string();
if str_ep.len() < bin_len {
endpoints_str.push(str_ep);
} else {
endpoints_bin.push(ep_v2);
}
}
}
PeerCardV11 {
currency_name,
issuer,
node_id,
blockstamp,
endpoints: endpoints_bin,
endpoints_str,
sig: None,
}
}
......@@ -45,8 +45,8 @@ extern crate durs_network_documents;
extern crate durs_ws2p_messages;
mod constants;
mod generate_peer;
pub mod controllers;
mod generate_peer;
pub mod services;
use constants::*;
......
......@@ -15,7 +15,7 @@
//! WS2P outgoing Services
use duniter_documents::CurrencyName;
use dubp_documents::CurrencyName;
use durs_network_documents::NodeFullId;
use services::*;
use std::collections::HashMap;
......@@ -87,12 +87,21 @@ impl WS2POutgoingService {
}
/// Connect to WSPv2 Endpoint
pub fn connect_to_ws2p_v2_endpoint(&self, endpoint: &EndpointEnum) -> Result<(), WsError> {
pub fn connect_to_ws2p_v2_endpoint(
&self,
endpoint: &EndpointEnum,
remote_node_id: Option<NodeId>,
) -> Result<(), WsError> {
let expected_remote_full_id = if let Some(remote_node_id) = remote_node_id {
Some(NodeFullId(remote_node_id, endpoint.pubkey()))
} else {
None
};
match controllers::outgoing_connections::connect_to_ws2p_v2_endpoint(
&self.currency,
&self.sender,
&self.self_node,
endpoint.node_full_id(),
expected_remote_full_id,
endpoint,
) {
Ok(_) => Ok(()),
......
extern crate duniter_documents;
extern crate dubp_documents;
extern crate dup_crypto;
extern crate durs_network_documents;
extern crate durs_ws2p;
extern crate durs_ws2p_messages;
use duniter_documents::CurrencyName;
use dubp_documents::CurrencyName;
use dup_crypto::keys::KeyPair;
use dup_crypto::keys::*;
use durs_network_documents::network_endpoint::*;
......@@ -103,7 +103,7 @@ fn test_connection_negociation() {
server_node_clone.my_node_id,
server_node_clone.my_key_pair.public_key(),
)),
&EndpointV2::parse_from_raw(&format!("WS2P 2 0 0 {} localhost", *PORT), 0, 0)
&EndpointV2::parse_from_raw(&format!("WS2P 2 localhost {}", *PORT))
.expect("Fail to parse 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