Skip to content

Commit 859c4b0

Browse files
authored
Upgrade tokio to v1 (#61)
* upgrade to tokio v1 Signed-off-by: Petros Angelatos <[email protected]> * fix warning about renamed lint Signed-off-by: Petros Angelatos <[email protected]> * fix cargo fmt and cargo clippy warnings Signed-off-by: Petros Angelatos <[email protected]> * update base64 crate to 0.13 Signed-off-by: Petros Angelatos <[email protected]> * update hmac and sha2 crates Signed-off-by: Petros Angelatos <[email protected]> * update derive builder to 0.10 Signed-off-by: Petros Angelatos <[email protected]> * uritemplate is unmaintained, switch to uritemplate-next Signed-off-by: Petros Angelatos <[email protected]> * update minimum rust version in CI to 1.46 rust >= 1.41 is required to build subtle, see: dalek-cryptography/subtle#77 rust >= 1.42 is required for the stabilization of the matches! macro rust >= 1.43 is required for inclusion of usize::MAX required by socket2 which is required by hyper rust >= 1.46 is required to allow match and if statements inside const expressions, which is required by socket2 which is required by hyper Signed-off-by: Petros Angelatos <[email protected]> * ignore failing test due to missing CI credentials Signed-off-by: Petros Angelatos <[email protected]>
1 parent 2505adb commit 859c4b0

File tree

22 files changed

+53
-52
lines changed

22 files changed

+53
-52
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: rust
22
rust:
3-
- 1.39.0
3+
- 1.46.0
44
- stable
55
- beta
66
- nightly

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
[![Build Status](https://travis-ci.com/pubnub/rust.svg?branch=master)](https://travis-ci.com/pubnub/rust)
44
[![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/)
55

6-
The PubNub Rust SDK is based on Tokio `0.2`. This library uses `HTTP/2` to communicate with the PubNub Edge Messaging Network.
6+
The PubNub Rust SDK is based on Tokio `1.0`. This library uses `HTTP/2` to communicate with the PubNub Edge Messaging Network.
77

88
## MSRV
99

10-
Supports Rust 1.39.0 and higher.
10+
Supports Rust 1.46.0 and higher.
1111

1212
## Get Started
1313

pubnub-core/src/data/uuid.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::ops::Deref;
55
/// A unique alphanumeric ID for identifying the client to the PubNub Presence
66
/// System, as well as for PubNub Analytics.
77
#[derive(Debug, Clone, PartialEq, Eq)]
8+
#[allow(clippy::upper_case_acronyms)]
89
pub struct UUID(String);
910

1011
impl UUID {

pubnub-core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
missing_docs,
1616
missing_debug_implementations,
1717
missing_copy_implementations,
18-
intra_doc_link_resolution_failure
18+
broken_intra_doc_links
1919
)]
2020
#![allow(clippy::doc_markdown)]
2121
#![forbid(unsafe_code)]

pubnub-core/src/subscription/message_destinations.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ mod tests {
5555
use crate::data::message::{self, Message};
5656
use crate::data::pubsub;
5757

58-
fn route_channel_wildcard(s: &'static str) -> Option<message::Route> {
58+
fn route_channel_wildcard(s: &'static str) -> message::Route {
5959
let val = s.parse().unwrap();
60-
Some(message::Route::ChannelWildcard(val))
60+
message::Route::ChannelWildcard(val)
6161
}
6262

63-
fn route_channel_group(s: &'static str) -> Option<message::Route> {
63+
fn route_channel_group(s: &'static str) -> message::Route {
6464
let val = s.parse().unwrap();
65-
Some(message::Route::ChannelGroup(val))
65+
message::Route::ChannelGroup(val)
6666
}
6767

6868
fn message(route: Option<message::Route>, channel: &'static str) -> Message {
@@ -88,15 +88,15 @@ mod tests {
8888
);
8989

9090
assert_iter_eq(
91-
&message(route_channel_wildcard("qwe.*"), "test"),
91+
&message(Some(route_channel_wildcard("qwe.*")), "test"),
9292
&[
9393
pubsub::SubscribeTo::ChannelWildcard("qwe.*".parse().unwrap()),
9494
pubsub::SubscribeTo::Channel("test".parse().unwrap()),
9595
],
9696
);
9797

9898
assert_iter_eq(
99-
&message(route_channel_group("qwe"), "test"),
99+
&message(Some(route_channel_group("qwe")), "test"),
100100
&[
101101
pubsub::SubscribeTo::ChannelGroup("qwe".parse().unwrap()),
102102
pubsub::SubscribeTo::Channel("test".parse().unwrap()),

pubnub-core/src/subscription/subscribe_loop_supervisor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ impl SubscribeLoopSupervisor {
4545
}
4646

4747
impl SubscribeLoopSupervisor {
48-
pub async fn subscribe<'a, TTransport, TRuntime>(
48+
pub async fn subscribe<TTransport, TRuntime>(
4949
&mut self,
50-
pubnub: &'a mut PubNub<TTransport, TRuntime>,
50+
pubnub: &mut PubNub<TTransport, TRuntime>,
5151
to: pubsub::SubscribeTo,
5252
) -> Subscription<TRuntime>
5353
where

pubnub-core/src/subscription/subscription.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@ fn is_drop_send_result_error(result: Result<(), mpsc::SendError>) -> bool {
7171
// successfully.
7272
false
7373
}
74-
_ => true,
74+
Err(_) => true,
7575
}
7676
}

pubnub-hyper/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ license-file = "../LICENSE"
1515
pubnub-core = { version = "=0.1.0", path = "../pubnub-core" }
1616
pubnub-util = { version = "=0.1.0", path = "../pubnub-util", default-features = false, features = ["uritemplate_api", "pam_signature"] }
1717
async-trait = "0.1"
18-
derive_builder = "0.9"
18+
derive_builder = "0.10.0-alpha"
1919
error-iter = "0.2"
2020
futures-util = { version = "0.3", features = ["async-await", "async-await-macro"] }
2121
getset = "0.1"
2222
http = "0.2"
23-
hyper = { version = "0.13.3", features = ["stream"] }
24-
hyper-tls = "0.4"
23+
hyper = { version = "0.14", features = ["client", "http1", "http2", "stream"] }
24+
hyper-tls = "0.5"
2525
log = "0.4"
2626
thiserror = "1.0"
27-
tokio = "0.2"
27+
tokio = { version = "1", features = ["rt-multi-thread"] }
2828

2929
[dev-dependencies]
3030
pubnub-test-util = { version = "0.1", path = "../pubnub-test-util" }
@@ -37,7 +37,7 @@ json = "0.12"
3737
log = "0.4"
3838
percent-encoding = "2.1"
3939
randomize = "3.0"
40-
tokio = { version = "0.2", features = ["macros"] }
40+
tokio = { version = "1", features = ["macros", "time"] }
4141

4242
[badges]
4343
travis-ci = { repository = "pubnub/rust", branch = "master" }

pubnub-hyper/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
missing_docs,
4646
missing_debug_implementations,
4747
missing_copy_implementations,
48-
intra_doc_link_resolution_failure
48+
broken_intra_doc_links
4949
)]
50-
#![allow(clippy::doc_markdown)]
50+
#![allow(clippy::default_trait_access, clippy::doc_markdown)]
5151
#![forbid(unsafe_code)]
5252

5353
/// Re-export core for ease of use.

pubnub-hyper/src/transport/hyper/history.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl TransportService<request::GetHistory> for Hyper {
6060

6161
// Parse response.
6262
let channels = parse_get_history(&data_json)
63-
.ok_or_else(|| error::Error::UnexpectedResponseSchema(data_json))?;
63+
.ok_or(error::Error::UnexpectedResponseSchema(data_json))?;
6464
Ok(channels)
6565
}
6666
}
@@ -130,7 +130,7 @@ impl TransportService<request::MessageCountsWithTimetoken> for Hyper {
130130

131131
// Parse response.
132132
let channels = parse_message_counts(&data_json)
133-
.ok_or_else(|| error::Error::UnexpectedResponseSchema(data_json))?;
133+
.ok_or(error::Error::UnexpectedResponseSchema(data_json))?;
134134
Ok(channels)
135135
}
136136
}
@@ -165,7 +165,7 @@ impl TransportService<request::MessageCountsWithChannelTimetokens> for Hyper {
165165

166166
// Parse response.
167167
let channels = parse_message_counts(&data_json)
168-
.ok_or_else(|| error::Error::UnexpectedResponseSchema(data_json))?;
168+
.ok_or(error::Error::UnexpectedResponseSchema(data_json))?;
169169
Ok(channels)
170170
}
171171
}

pubnub-hyper/src/transport/hyper/pam.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl TransportService<request::Grant> for Hyper {
2121
let secret_key = self
2222
.secret_key
2323
.as_ref()
24-
.ok_or_else(|| error::Configuration::SecretKeyUnavailable)?;
24+
.ok_or(error::Configuration::SecretKeyUnavailable)?;
2525

2626
// Prepare the request body and the signature.
2727
let body = prepare_grant_body(request);

pubnub-hyper/src/transport/hyper/presence.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl HereNowParse<presence::respond_with::OccupancyAndUUIDs> for () {
7171
data_json: &json::JsonValue,
7272
) -> Option<
7373
<presence::respond_with::OccupancyAndUUIDs as presence::respond_with::RespondWith>::Response
74-
>{
74+
>{
7575
let occupancy = data_json["occupancy"].as_u64()?;
7676

7777
let occupants = {
@@ -147,7 +147,7 @@ impl TransportService<request::SetState> for Hyper {
147147

148148
// Send network request.
149149
let response = self.http_client.get(url).await?;
150-
let _ = handle_presence_response(response).await?;
150+
handle_presence_response(response).await?;
151151

152152
Ok(())
153153
}
@@ -216,7 +216,7 @@ impl TransportService<request::HereNow<presence::respond_with::OccupancyOnly>> f
216216

217217
// Parse response.
218218
let value = HereNowParse::<presence::respond_with::OccupancyOnly>::parse(&(), &data_json)
219-
.ok_or_else(|| error::Error::UnexpectedResponseSchema(data_json))?;
219+
.ok_or(error::Error::UnexpectedResponseSchema(data_json))?;
220220
Ok(value)
221221
}
222222
}
@@ -253,7 +253,7 @@ impl TransportService<request::HereNow<presence::respond_with::OccupancyAndUUIDs
253253
// Parse response.
254254
let value =
255255
HereNowParse::<presence::respond_with::OccupancyAndUUIDs>::parse(&(), &data_json)
256-
.ok_or_else(|| error::Error::UnexpectedResponseSchema(data_json))?;
256+
.ok_or(error::Error::UnexpectedResponseSchema(data_json))?;
257257
Ok(value)
258258
}
259259
}
@@ -289,7 +289,7 @@ impl TransportService<request::HereNow<presence::respond_with::Full>> for Hyper
289289

290290
// Parse response.
291291
let value = HereNowParse::<presence::respond_with::Full>::parse(&(), &data_json)
292-
.ok_or_else(|| error::Error::UnexpectedResponseSchema(data_json))?;
292+
.ok_or(error::Error::UnexpectedResponseSchema(data_json))?;
293293
Ok(value)
294294
}
295295
}
@@ -319,7 +319,7 @@ impl TransportService<request::GlobalHereNow<presence::respond_with::OccupancyOn
319319
// Parse response.
320320
let value =
321321
HereNowParse::<presence::respond_with::OccupancyOnly>::parse_global(&(), &data_json)
322-
.ok_or_else(|| error::Error::UnexpectedResponseSchema(data_json))?;
322+
.ok_or(error::Error::UnexpectedResponseSchema(data_json))?;
323323
Ok(value)
324324
}
325325
}
@@ -351,7 +351,7 @@ impl TransportService<request::GlobalHereNow<presence::respond_with::OccupancyAn
351351
&(),
352352
&data_json,
353353
)
354-
.ok_or_else(|| error::Error::UnexpectedResponseSchema(data_json))?;
354+
.ok_or(error::Error::UnexpectedResponseSchema(data_json))?;
355355
Ok(value)
356356
}
357357
}
@@ -380,7 +380,7 @@ impl TransportService<request::GlobalHereNow<presence::respond_with::Full>> for
380380

