Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make it possible to have use-native-tls without use-rustls #932

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rumqttc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Replace `Vec<Option<u16>>` with `FixedBitSet` for managing packet ids of released QoS 2 publishes and incoming QoS 2 publishes in `MqttState`.
* Accept `native_tls::TlsConnector` as input for `Transport::tls_with_config`.
* Update `thiserror` to `2.0.8`, `tokio-rustls` to `0.26.0`, `rustls-webpki` to `0.102.8`, `rustls-pemfile` to `2.2.0`, `rustls-native-certs` to `0.8.1`, `async-tungstenite` to `0.28.0`, `ws_stream_tungstenite` to `0.14.0`, `native-tls` to `0.2.12` and `tokio-stream` to `0.1.16`.
* `use-native-tls` and `url` can be used without rustls.

### Deprecated

Expand Down
24 changes: 20 additions & 4 deletions rumqttc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl Transport {
Self::Tcp
}

#[cfg(feature = "use-rustls")]
#[cfg(any(feature = "use-rustls", feature = "use-native-tls"))]
pub fn tls_with_default_config() -> Self {
Self::tls_with_config(Default::default())
}
Expand Down Expand Up @@ -311,8 +311,17 @@ impl Transport {
Self::Wss(tls_config)
}

#[cfg(all(feature = "use-rustls", feature = "websocket"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "use-rustls", feature = "websocket"))))]
#[cfg(all(
any(feature = "use-rustls", feature = "use-native-tls"),
feature = "websocket"
))]
#[cfg_attr(
docsrs,
doc(cfg(all(
any(feature = "use-rustls", feature = "use-native-tls"),
feature = "websocket"
)))
)]
pub fn wss_with_default_config() -> Self {
Self::Wss(Default::default())
}
Expand Down Expand Up @@ -365,6 +374,13 @@ impl Default for TlsConfiguration {
}
}

#[cfg(all(feature = "use-native-tls", not(feature = "use-rustls")))]
impl Default for TlsConfiguration {
fn default() -> Self {
Self::Native
}
}

#[cfg(feature = "use-rustls")]
impl From<ClientConfig> for TlsConfiguration {
fn from(config: ClientConfig) -> Self {
Expand Down Expand Up @@ -783,7 +799,7 @@ impl std::convert::TryFrom<url::Url> for MqttOptions {
// Encrypted connections are supported, but require explicit TLS configuration. We fall
// back to the unencrypted transport layer, so that `set_transport` can be used to
// configure the encrypted transport layer with the provided TLS configuration.
#[cfg(feature = "use-rustls")]
#[cfg(any(feature = "use-rustls", feature = "use-native-tls"))]
"mqtts" | "ssl" => (Transport::tls_with_default_config(), 8883),
"mqtt" | "tcp" => (Transport::Tcp, 1883),
#[cfg(feature = "websocket")]
Expand Down
22 changes: 17 additions & 5 deletions rumqttc/src/v5/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl MqttState {
}
_ => {
warn!("SubAck Pkid = {:?}, Reason = {:?}", suback.pkid, reason);
},
}
}
}
Ok(None)
Expand Down Expand Up @@ -364,7 +364,10 @@ impl MqttState {
if puback.reason != PubAckReason::Success
&& puback.reason != PubAckReason::NoMatchingSubscribers
{
warn!("PubAck Pkid = {:?}, reason: {:?}", puback.pkid, puback.reason);
warn!(
"PubAck Pkid = {:?}, reason: {:?}",
puback.pkid, puback.reason
);
return Ok(None);
}

Expand Down Expand Up @@ -397,7 +400,10 @@ impl MqttState {
if pubrec.reason != PubRecReason::Success
&& pubrec.reason != PubRecReason::NoMatchingSubscribers
{
warn!("PubRec Pkid = {:?}, reason: {:?}", pubrec.pkid, pubrec.reason);
warn!(
"PubRec Pkid = {:?}, reason: {:?}",
pubrec.pkid, pubrec.reason
);
return Ok(None);
}

Expand All @@ -417,7 +423,10 @@ impl MqttState {
self.incoming_pub.set(pubrel.pkid as usize, false);

if pubrel.reason != PubRelReason::Success {
warn!("PubRel Pkid = {:?}, reason: {:?}", pubrel.pkid, pubrel.reason);
warn!(
"PubRel Pkid = {:?}, reason: {:?}",
pubrel.pkid, pubrel.reason
);
return Ok(None);
}

Expand All @@ -444,7 +453,10 @@ impl MqttState {
self.outgoing_rel.set(pubcomp.pkid as usize, false);

if pubcomp.reason != PubCompReason::Success {
warn!("PubComp Pkid = {:?}, reason: {:?}", pubcomp.pkid, pubcomp.reason);
warn!(
"PubComp Pkid = {:?}, reason: {:?}",
pubcomp.pkid, pubcomp.reason
);
return Ok(None);
}

Expand Down