-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ebc1ca3
commit faea387
Showing
17 changed files
with
570 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use crate::{error::*, globals::Globals, http_client::HttpClientInner}; | ||
use std::sync::Arc; | ||
use tokio::sync::RwLock; | ||
|
||
#[derive(Debug)] | ||
/// DoH, ODoH, MODoH client | ||
pub struct DoHClient { | ||
inner: Arc<RwLock<HttpClientInner>>, | ||
} | ||
|
||
impl DoHClient { | ||
/// Create a new DoH client | ||
pub fn new(inner: Arc<RwLock<HttpClientInner>>) -> Self { | ||
Self { inner } | ||
} | ||
|
||
/// Make DoH query | ||
pub async fn make_doh_query(&self, packet_buf: &[u8], globals: &Arc<Globals>) -> Result<Vec<u8>> { | ||
Ok(vec![]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
use crate::log::*; | ||
use std::sync::atomic::{AtomicUsize, Ordering}; | ||
use std::sync::Arc; | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum CounterType { | ||
Tcp, | ||
Udp, | ||
} | ||
impl CounterType { | ||
fn as_str(&self) -> &'static str { | ||
match self { | ||
CounterType::Tcp => "TCP", | ||
CounterType::Udp => "UDP", | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, Default)] | ||
/// Connection counter | ||
pub struct ConnCounter { | ||
pub cnt_total: Arc<AtomicUsize>, | ||
pub cnt_udp: Arc<AtomicUsize>, | ||
pub cnt_tcp: Arc<AtomicUsize>, | ||
} | ||
|
||
impl ConnCounter { | ||
pub fn get_current_total(&self) -> usize { | ||
self.cnt_total.load(Ordering::Relaxed) | ||
} | ||
|
||
pub fn get_current(&self, ctype: CounterType) -> usize { | ||
match ctype { | ||
CounterType::Tcp => self.cnt_tcp.load(Ordering::Relaxed), | ||
CounterType::Udp => self.cnt_udp.load(Ordering::Relaxed), | ||
} | ||
} | ||
|
||
pub fn increment(&self, ctype: CounterType) -> usize { | ||
self.cnt_total.fetch_add(1, Ordering::Relaxed); | ||
let c = match ctype { | ||
CounterType::Tcp => self.cnt_tcp.fetch_add(1, Ordering::Relaxed), | ||
CounterType::Udp => self.cnt_udp.fetch_add(1, Ordering::Relaxed), | ||
}; | ||
|
||
debug!( | ||
"{} connection count++: {} (total = {})", | ||
&ctype.as_str(), | ||
self.get_current(ctype), | ||
self.get_current_total() | ||
); | ||
c | ||
} | ||
|
||
pub fn decrement(&self, ctype: CounterType) { | ||
let cnt; | ||
match ctype { | ||
CounterType::Tcp => { | ||
let res = { | ||
cnt = self.cnt_tcp.load(Ordering::Relaxed); | ||
cnt > 0 | ||
&& self | ||
.cnt_tcp | ||
.compare_exchange(cnt, cnt - 1, Ordering::Relaxed, Ordering::Relaxed) | ||
!= Ok(cnt) | ||
}; | ||
if res {} | ||
} | ||
CounterType::Udp => { | ||
let res = { | ||
cnt = self.cnt_udp.load(Ordering::Relaxed); | ||
cnt > 0 | ||
&& self | ||
.cnt_udp | ||
.compare_exchange(cnt, cnt - 1, Ordering::Relaxed, Ordering::Relaxed) | ||
!= Ok(cnt) | ||
}; | ||
if res {} | ||
} | ||
}; | ||
self.cnt_total.store( | ||
self.cnt_udp.load(Ordering::Relaxed) + self.cnt_tcp.load(Ordering::Relaxed), | ||
Ordering::Relaxed, | ||
); | ||
|
||
debug!( | ||
"{} connection count--: {} (total = {})", | ||
&ctype.as_str(), | ||
self.get_current(ctype), | ||
self.get_current_total() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
mod counter; | ||
mod proxy_main; | ||
mod proxy_tcp; | ||
mod proxy_udp; | ||
mod socket; | ||
|
||
pub use proxy_main::Proxy; |
Oops, something went wrong.