Skip to content

Commit f1729e4

Browse files
committed
deps: upgrade to tokio v1.0 ecosystem
1 parent 07aa69f commit f1729e4

File tree

12 files changed

+63
-30
lines changed

12 files changed

+63
-30
lines changed

postgres-native-tls/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ runtime = ["tokio-postgres/runtime"]
1818
[dependencies]
1919
futures = "0.3"
2020
native-tls = "0.2"
21-
tokio = "0.3"
22-
tokio-native-tls = "0.2"
21+
tokio = "1.0"
22+
tokio-native-tls = "0.3"
2323
tokio-postgres = { version = "0.6.0", path = "../tokio-postgres", default-features = false }
2424

2525
[dev-dependencies]
26-
tokio = { version = "0.3", features = ["full"] }
26+
tokio = { version = "1.0", features = ["full"] }
2727
postgres = { version = "0.18.0", path = "../postgres" }

postgres-openssl/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ runtime = ["tokio-postgres/runtime"]
1818
[dependencies]
1919
futures = "0.3"
2020
openssl = "0.10"
21-
tokio = "0.3"
22-
tokio-openssl = "0.5"
21+
tokio = "1.0"
22+
tokio-openssl = "0.6"
2323
tokio-postgres = { version = "0.6.0", path = "../tokio-postgres", default-features = false }
2424

2525
[dev-dependencies]
26-
tokio = { version = "0.3", features = ["full"] }
26+
tokio = { version = "1.0", features = ["full"] }
2727
postgres = { version = "0.18.0", path = "../postgres" }

postgres-openssl/src/lib.rs

+42-8
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,18 @@ use openssl::hash::MessageDigest;
4848
use openssl::nid::Nid;
4949
#[cfg(feature = "runtime")]
5050
use openssl::ssl::SslConnector;
51-
use openssl::ssl::{ConnectConfiguration, SslRef};
52-
use std::fmt::Debug;
51+
use openssl::ssl::{self, ConnectConfiguration, SslRef};
52+
use openssl::x509::X509VerifyResult;
53+
use std::error::Error;
54+
use std::fmt::{self, Debug};
5355
use std::future::Future;
5456
use std::io;
5557
use std::pin::Pin;
5658
#[cfg(feature = "runtime")]
5759
use std::sync::Arc;
5860
use std::task::{Context, Poll};
5961
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
60-
use tokio_openssl::{HandshakeError, SslStream};
62+
use tokio_openssl::SslStream;
6163
use tokio_postgres::tls;
6264
#[cfg(feature = "runtime")]
6365
use tokio_postgres::tls::MakeTlsConnect;
@@ -131,23 +133,55 @@ impl TlsConnector {
131133

132134
impl<S> TlsConnect<S> for TlsConnector
133135
where
134-
S: AsyncRead + AsyncWrite + Unpin + Debug + 'static + Sync + Send,
136+
S: AsyncRead + AsyncWrite + Unpin + Send + 'static,
135137
{
136138
type Stream = TlsStream<S>;
137-
type Error = HandshakeError<S>;
139+
type Error = Box<dyn Error + Send + Sync>;
138140
#[allow(clippy::type_complexity)]
139-
type Future = Pin<Box<dyn Future<Output = Result<TlsStream<S>, HandshakeError<S>>> + Send>>;
141+
type Future = Pin<Box<dyn Future<Output = Result<TlsStream<S>, Self::Error>> + Send>>;
140142

141143
fn connect(self, stream: S) -> Self::Future {
142144
let future = async move {
143-
let stream = tokio_openssl::connect(self.ssl, &self.domain, stream).await?;
144-
Ok(TlsStream(stream))
145+
let ssl = self.ssl.into_ssl(&self.domain)?;
146+
let mut stream = SslStream::new(ssl, stream)?;
147+
match Pin::new(&mut stream).connect().await {
148+
Ok(()) => Ok(TlsStream(stream)),
149+
Err(error) => Err(Box::new(ConnectError {
150+
error,
151+
verify_result: stream.ssl().verify_result(),
152+
}) as _),
153+
}
145154
};
146155

147156
Box::pin(future)
148157
}
149158
}
150159

160+
#[derive(Debug)]
161+
struct ConnectError {
162+
error: ssl::Error,
163+
verify_result: X509VerifyResult,
164+
}
165+
166+
impl fmt::Display for ConnectError {
167+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
168+
fmt::Display::fmt(&self.error, fmt)?;
169+
170+
if self.verify_result != X509VerifyResult::OK {
171+
fmt.write_str(": ")?;
172+
fmt::Display::fmt(&self.verify_result, fmt)?;
173+
}
174+
175+
Ok(())
176+
}
177+
}
178+
179+
impl Error for ConnectError {
180+
fn source(&self) -> Option<&(dyn Error + 'static)> {
181+
Some(&self.error)
182+
}
183+
}
184+
151185
/// The stream returned by `TlsConnector`.
152186
pub struct TlsStream<S>(SslStream<S>);
153187

postgres-protocol/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ readme = "../README.md"
1111
[dependencies]
1212
base64 = "0.13"
1313
byteorder = "1.0"
14-
bytes = "0.5"
14+
bytes = "1.0"
1515
fallible-iterator = "0.2"
1616
hmac = "0.10"
1717
md5 = "0.7"

postgres-types/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ with-uuid-0_8 = ["uuid-08"]
2222
with-time-0_2 = ["time-02"]
2323

2424
[dependencies]
25-
bytes = "0.5"
25+
bytes = "1.0"
2626
fallible-iterator = "0.2"
2727
postgres-protocol = { version = "0.5.0", path = "../postgres-protocol" }
2828
postgres-derive = { version = "0.4.0", optional = true, path = "../postgres-derive" }

postgres-types/src/serde_json_1.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::{FromSql, IsNull, ToSql, Type};
2-
use bytes::buf::BufMutExt;
32
use bytes::{BufMut, BytesMut};
43
use serde_1::{Deserialize, Serialize};
54
use serde_json_1::Value;

postgres/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ with-uuid-0_8 = ["tokio-postgres/with-uuid-0_8"]
3131
with-time-0_2 = ["tokio-postgres/with-time-0_2"]
3232

3333
[dependencies]
34-
bytes = "0.5"
34+
bytes = "1.0"
3535
fallible-iterator = "0.2"
3636
futures = "0.3"
3737
tokio-postgres = { version = "0.6.0", path = "../tokio-postgres" }
3838

39-
tokio = { version = "0.3", features = ["rt", "time"] }
39+
tokio = { version = "1.0", features = ["rt", "time"] }
4040
log = "0.4"
4141

4242
[dev-dependencies]

postgres/src/copy_out_reader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl BufRead for CopyOutReader<'_> {
4646
};
4747
}
4848

49-
Ok(self.cur.bytes())
49+
Ok(&self.cur)
5050
}
5151

5252
fn consume(&mut self, amt: usize) {

postgres/src/notifications.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::connection::ConnectionRef;
44
use crate::{Error, Notification};
55
use fallible_iterator::FallibleIterator;
66
use futures::{ready, FutureExt};
7+
use std::pin::Pin;
78
use std::task::Poll;
89
use std::time::Duration;
910
use tokio::time::{self, Instant, Sleep};
@@ -64,7 +65,7 @@ impl<'a> Notifications<'a> {
6465
/// This iterator may start returning `Some` after previously returning `None` if more notifications are received.
6566
pub fn timeout_iter(&mut self, timeout: Duration) -> TimeoutIter<'_> {
6667
TimeoutIter {
67-
delay: self.connection.enter(|| time::sleep(timeout)),
68+
delay: Box::pin(self.connection.enter(|| time::sleep(timeout))),
6869
timeout,
6970
connection: self.connection.as_ref(),
7071
}
@@ -124,7 +125,7 @@ impl<'a> FallibleIterator for BlockingIter<'a> {
124125
/// A time-limited blocking iterator over pending notifications.
125126
pub struct TimeoutIter<'a> {
126127
connection: ConnectionRef<'a>,
127-
delay: Sleep,
128+
delay: Pin<Box<Sleep>>,
128129
timeout: Duration,
129130
}
130131

@@ -134,7 +135,7 @@ impl<'a> FallibleIterator for TimeoutIter<'a> {
134135

135136
fn next(&mut self) -> Result<Option<Self::Item>, Self::Error> {
136137
if let Some(notification) = self.connection.notifications_mut().pop_front() {
137-
self.delay.reset(Instant::now() + self.timeout);
138+
self.delay.as_mut().reset(Instant::now() + self.timeout);
138139
return Ok(Some(notification));
139140
}
140141

@@ -143,7 +144,7 @@ impl<'a> FallibleIterator for TimeoutIter<'a> {
143144
self.connection.poll_block_on(|cx, notifications, done| {
144145
match notifications.pop_front() {
145146
Some(notification) => {
146-
delay.reset(Instant::now() + timeout);
147+
delay.as_mut().reset(Instant::now() + timeout);
147148
return Poll::Ready(Ok(Some(notification)));
148149
}
149150
None if done => return Poll::Ready(Ok(None)),

tokio-postgres/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ with-time-0_2 = ["postgres-types/with-time-0_2"]
3838

3939
[dependencies]
4040
async-trait = "0.1"
41-
bytes = "0.5"
41+
bytes = "1.0"
4242
byteorder = "1.0"
4343
fallible-iterator = "0.2"
4444
futures = "0.3"
@@ -50,11 +50,11 @@ phf = "0.8"
5050
postgres-protocol = { version = "0.5.0", path = "../postgres-protocol" }
5151
postgres-types = { version = "0.1.2", path = "../postgres-types" }
5252
socket2 = "0.3"
53-
tokio = { version = "0.3", features = ["io-util"] }
54-
tokio-util = { version = "0.4", features = ["codec"] }
53+
tokio = { version = "1.0", features = ["io-util"] }
54+
tokio-util = { version = "0.6", features = ["codec"] }
5555

5656
[dev-dependencies]
57-
tokio = { version = "0.3", features = ["full"] }
57+
tokio = { version = "1.0", features = ["full"] }
5858
env_logger = "0.8"
5959
criterion = "0.3"
6060

tokio-postgres/src/binary_copy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl Stream for BinaryCopyOutStream {
153153
Some(header) => header.has_oids,
154154
None => {
155155
check_remaining(&chunk, HEADER_LEN)?;
156-
if &chunk.bytes()[..MAGIC.len()] != MAGIC {
156+
if !chunk.chunk().starts_with(MAGIC) {
157157
return Poll::Ready(Some(Err(Error::parse(io::Error::new(
158158
io::ErrorKind::InvalidData,
159159
"invalid magic value",

tokio-postgres/src/copy_in.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::client::{InnerClient, Responses};
22
use crate::codec::FrontendMessage;
33
use crate::connection::RequestMessages;
44
use crate::{query, slice_iter, Error, Statement};
5-
use bytes::buf::BufExt;
65
use bytes::{Buf, BufMut, BytesMut};
76
use futures::channel::mpsc;
87
use futures::future;

0 commit comments

Comments
 (0)