mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
aquatic_ws: add inline markers to functions that will probably be hot
This commit is contained in:
parent
3321f40697
commit
6c26331ffb
4 changed files with 25 additions and 0 deletions
|
|
@ -69,6 +69,7 @@ pub struct TorrentData {
|
||||||
|
|
||||||
|
|
||||||
impl Default for TorrentData {
|
impl Default for TorrentData {
|
||||||
|
#[inline]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
peers: IndexMap::new(),
|
peers: IndexMap::new(),
|
||||||
|
|
@ -109,6 +110,8 @@ impl OutMessageSender {
|
||||||
pub fn new(senders: Vec<Sender<(ConnectionMeta, OutMessage)>>) -> Self {
|
pub fn new(senders: Vec<Sender<(ConnectionMeta, OutMessage)>>) -> Self {
|
||||||
Self(senders)
|
Self(senders)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn send(
|
pub fn send(
|
||||||
&self,
|
&self,
|
||||||
meta: ConnectionMeta,
|
meta: ConnectionMeta,
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ pub enum Stream {
|
||||||
|
|
||||||
|
|
||||||
impl Stream {
|
impl Stream {
|
||||||
|
#[inline]
|
||||||
pub fn get_peer_addr(&self) -> SocketAddr {
|
pub fn get_peer_addr(&self) -> SocketAddr {
|
||||||
match self {
|
match self {
|
||||||
Self::TcpStream(stream) => stream.peer_addr().unwrap(),
|
Self::TcpStream(stream) => stream.peer_addr().unwrap(),
|
||||||
|
|
@ -47,6 +48,7 @@ impl Stream {
|
||||||
|
|
||||||
|
|
||||||
impl Read for Stream {
|
impl Read for Stream {
|
||||||
|
#[inline]
|
||||||
fn read(&mut self, buf: &mut [u8]) -> Result<usize, ::std::io::Error> {
|
fn read(&mut self, buf: &mut [u8]) -> Result<usize, ::std::io::Error> {
|
||||||
match self {
|
match self {
|
||||||
Self::TcpStream(stream) => stream.read(buf),
|
Self::TcpStream(stream) => stream.read(buf),
|
||||||
|
|
@ -57,6 +59,7 @@ impl Read for Stream {
|
||||||
|
|
||||||
|
|
||||||
impl Write for Stream {
|
impl Write for Stream {
|
||||||
|
#[inline]
|
||||||
fn write(&mut self, buf: &[u8]) -> ::std::io::Result<usize> {
|
fn write(&mut self, buf: &[u8]) -> ::std::io::Result<usize> {
|
||||||
match self {
|
match self {
|
||||||
Self::TcpStream(stream) => stream.write(buf),
|
Self::TcpStream(stream) => stream.write(buf),
|
||||||
|
|
@ -64,6 +67,7 @@ impl Write for Stream {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn flush(&mut self) -> ::std::io::Result<()> {
|
fn flush(&mut self) -> ::std::io::Result<()> {
|
||||||
match self {
|
match self {
|
||||||
Self::TcpStream(stream) => stream.flush(),
|
Self::TcpStream(stream) => stream.flush(),
|
||||||
|
|
@ -82,10 +86,12 @@ pub enum HandshakeMachine {
|
||||||
|
|
||||||
|
|
||||||
impl HandshakeMachine {
|
impl HandshakeMachine {
|
||||||
|
#[inline]
|
||||||
pub fn new(tcp_stream: TcpStream) -> Self {
|
pub fn new(tcp_stream: TcpStream) -> Self {
|
||||||
Self::TcpStream(tcp_stream)
|
Self::TcpStream(tcp_stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn advance(
|
pub fn advance(
|
||||||
self,
|
self,
|
||||||
opt_tls_acceptor: &Option<TlsAcceptor>, // If set, run TLS
|
opt_tls_acceptor: &Option<TlsAcceptor>, // If set, run TLS
|
||||||
|
|
@ -122,6 +128,7 @@ impl HandshakeMachine {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn handle_tls_handshake_result(
|
fn handle_tls_handshake_result(
|
||||||
result: Result<TlsStream<TcpStream>, ::native_tls::HandshakeError<TcpStream>>,
|
result: Result<TlsStream<TcpStream>, ::native_tls::HandshakeError<TcpStream>>,
|
||||||
) -> (Option<Either<EstablishedWs, Self>>, bool) {
|
) -> (Option<Either<EstablishedWs, Self>>, bool) {
|
||||||
|
|
@ -144,6 +151,7 @@ impl HandshakeMachine {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn handle_ws_handshake_result(
|
fn handle_ws_handshake_result(
|
||||||
result: Result<WebSocket<Stream>, HandshakeError<ServerHandshake<Stream, DebugCallback>>> ,
|
result: Result<WebSocket<Stream>, HandshakeError<ServerHandshake<Stream, DebugCallback>>> ,
|
||||||
) -> (Option<Either<EstablishedWs, Self>>, bool) {
|
) -> (Option<Either<EstablishedWs, Self>>, bool) {
|
||||||
|
|
@ -190,6 +198,7 @@ pub struct Connection {
|
||||||
/// Create from TcpStream. Run `advance_handshakes` until `get_established_ws`
|
/// Create from TcpStream. Run `advance_handshakes` until `get_established_ws`
|
||||||
/// returns Some(EstablishedWs).
|
/// returns Some(EstablishedWs).
|
||||||
impl Connection {
|
impl Connection {
|
||||||
|
#[inline]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
valid_until: ValidUntil,
|
valid_until: ValidUntil,
|
||||||
tcp_stream: TcpStream,
|
tcp_stream: TcpStream,
|
||||||
|
|
@ -200,6 +209,7 @@ impl Connection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn get_established_ws<'a>(&mut self) -> Option<&mut EstablishedWs> {
|
pub fn get_established_ws<'a>(&mut self) -> Option<&mut EstablishedWs> {
|
||||||
match self.inner {
|
match self.inner {
|
||||||
Either::Left(ref mut ews) => Some(ews),
|
Either::Left(ref mut ews) => Some(ews),
|
||||||
|
|
@ -207,6 +217,7 @@ impl Connection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn advance_handshakes(
|
pub fn advance_handshakes(
|
||||||
self,
|
self,
|
||||||
opt_tls_acceptor: &Option<TlsAcceptor>,
|
opt_tls_acceptor: &Option<TlsAcceptor>,
|
||||||
|
|
@ -227,6 +238,7 @@ impl Connection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn close(&mut self){
|
pub fn close(&mut self){
|
||||||
if let Either::Left(ref mut ews) = self.inner {
|
if let Either::Left(ref mut ews) = self.inner {
|
||||||
if ews.ws.can_read(){
|
if ews.ws.can_read(){
|
||||||
|
|
|
||||||
|
|
@ -192,12 +192,14 @@ struct ActionWrapper<T> {
|
||||||
|
|
||||||
|
|
||||||
impl <T>ActionWrapper<T> {
|
impl <T>ActionWrapper<T> {
|
||||||
|
#[inline]
|
||||||
pub fn announce(t: T) -> Self {
|
pub fn announce(t: T) -> Self {
|
||||||
Self {
|
Self {
|
||||||
action: Action::Announce,
|
action: Action::Announce,
|
||||||
inner: t
|
inner: t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[inline]
|
||||||
pub fn scrape(t: T) -> Self {
|
pub fn scrape(t: T) -> Self {
|
||||||
Self {
|
Self {
|
||||||
action: Action::Scrape,
|
action: Action::Scrape,
|
||||||
|
|
@ -217,6 +219,7 @@ pub enum InMessage {
|
||||||
impl InMessage {
|
impl InMessage {
|
||||||
/// Try parsing as announce request first. If that fails, try parsing as
|
/// Try parsing as announce request first. If that fails, try parsing as
|
||||||
/// scrape request, or return None
|
/// scrape request, or return None
|
||||||
|
#[inline]
|
||||||
pub fn from_ws_message(ws_message: tungstenite::Message) -> Option<Self> {
|
pub fn from_ws_message(ws_message: tungstenite::Message) -> Option<Self> {
|
||||||
use tungstenite::Message::{Text, Binary};
|
use tungstenite::Message::{Text, Binary};
|
||||||
|
|
||||||
|
|
@ -255,6 +258,7 @@ pub enum OutMessage {
|
||||||
|
|
||||||
|
|
||||||
impl OutMessage {
|
impl OutMessage {
|
||||||
|
#[inline]
|
||||||
pub fn to_ws_message(self) -> tungstenite::Message {
|
pub fn to_ws_message(self) -> tungstenite::Message {
|
||||||
let json = match self {
|
let json = match self {
|
||||||
Self::AnnounceResponse(message) => {
|
Self::AnnounceResponse(message) => {
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ impl<'de> Visitor<'de> for TwentyByteVisitor {
|
||||||
formatter.write_str("string consisting of 20 bytes")
|
formatter.write_str("string consisting of 20 bytes")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
|
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
|
||||||
where E: ::serde::de::Error,
|
where E: ::serde::de::Error,
|
||||||
{
|
{
|
||||||
|
|
@ -60,6 +61,7 @@ impl<'de> Visitor<'de> for TwentyByteVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn deserialize_20_bytes<'de, D>(
|
pub fn deserialize_20_bytes<'de, D>(
|
||||||
deserializer: D
|
deserializer: D
|
||||||
) -> Result<[u8; 20], D::Error>
|
) -> Result<[u8; 20], D::Error>
|
||||||
|
|
@ -79,6 +81,7 @@ impl<'de> Visitor<'de> for InfoHashVecVisitor {
|
||||||
formatter.write_str("string or array of strings consisting of 20 bytes")
|
formatter.write_str("string or array of strings consisting of 20 bytes")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
|
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
|
||||||
where E: ::serde::de::Error,
|
where E: ::serde::de::Error,
|
||||||
{
|
{
|
||||||
|
|
@ -88,6 +91,7 @@ impl<'de> Visitor<'de> for InfoHashVecVisitor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
|
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
|
||||||
where A: SeqAccess<'de>
|
where A: SeqAccess<'de>
|
||||||
{
|
{
|
||||||
|
|
@ -104,6 +108,7 @@ impl<'de> Visitor<'de> for InfoHashVecVisitor {
|
||||||
Ok(info_hashes)
|
Ok(info_hashes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn visit_none<E>(self) -> Result<Self::Value, E>
|
fn visit_none<E>(self) -> Result<Self::Value, E>
|
||||||
where E: ::serde::de::Error
|
where E: ::serde::de::Error
|
||||||
{
|
{
|
||||||
|
|
@ -114,6 +119,7 @@ impl<'de> Visitor<'de> for InfoHashVecVisitor {
|
||||||
|
|
||||||
/// Empty vector is returned if value is null or any invalid info hash
|
/// Empty vector is returned if value is null or any invalid info hash
|
||||||
/// is present
|
/// is present
|
||||||
|
#[inline]
|
||||||
pub fn deserialize_info_hashes<'de, D>(
|
pub fn deserialize_info_hashes<'de, D>(
|
||||||
deserializer: D
|
deserializer: D
|
||||||
) -> Result<Vec<InfoHash>, D::Error>
|
) -> Result<Vec<InfoHash>, D::Error>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue