Compare commits

...

3 Commits

  1. 20
      Cargo.toml
  2. 2
      examples/server-custom-accept.rs
  3. 26
      src/async_std.rs
  4. 10
      src/async_tls.rs
  5. 2
      src/compat.rs
  6. 10
      src/gio.rs
  7. 12
      src/handshake.rs
  8. 30
      src/lib.rs
  9. 10
      src/tokio.rs
  10. 4
      src/tokio/async_tls.rs
  11. 10
      src/tokio/dummy_tls.rs
  12. 8
      src/tokio/native_tls.rs
  13. 8
      src/tokio/openssl.rs
  14. 10
      src/tokio/rustls.rs
  15. 2
      tests/communication.rs

@ -1,7 +1,7 @@
[package]
name = "async-tungstenite"
description = "Async binding for Tungstenite, the Lightweight stream-based WebSocket implementation"
categories = ["web-programming::websocket", "network-programming", "asynchronous", "concurrency"]
name = "ng-async-tungstenite"
description = "fork of async-tungstenite for NextGraph.org"
categories = []
keywords = ["websocket", "io", "web", "tokio", "async-std"]
authors = ["Sebastian Dröge <sebastian@centricular.com>"]
license = "MIT"
@ -16,20 +16,20 @@ rust-version = "1.64"
[features]
default = ["handshake"]
handshake = ["tungstenite/handshake"]
handshake = ["ng-tungstenite/handshake"]
async-std-runtime = ["async-std", "handshake"]
tokio-runtime = ["tokio", "handshake"]
gio-runtime = ["gio", "glib", "handshake"]
async-tls = ["real-async-tls", "handshake"]
async-native-tls = ["async-std-runtime", "real-async-native-tls", "tungstenite/native-tls"]
tokio-native-tls = ["tokio-runtime", "real-tokio-native-tls", "real-native-tls", "tungstenite/native-tls"]
async-native-tls = ["async-std-runtime", "real-async-native-tls", "ng-tungstenite/native-tls"]
tokio-native-tls = ["tokio-runtime", "real-tokio-native-tls", "real-native-tls", "ng-tungstenite/native-tls"]
tokio-rustls-manual-roots = ["__rustls-tls"]
tokio-rustls-webpki-roots = ["__rustls-tls", "webpki-roots"]
tokio-rustls-native-certs = ["__rustls-tls", "rustls-native-certs"]
tokio-openssl = ["tokio-runtime", "real-tokio-openssl", "openssl"]
verbose-logging = []
__rustls-tls = ["tokio-runtime", "real-tokio-rustls", "tungstenite/__rustls-tls"]
__rustls-tls = ["tokio-runtime", "real-tokio-rustls", "ng-tungstenite/__rustls-tls"]
[package.metadata.docs.rs]
features = ["async-std-runtime", "tokio-runtime", "gio-runtime", "async-tls", "async-native-tls", "tokio-native-tls"]
@ -40,9 +40,11 @@ futures-util = { version = "0.3", default-features = false, features = ["sink",
futures-io = { version = "0.3", default-features = false, features = ["std"] }
pin-project-lite = "0.2"
[dependencies.tungstenite]
version = "0.19"
[dependencies.ng-tungstenite]
git = "https://git.nextgraph.org/NextGraph/tungstenite-rs.git"
branch = "nextgraph"
default-features = false
version = "0.19.0"
[dependencies.async-std]
optional = true

@ -40,7 +40,7 @@ use futures_channel::mpsc::{unbounded, UnboundedSender};
use futures_util::{future, pin_mut, stream::TryStreamExt, StreamExt};
use async_tungstenite::{tokio::TokioAdapter, WebSocketStream};
use tungstenite::{
use ng_tungstenite::{
handshake::derive_accept_key,
protocol::{Message, Role},
};

@ -1,8 +1,8 @@
//! `async-std` integration.
use tungstenite::client::IntoClientRequest;
use tungstenite::handshake::client::{Request, Response};
use tungstenite::protocol::WebSocketConfig;
use tungstenite::Error;
use ng_tungstenite::client::IntoClientRequest;
use ng_tungstenite::handshake::client::{Request, Response};
use ng_tungstenite::protocol::WebSocketConfig;
use ng_tungstenite::Error;
use async_std::net::TcpStream;
@ -17,10 +17,10 @@ pub(crate) mod async_native_tls {
use async_native_tls::TlsStream;
use real_async_native_tls as async_native_tls;
use tungstenite::client::uri_mode;
use tungstenite::handshake::client::Request;
use tungstenite::stream::Mode;
use tungstenite::Error;
use ng_tungstenite::client::uri_mode;
use ng_tungstenite::handshake::client::Request;
use ng_tungstenite::stream::Mode;
use ng_tungstenite::Error;
use futures_io::{AsyncRead, AsyncWrite};
@ -95,10 +95,10 @@ pub(crate) mod async_native_tls {
pub(crate) mod dummy_tls {
use futures_io::{AsyncRead, AsyncWrite};
use tungstenite::client::{uri_mode, IntoClientRequest};
use tungstenite::handshake::client::Request;
use tungstenite::stream::Mode;
use tungstenite::Error;
use ng_tungstenite::client::{uri_mode, IntoClientRequest};
use ng_tungstenite::handshake::client::Request;
use ng_tungstenite::stream::Mode;
use ng_tungstenite::Error;
use crate::{client_async_with_config, domain, Response, WebSocketConfig, WebSocketStream};
@ -117,7 +117,7 @@ pub(crate) mod dummy_tls {
match mode {
Mode::Plain => Ok(socket),
Mode::Tls => Err(Error::Url(
tungstenite::error::UrlError::TlsFeatureNotEnabled,
ng_tungstenite::error::UrlError::TlsFeatureNotEnabled,
)),
}
}

@ -1,8 +1,8 @@
//! `async-tls` integration.
use tungstenite::client::{uri_mode, IntoClientRequest};
use tungstenite::handshake::client::{Request, Response};
use tungstenite::protocol::WebSocketConfig;
use tungstenite::Error;
use ng_tungstenite::client::{uri_mode, IntoClientRequest};
use ng_tungstenite::handshake::client::{Request, Response};
use ng_tungstenite::protocol::WebSocketConfig;
use ng_tungstenite::Error;
use futures_io::{AsyncRead, AsyncWrite};
@ -12,7 +12,7 @@ use async_tls::client::TlsStream;
use async_tls::TlsConnector as AsyncTlsConnector;
use real_async_tls as async_tls;
use tungstenite::stream::Mode;
use ng_tungstenite::stream::Mode;
use crate::domain;
use crate::stream::Stream as StreamSwitcher;

@ -6,8 +6,8 @@ use std::task::{Context, Poll};
use futures_io::{AsyncRead, AsyncWrite};
use futures_util::task;
use ng_tungstenite::Error as WsError;
use std::sync::Arc;
use tungstenite::Error as WsError;
pub(crate) enum ContextWaker {
Read,

@ -1,5 +1,5 @@
//! `gio` integration.
use tungstenite::Error;
use ng_tungstenite::Error;
use std::io;
@ -7,10 +7,10 @@ use gio::prelude::*;
use futures_io::{AsyncRead, AsyncWrite};
use tungstenite::client::{uri_mode, IntoClientRequest};
use tungstenite::handshake::client::Request;
use tungstenite::handshake::server::{Callback, NoCallback};
use tungstenite::stream::Mode;
use ng_tungstenite::client::{uri_mode, IntoClientRequest};
use ng_tungstenite::handshake::client::Request;
use ng_tungstenite::handshake::server::{Callback, NoCallback};
use ng_tungstenite::stream::Mode;
use crate::{client_async_with_config, domain, port, Response, WebSocketConfig, WebSocketStream};

@ -5,19 +5,19 @@ use crate::WebSocketStream;
use futures_io::{AsyncRead, AsyncWrite};
#[allow(unused_imports)]
use log::*;
use std::future::Future;
use std::io::{Read, Write};
use std::pin::Pin;
use std::task::{Context, Poll};
use tungstenite::WebSocket;
use ng_tungstenite::WebSocket;
#[cfg(feature = "handshake")]
use tungstenite::{
use ng_tungstenite::{
handshake::{
client::Response, server::Callback, HandshakeError as Error, HandshakeRole,
MidHandshake as WsHandshake,
},
ClientHandshake, ServerHandshake,
};
use std::future::Future;
use std::io::{Read, Write};
use std::pin::Pin;
use std::task::{Context, Poll};
pub(crate) async fn without_handshake<F, S>(stream: S, f: F) -> WebSocketStream<S>
where

@ -42,7 +42,7 @@
unused_import_braces
)]
pub use tungstenite;
pub use ng_tungstenite as tungstenite;
mod compat;
mod handshake;
@ -71,7 +71,7 @@ use std::pin::Pin;
use std::task::{Context, Poll};
#[cfg(feature = "handshake")]
use tungstenite::{
use ng_tungstenite::{
client::IntoClientRequest,
handshake::{
client::{ClientHandshake, Response},
@ -79,7 +79,7 @@ use tungstenite::{
HandshakeError,
},
};
use tungstenite::{
use ng_tungstenite::{
error::Error as WsError,
protocol::{Message, Role, WebSocket, WebSocketConfig},
};
@ -93,7 +93,7 @@ pub mod gio;
#[cfg(feature = "tokio-runtime")]
pub mod tokio;
use tungstenite::protocol::CloseFrame;
use ng_tungstenite::protocol::CloseFrame;
/// Creates a WebSocket handshake from a request and a stream.
/// For convenience, the user may call this with a url string, a URL,
@ -204,7 +204,7 @@ where
C: Callback + Unpin,
{
let f = handshake::server_handshake(stream, move |allow_std| {
tungstenite::accept_hdr_with_config(allow_std, callback, config)
ng_tungstenite::accept_hdr_with_config(allow_std, callback, config)
});
f.await.map_err(|e| match e {
HandshakeError::Failure(e) => e,
@ -436,8 +436,8 @@ where
/// Get a domain from an URL.
#[inline]
pub(crate) fn domain(
request: &tungstenite::handshake::client::Request,
) -> Result<String, tungstenite::Error> {
request: &ng_tungstenite::handshake::client::Request,
) -> Result<String, ng_tungstenite::Error> {
request
.uri()
.host()
@ -455,8 +455,8 @@ pub(crate) fn domain(
host.to_owned()
})
.ok_or(tungstenite::Error::Url(
tungstenite::error::UrlError::NoHostName,
.ok_or(ng_tungstenite::Error::Url(
ng_tungstenite::error::UrlError::NoHostName,
))
}
@ -468,8 +468,8 @@ pub(crate) fn domain(
/// Get the port from an URL.
#[inline]
pub(crate) fn port(
request: &tungstenite::handshake::client::Request,
) -> Result<u16, tungstenite::Error> {
request: &ng_tungstenite::handshake::client::Request,
) -> Result<u16, ng_tungstenite::Error> {
request
.uri()
.port_u16()
@ -478,8 +478,8 @@ pub(crate) fn port(
Some("ws") => Some(80),
_ => None,
})
.ok_or(tungstenite::Error::Url(
tungstenite::error::UrlError::UnsupportedUrlScheme,
.ok_or(ng_tungstenite::Error::Url(
ng_tungstenite::error::UrlError::UnsupportedUrlScheme,
))
}
@ -493,7 +493,7 @@ mod tests {
))]
#[test]
fn domain_strips_ipv6_brackets() {
use tungstenite::client::IntoClientRequest;
use ng_tungstenite::client::IntoClientRequest;
let request = "ws://[::1]:80".into_client_request().unwrap();
assert_eq!(crate::domain(&request).unwrap(), "::1");
@ -502,7 +502,7 @@ mod tests {
#[cfg(feature = "handshake")]
#[test]
fn requests_cannot_contain_invalid_uris() {
use tungstenite::client::IntoClientRequest;
use ng_tungstenite::client::IntoClientRequest;
assert!("ws://[".into_client_request().is_err());
assert!("ws://[blabla/bla".into_client_request().is_err());

@ -1,9 +1,9 @@
//! `tokio` integration.
use tungstenite::client::IntoClientRequest;
use tungstenite::handshake::client::{Request, Response};
use tungstenite::handshake::server::{Callback, NoCallback};
use tungstenite::protocol::WebSocketConfig;
use tungstenite::Error;
use ng_tungstenite::client::IntoClientRequest;
use ng_tungstenite::handshake::client::{Request, Response};
use ng_tungstenite::handshake::server::{Callback, NoCallback};
use ng_tungstenite::protocol::WebSocketConfig;
use ng_tungstenite::Error;
use tokio::net::TcpStream;

@ -1,8 +1,8 @@
use real_async_tls::client::TlsStream;
use real_async_tls::TlsConnector;
use tungstenite::client::IntoClientRequest;
use tungstenite::Error;
use ng_tungstenite::client::IntoClientRequest;
use ng_tungstenite::Error;
use crate::stream::Stream as StreamSwitcher;
use crate::{Response, WebSocketConfig, WebSocketStream};

@ -1,7 +1,7 @@
use tungstenite::client::{uri_mode, IntoClientRequest};
use tungstenite::handshake::client::Request;
use tungstenite::stream::Mode;
use tungstenite::Error;
use ng_tungstenite::client::{uri_mode, IntoClientRequest};
use ng_tungstenite::handshake::client::Request;
use ng_tungstenite::stream::Mode;
use ng_tungstenite::Error;
use super::TokioAdapter;
@ -23,7 +23,7 @@ where
match mode {
Mode::Plain => Ok(TokioAdapter::new(socket)),
Mode::Tls => Err(Error::Url(
tungstenite::error::UrlError::TlsFeatureNotEnabled,
ng_tungstenite::error::UrlError::TlsFeatureNotEnabled,
)),
}
}

@ -1,10 +1,10 @@
use real_tokio_native_tls::TlsConnector as AsyncTlsConnector;
use real_tokio_native_tls::TlsStream;
use tungstenite::client::{uri_mode, IntoClientRequest};
use tungstenite::handshake::client::Request;
use tungstenite::stream::Mode;
use tungstenite::Error;
use ng_tungstenite::client::{uri_mode, IntoClientRequest};
use ng_tungstenite::handshake::client::Request;
use ng_tungstenite::stream::Mode;
use ng_tungstenite::Error;
use crate::stream::Stream as StreamSwitcher;
use crate::{client_async_with_config, domain, Response, WebSocketConfig, WebSocketStream};

@ -1,10 +1,10 @@
use openssl::ssl::{ConnectConfiguration, SslConnector, SslMethod};
use real_tokio_openssl::SslStream as TlsStream;
use tungstenite::client::{uri_mode, IntoClientRequest};
use tungstenite::handshake::client::Request;
use tungstenite::stream::Mode;
use tungstenite::Error;
use ng_tungstenite::client::{uri_mode, IntoClientRequest};
use ng_tungstenite::handshake::client::Request;
use ng_tungstenite::stream::Mode;
use ng_tungstenite::Error;
use crate::stream::Stream as StreamSwitcher;
use crate::{client_async_with_config, domain, Response, WebSocketConfig, WebSocketStream};

@ -1,11 +1,11 @@
use real_tokio_rustls::rustls::{ClientConfig, RootCertStore, ServerName};
use real_tokio_rustls::{client::TlsStream, TlsConnector};
use tungstenite::client::{uri_mode, IntoClientRequest};
use tungstenite::error::TlsError;
use tungstenite::handshake::client::Request;
use tungstenite::stream::Mode;
use tungstenite::Error;
use ng_tungstenite::client::{uri_mode, IntoClientRequest};
use ng_tungstenite::error::TlsError;
use ng_tungstenite::handshake::client::Request;
use ng_tungstenite::stream::Mode;
use ng_tungstenite::Error;
use std::convert::TryFrom;

@ -5,7 +5,7 @@ use async_std::task;
use async_tungstenite::{accept_async, client_async, WebSocketStream};
use futures::prelude::*;
use log::*;
use tungstenite::Message;
use ng_tungstenite::Message;
async fn run_connection<S>(
connection: WebSocketStream<S>,

Loading…
Cancel
Save