381381
// Parse response.
382382
let value = HereNowParse::<presence::respond_with::Full>::parse_global(&(), &data_json)
383-
.ok_or_else(|| error::Error::UnexpectedResponseSchema(data_json))?;
383+
.ok_or(error::Error::UnexpectedResponseSchema(data_json))?;
384384
Ok(value)
385385
}
386386
}
@@ -445,7 +445,7 @@ impl TransportService<request::Heartbeat> for Hyper {
445445

446446
// Send network request.
447447
let response = self.http_client.get(url).await?;
448-
let _ = handle_presence_response(response).await?;
448+
handle_presence_response(response).await?;
449449

450450
Ok(())
451451
}

pubnub-hyper/src/transport/hyper/pubsub.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ impl TransportService<request::Subscribe> for Hyper {
7979
let data_json = handle_json_response(response).await?;
8080

8181
// Parse response.
82-
let (messages, timetoken) = parse_subscribe(&data_json)
83-
.ok_or_else(|| error::Error::UnexpectedResponseSchema(data_json))?;
82+
let (messages, timetoken) =
83+
parse_subscribe(&data_json).ok_or(error::Error::UnexpectedResponseSchema(data_json))?;
8484
Ok((messages, timetoken))
8585
}
8686
}

pubnub-hyper/src/transport/hyper/shared_parsers.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ pub enum ParseMessageError {
4444
pub fn parse_message(message: &json::object::Object) -> Result<Message, ParseMessageError> {
4545
let message = Message {
4646
message_type: parse_message_type(&message["e"]).ok_or(ParseMessageError::Type)?,
47-
route: parse_message_route(&message["b"]).map_err(|_| ParseMessageError::Route)?,
47+
route: parse_message_route(&message["b"]).or(Err(ParseMessageError::Route))?,
4848
channel: message["c"]
4949
.as_str()
5050
.ok_or(ParseMessageError::Channel)?
5151
.parse()
52-
.map_err(|_| ParseMessageError::Channel)?,
52+
.or(Err(ParseMessageError::Channel))?,
5353
json: message["d"].clone(),
5454
metadata: message["u"].clone(),
5555
timetoken: Timetoken {
5656
t: message["p"]["t"]
5757
.as_str()
5858
.ok_or(ParseMessageError::Timetoken)?
5959
.parse()
60-
.map_err(|_| ParseMessageError::Timetoken)?,
60+
.or(Err(ParseMessageError::Timetoken))?,
6161
r: message["p"]["r"].as_u32().unwrap_or(0),
6262
},
6363
client: message["i"].as_str().map(std::borrow::ToOwned::to_owned),

pubnub-hyper/tests/common/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ pub fn init() {
55
}
66

77
pub fn current_thread_block_on<F: Future>(future: F) -> F::Output {
8-
let mut rt = tokio::runtime::Builder::new()
8+
let rt = tokio::runtime::Builder::new_current_thread()
99
.enable_all()
10-
.basic_scheduler()
1110
.build()
1211
.expect("unable to build tokio runtime");
1312
rt.block_on(future)

pubnub-hyper/tests/history.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mod common;
1010
/// Delay execution for the specified amount of milliseconds.
1111
async fn sleep(ms: u64) {
1212
info!(target: "pubnub", "Sleeping for {} ms", ms);
13-
tokio::time::delay_for(std::time::Duration::from_millis(ms)).await
13+
tokio::time::sleep(std::time::Duration::from_millis(ms)).await
1414
}
1515

1616
/// Generate a string of random numbers.

pubnub-hyper/tests/pam.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ fn secret_key_from_env() -> String {
1212
}
1313

1414
#[test]
15+
#[ignore]
1516
fn grant() {
1617
common::init();
1718
common::current_thread_block_on(async {

pubnub-hyper/tests/presence.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const SAMPLE_UUID: &str = "903145ee-7c15-4579-aa5d-38a900717512";
1616
/// Delay execution for the specified amount of milliseconds.
1717
async fn sleep(ms: u64) {
1818
info!(target: "pubnub", "Sleeping for {} ms", ms);
19-
tokio::time::delay_for(std::time::Duration::from_millis(ms)).await
19+
tokio::time::sleep(std::time::Duration::from_millis(ms)).await
2020
}
2121

2222
/// Generate a string of random numbers.

pubnub-test-util/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
missing_docs,
77
missing_debug_implementations,
88
missing_copy_implementations,
9-
intra_doc_link_resolution_failure
9+
broken_intra_doc_links
1010
)]
1111
#![allow(clippy::doc_markdown)]
1212
#![forbid(unsafe_code)]

pubnub-util/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ readme = "../README.md"
1212
license-file = "../LICENSE"
1313

1414
[dependencies]
15-
base64 = { version = "0.12", optional = true }
16-
hmac = { version = "0.7", optional = true }
15+
base64 = { version = "0.13", optional = true }
16+
hmac = { version = "0.10", optional = true }
1717
percent-encoding = { version = "2.1", optional = true }
18-
sha2 = { version = "0.8", optional = true }
19-
uritemplate = { version = "0.1", optional = true }
18+
sha2 = { version = "0.9", optional = true }
19+
uritemplate-next = { version = "0.2", optional = true }
2020

2121
[features]
2222
default = ["url-encoded-list", "uritemplate_api", "pam_signature"]
2323
url-encoded-list = ["percent-encoding"]
24-
uritemplate_api = ["uritemplate"]
24+
uritemplate_api = ["uritemplate-next"]
2525
pam_signature = ["hmac", "sha2", "base64"]
2626

2727
[badges]

pubnub-util/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
missing_docs,
88
missing_debug_implementations,
99
missing_copy_implementations,
10-
intra_doc_link_resolution_failure
10+
broken_intra_doc_links
1111
)]
1212
#![allow(clippy::doc_markdown)]
1313
#![forbid(unsafe_code)]

pubnub-util/src/pam_signature.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! PAM v3 signature implemetnation.
22
3-
use hmac::{Hmac, Mac};
3+
use hmac::{Hmac, Mac, NewMac};
44
use sha2::Sha256;
55

66
/// The request to sign.
@@ -43,8 +43,8 @@ type HmacSha256 = Hmac<Sha256>;
4343

4444
fn encrypt(secret: &str, plain_message: &str) -> [u8; 32] {
4545
let mut mac = HmacSha256::new_varkey(secret.as_bytes()).expect("HMAC can take key of any size");
46-
mac.input(plain_message.as_bytes());
47-
let code = mac.result().code();
46+
mac.update(plain_message.as_bytes());
47+
let code = mac.finalize().into_bytes();
4848
code.into()
4949
}
5050

0 commit comments

Comments
 (0)