Skip to content

Commit

Permalink
Move Client struct Connection with the rest of structs
Browse files Browse the repository at this point in the history
  • Loading branch information
Lonami committed Oct 29, 2023
1 parent 0422a1c commit 191c838
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
17 changes: 12 additions & 5 deletions lib/grammers-client/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use super::net::Connection;
use grammers_mtsender::ReconnectionPolicy;
use grammers_mtproto::{mtp, transport};
use grammers_mtsender::{self as sender, ReconnectionPolicy, Sender};
use grammers_session::{ChatHashCache, MessageBox, Session};
use sender::Enqueuer;
use std::collections::{HashMap, VecDeque};
use std::fmt;
use std::net::SocketAddr;
use std::sync::Arc;
use std::sync::RwLock;
use std::sync::atomic::AtomicU32;
use std::sync::{Arc, RwLock};
use std::time::Instant;
use tokio::sync::RwLock as AsyncRwLock;
use tokio::sync::{Mutex as AsyncMutex, RwLock as AsyncRwLock};

/// When no locale is found, use this one instead.
const DEFAULT_LOCALE: &str = "en";
Expand Down Expand Up @@ -138,6 +139,12 @@ pub(crate) struct ClientState {
pub(crate) updates: VecDeque<crate::types::Update>,
}

pub(crate) struct Connection {
pub(crate) sender: AsyncMutex<Sender<transport::Full, mtp::Encrypted>>,
pub(crate) request_tx: RwLock<Enqueuer>,
pub(crate) step_counter: AtomicU32,
}

/// A client capable of connecting to Telegram and invoking requests.
///
/// This structure is the "entry point" of the library, from which you can start using the rest.
Expand Down
8 changes: 1 addition & 7 deletions lib/grammers-client/src/client/net.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::client::ClientState;
// Copyright 2020 - developers of the `grammers` project.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use super::client::{ClientState, Connection};
use super::{Client, ClientInner, Config};
use crate::utils;
use grammers_mtproto::mtp::{self, RpcError};
Expand Down Expand Up @@ -38,12 +38,6 @@ const DC_ADDRESSES: [(Ipv4Addr, u16); 6] = [

const DEFAULT_DC: i32 = 2;

pub(crate) struct Connection {
pub(crate) sender: AsyncMutex<Sender<transport::Full, mtp::Encrypted>>,
pub(crate) request_tx: RwLock<Enqueuer>,
pub(crate) step_counter: AtomicU32,
}

pub(crate) async fn connect_sender(
dc_id: i32,
config: &Config,
Expand Down

0 comments on commit 191c838

Please sign in to comment.