Skip to content

Commit

Permalink
re-added TCP stack, due to Quic blocking and censorship in some networks
Browse files Browse the repository at this point in the history
  • Loading branch information
MathJud committed May 26, 2024
1 parent ec737d1 commit f213872
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 62 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Changed
- Upgraded many libraries to new versions.
- removed old versions of unmaintained `sled` versions, which were only used for the upgrade procedure to qaul 2.0.0 beta 18.
This means that upgrading to qaul version 2.0.0 beta 19 is only possible from qaul version 2.0.0 beta 18.
- Removed TCP connection stack, in favor for the new UDP/QUIC protocol for interconnections.
- Configuration auto-upgrade of all static TCP peer entries to use the QUIC protocol for interconnections.

## [2.0.0 beta 18] 2024-04-11

Expand Down
2 changes: 1 addition & 1 deletion rust/libqaul/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ crate-type = ["cdylib", "staticlib", "rlib"]
default = []

[dependencies]
libp2p = { version = "0.53.2", features = ["async-std", "macros", "floodsub", "identify", "mdns", "noise", "ping", "quic", "dns", "macros"] }
libp2p = { version = "0.53.2", features = ["async-std", "macros", "floodsub", "identify", "mdns", "noise", "ping", "tcp", "yamux", "quic", "dns", "macros"] }
async-std = { version = "1.12", features = ["attributes"] }
futures = "0.3"
serde = {version = "1.0", features = ["derive"] }
Expand Down
12 changes: 10 additions & 2 deletions rust/libqaul/src/connections/internet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@
//! do_listen: false
//! listen:
//! - /ip4/0.0.0.0/udp/9229/quic-v1
//! - /ip4/0.0.0.0/tcp/9229
//! - /ip6/::/udp/9229/quic-v1
//! - /ip6/::/tcp/9229
//! ```

use libp2p::{
floodsub::{Floodsub, FloodsubEvent},
identify,
identity::Keypair,
ping,
noise, ping,
swarm::{NetworkBehaviour, Swarm},
Multiaddr, PeerId, SwarmBuilder,
tcp, yamux, Multiaddr, PeerId, SwarmBuilder,
};
use prost::Message;
use state::InitCell;
Expand Down Expand Up @@ -220,6 +222,12 @@ impl Internet {

let mut swarm = SwarmBuilder::with_existing_identity(node_keys.to_owned())
.with_async_std()
.with_tcp(
tcp::Config::new().nodelay(true),
noise::Config::new,
yamux::Config::default,
)
.unwrap()
.with_quic()
.with_behaviour(|key| {
log::trace!("internal INTERNET node ID: {:?}", key.public().to_peer_id());
Expand Down
12 changes: 10 additions & 2 deletions rust/libqaul/src/connections/lan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
//! active: true
//! listen:
//! - /ip4/0.0.0.0/udp/0/quic-v1
//! - /ip4/0.0.0.0/tcp/0
//! - /ip6/::/udp/0/quic-v1
//! - /ip6/::/tcp/0
//! ```

use libp2p::{
floodsub::{Floodsub, FloodsubEvent},
identity::Keypair,
mdns, ping,
mdns, noise, ping,
swarm::{NetworkBehaviour, Swarm},
SwarmBuilder,
tcp, yamux, SwarmBuilder,
};
use prost::Message;
use std::time::Duration;
Expand Down Expand Up @@ -187,6 +189,12 @@ impl Lan {

let mut swarm = SwarmBuilder::with_existing_identity(node_keys.to_owned())
.with_async_std()
.with_tcp(
tcp::Config::new().nodelay(true),
noise::Config::new,
yamux::Config::default,
)
.unwrap()
.with_quic()
.with_behaviour(|key| {
log::trace!("internal LAN node ID: {:?}", key.public().to_peer_id());
Expand Down
10 changes: 9 additions & 1 deletion rust/libqaul/src/storage/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ impl Default for Lan {
active: true,
listen: vec![
String::from("/ip4/0.0.0.0/udp/0/quic-v1"),
String::from("/ip4/0.0.0.0/tcp/0"),
String::from("/ip6/::/udp/0/quic-v1"),
String::from("/ip6/::/tcp/0"),
],
}
}
Expand Down Expand Up @@ -91,7 +93,11 @@ impl Default for Internet {
#[allow(unused_variables)]
let listen_ipv4_quic: String = format!("/ip4/0.0.0.0/udp/{}/quic-v1", port);
#[allow(unused_variables)]
let listen_ipv4: String = format!("/ip4/0.0.0.0/tcp/{}", port);
#[allow(unused_variables)]
let listen_ipv6_quic: String = format!("/ip6/::/udp/{}/quic-v1", port);
#[allow(unused_variables)]
let listen_ipv6: String = format!("/ip6/::/tcp/{}", port);

Internet {
active: true,
Expand All @@ -104,10 +110,12 @@ impl Default for Internet {
#[cfg(any(target_os = "android", target_os = "ios"))]
listen: vec![
String::from("/ip4/0.0.0.0/udp/9229/quic-v1"),
String::from("/ip4/0.0.0.0/tcp/9229"),
String::from("/ip6/::/udp/9229/quic-v1"),
String::from("/ip6/::/tcp/9229"),
],
#[cfg(not(any(target_os = "android", target_os = "ios")))]
listen: vec![listen_ipv4_quic, listen_ipv6_quic],
listen: vec![listen_ipv4_quic, listen_ipv4, listen_ipv6_quic, listen_ipv6],
}
}
}
Expand Down
59 changes: 4 additions & 55 deletions rust/libqaul/src/utilities/upgrade/v2_0_0_rc_1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
//!
//! Changes to be upgraded:
//!
//! * configuration file: remove all TCP listen entries
//! - config.internet.listen
//! - config.lan.listen
//! * configuration file: change all TCP peer entries to UDP/QUIC entries
//! - config.internet.peers

Expand Down Expand Up @@ -72,22 +69,13 @@ impl VersionUpgrade {
keys: old_cfg.node.keys.clone(),
};

// remove all non QUIC LAN listening interfaces
let mut listen_lan: Vec<String> = vec![];
for entry in old_cfg.lan.listen.iter() {
if Self::multiaddr_is_quic(entry) {
listen_lan.push(entry.to_string());
}
}
if listen_lan.len() == 0 {
listen_lan.push(String::from("/ip4/0.0.0.0/udp/0/quic-v1"));
listen_lan.push(String::from("/ip6/::/udp/0/quic-v1"));
}
// Copy LAN section
let lan = crate::storage::configuration::Lan {
active: old_cfg.lan.active,
listen: listen_lan,
listen: old_cfg.lan.listen.clone(),
};

// Internet section update
// change TCP peer addresses to QUIC addresses
let mut peers: Vec<crate::storage::configuration::InternetPeer> = vec![];
for peer in &old_cfg.internet.peers {
Expand All @@ -102,31 +90,11 @@ impl VersionUpgrade {
None => {}
}
}

// remove all non QUIC internet listening interfaces
let mut listen_internet: Vec<String> = vec![];
for entry in old_cfg.internet.listen.iter() {
if Self::multiaddr_is_quic(entry) {
listen_internet.push(entry.to_string());
}
}
if listen_internet.len() == 0 {
#[cfg(any(target_os = "android", target_os = "ios"))]
{
listen_internet.push(String::from("/ip4/0.0.0.0/udp/9229/quic-v1"));
listen_internet.push(String::from("/ip6/::/udp/9229/quic-v1"));
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
{
listen_internet.push(String::from("/ip4/0.0.0.0/udp/0/quic-v1"));
listen_internet.push(String::from("/ip6/::/udp/0/quic-v1"));
}
}
let internet = crate::storage::configuration::Internet {
active: old_cfg.internet.active,
peers,
do_listen: old_cfg.internet.do_listen,
listen: listen_internet,
listen: old_cfg.internet.listen.clone(),
};

// copy user account
Expand Down Expand Up @@ -183,25 +151,6 @@ impl VersionUpgrade {
}
}

/// check if a multi-address is UDP?
fn multiaddr_is_quic(multiaddr_string: &String) -> bool {
let multiaddr: Multiaddr = multiaddr_string.parse().unwrap();

// check if it is a udp address
let protocols = multiaddr.protocol_stack().collect::<Vec<_>>();
if protocols.len() < 2 {
return false;
}
if protocols[1] != "udp" {
return false;
}
if protocols[2] != "quic-v1" {
return false;
}

false
}

/// change TCP multi-address to UDP/QUIC
fn multiaddr_to_quic(multiaddr_string: &String) -> Option<Multiaddr> {
let multiaddr: Multiaddr = multiaddr_string.parse().unwrap();
Expand Down

0 comments on commit f213872

Please sign in to comment.