Skip to content

Commit 5c06ae5

Browse files
committed
Commit for v3.0.0
1 parent 275cd5c commit 5c06ae5

File tree

9 files changed

+59
-19
lines changed

9 files changed

+59
-19
lines changed

CHANGELOG.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,23 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [Unrelesed]
8+
## v3.0.0 - 2024-07-11
9+
10+
### Changed
11+
12+
* use the same version as in docker hub
913

1014
### Added
1115

1216
* Add maxclients in example
1317
* Document Health upstream
1418
* Add OpenShift deployment examples
19+
* remove jemalloc usage
20+
* Update sequenceDiagram in README.md
21+
* add `WouldBlock` in `proxy()`
22+
* increase buffer for proxy response reading to `8192`
23+
* Add error log output in `copy` function
24+
* Add docker hub link
1525

1626
## v1.0.1 - 2024-06-27
1727

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tls-proxy-tunnel"
3-
version = "1.0.1"
3+
version = "3.0.0"
44
edition = "2021"
55
authors = ["Aleksandar Lazic <[email protected]>"]
66
license = "Apache-2.0"

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ For detailed configuration, check [this example](./config.yaml.example).
105105
TPT_CONFIG=container-files/etc/tpt/config.yaml cargo run
106106
```
107107

108+
## Docker
109+
110+
There is a container Image about this tool.
111+
[tls-proxy-tunnel](https://hub.docker.com/r/me2digital/tls-proxy-tunnel)
112+
108113
## Thanks
109114

110115
- [`fourth`](https://crates.io/crates/fourth), of which this is a heavily modified fork.

container-files/etc/tpt/config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ servers:
1616
sni:
1717
www.test1.com: proxy-via
1818
default: echo
19-
maxclients: 3
19+
maxclients: 10
2020
via:
2121
*viaanchor
2222

src/servers/protocol/tcp.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ use log::{debug, error, info, warn};
55
use std::error::Error;
66
use std::sync::atomic::Ordering;
77
use std::sync::Arc;
8-
use tokio::net::{TcpListener, TcpStream};
8+
use tokio::{
9+
io::{self},
10+
net::{TcpListener, TcpStream},
11+
};
912

1013
pub(crate) async fn proxy(config: Arc<Proxy>) -> Result<(), Box<dyn Error>> {
1114
let listener = TcpListener::bind(config.listen).await?;
@@ -24,6 +27,9 @@ pub(crate) async fn proxy(config: Arc<Proxy>) -> Result<(), Box<dyn Error>> {
2427
let permit = config.maxclients.clone().acquire_owned().await.unwrap();
2528

2629
match listener.accept().await {
30+
Err(e) if e.kind() == io::ErrorKind::WouldBlock => {
31+
continue;
32+
}
2733
Err(err) => {
2834
error!("Failed to accept connection: {}", err);
2935
return Err(Box::new(err));
@@ -51,9 +57,9 @@ async fn accept(inbound: TcpStream, proxy: Arc<Proxy>) -> Result<(), Box<dyn Err
5157
} else {
5258
let old = GLOBAL_THREAD_COUNT.fetch_add(1, Ordering::SeqCst);
5359
info!(
54-
"New connection from {:?} , num :{:?}: Current Connections :{:?}",
60+
"New connection from {:?} , old :{:?}: Current Connections :{:?}",
5561
inbound.peer_addr()?,
56-
old + 1,
62+
old,
5763
GLOBAL_THREAD_COUNT
5864
);
5965
}
@@ -106,20 +112,18 @@ async fn accept(inbound: TcpStream, proxy: Arc<Proxy>) -> Result<(), Box<dyn Err
106112
} else {
107113
let old = GLOBAL_THREAD_COUNT.fetch_sub(1, Ordering::SeqCst);
108114
info!(
109-
"Connection closed for {:?}, num :{:?}: Current Connections :{:?}",
115+
"OKAY: Connection closed for {:?}, old :{:?}: Current Connections :{:?}",
110116
upstream_name, old, GLOBAL_THREAD_COUNT
111117
);
112-
//drop(permit);
113118
Ok(())
114119
}
115120
}
116121
Err(e) => {
117122
let old = GLOBAL_THREAD_COUNT.fetch_sub(1, Ordering::SeqCst);
118123
info!(
119-
"Connection closed for {:?}, num :{:?}: Current Connections :{:?}",
124+
"ERROR: Connection closed for {:?}, num :{:?}: Current Connections :{:?}",
120125
upstream_name, old, GLOBAL_THREAD_COUNT
121126
);
122-
//drop(permit);
123127
error!("my error {:?}", e);
124128
Ok(())
125129
}

src/upstreams/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use hyper::server::conn::http1;
77
use hyper::service::service_fn;
88
use hyper::{Request, Response};
99
use hyper_util::rt::TokioIo;
10-
use log::debug;
10+
use log::{debug, error};
1111
use serde::Deserialize;
1212
use std::convert::Infallible;
1313
use std::error::Error;
@@ -78,7 +78,11 @@ where
7878
let _ = writer.shutdown().await;
7979
Ok(u64)
8080
}
81-
Err(_) => Ok(0),
81+
Err(e) => {
82+
let _ = writer.shutdown().await;
83+
error!("Copy issue {:?}", e);
84+
Ok(0)
85+
}
8286
}
8387
}
8488

src/upstreams/proxy_to_upstream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl ProxyToUpstream {
162162

163163
// Creating the buffer **after** the `await` prevents it from
164164
// being stored in the async task.
165-
let mut inbufs = vec![0; 4096];
165+
let mut inbufs = vec![0; 8192];
166166
//let decoder = LinesCodec::new();
167167
//let proxy_response = String::new();
168168

tests/k6-tls-test.js

+22-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
import http from 'k6/http';
2-
import { check } from 'k6';
2+
import { check, sleep} from 'k6';
3+
import instance from 'k6/execution';
4+
35

46
export const options = {
7+
discardResponseBodies: true,
8+
batchPerHost: 10,
9+
scenarios: {
10+
default: {
11+
executor: 'constant-vus',
12+
vus: 16,
13+
duration: '10s',
14+
},
15+
},
516
tlsCipherSuites: ['TLS_RSA_WITH_RC4_128_SHA', 'TLS_RSA_WITH_AES_128_GCM_SHA256'],
617
tlsVersion: {
718
min: 'tls1.1',
@@ -13,8 +24,14 @@ export const options = {
1324

1425
export default function () {
1526
const res = http.get('https://www.test1.com:8080');
16-
check(res, {
17-
'is TLSv1.2': (r) => r.tls_version === http.TLS_1_2,
18-
'is sha256 cipher suite': (r) => r.tls_cipher_suite === 'TLS_RSA_WITH_AES_128_GCM_SHA256',
19-
});
27+
// check(res, {
28+
// 'is TLSv1.2': (r) => r.tls_version === http.TLS_1_2,
29+
// 'is sha256 cipher suite': (r) => r.tls_cipher_suite === 'TLS_RSA_WITH_AES_128_GCM_SHA256',
30+
// });
31+
32+
//console.log(`step1: scenario ran for ${instance.vusActive}`);
33+
34+
// Injecting sleep
35+
// Total iteration time is sleep + time to finish request.
36+
sleep(0.5);
2037
}

0 commit comments

Comments
 (0)