-
Notifications
You must be signed in to change notification settings - Fork 20
Refactor TCP logic #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
1912fd8
refine code
ssrlive 5c2aa85
improve InvalidTcpPacket detail
ssrlive 5be5321
refine code
ssrlive ba10b6f
rustfmt max_width = 140
ssrlive 6cd3850
refine code
ssrlive 32486e4
remove useless IpStackPacketProtocol
ssrlive 240959f
Make the terminated UDP Session removed smoothly
ssrlive 4995594
rename tcp_timeout to timeout_interval
ssrlive 3f448e0
use SeqNum data type
ssrlive afa00cf
rename udp_timeout to timeout_interval
ssrlive 95ec6f6
use SeqNum in create_rev_packet
ssrlive b55293a
rename calculate_payload_len to calculate_payload_max_len
ssrlive d1e17bb
re-format code
ssrlive 8beadd0
refactor TCP logic
ssrlive e8ba6f7
remove the logic of DROP_TTL
ssrlive 5f10ae5
mod tcp_wrapper removed
ssrlive d81fd0d
TcpHeaderWrapper removed
ssrlive 6ff3a90
find_inflight_packet & get_all_inflight_packets
ssrlive dba2683
incoming_seq
ssrlive 3c60021
hide some log::trace
ssrlive 98bf25f
refactor retransmission logic
ssrlive 21a5a9c
packet_to_send: Option<NetworkPacket> removed
ssrlive bfd468b
minor changes in SeqNum
ssrlive 227f76e
payload alias
ssrlive 9cab122
Refactor completed
ssrlive 3736ec2
.env file support in examples
ssrlive 0d9a467
network_tuple method for IpStackTcpStream
ssrlive 2b94d4f
refine code
ssrlive dda57b8
move timeout timer from tcb to tcp
ssrlive 9f48ba8
refine code
ssrlive fb1b1fe
refine log info
ssrlive 6c90e6f
refine code
ssrlive f02436b
rename example tun2 to tun
ssrlive dda0369
refactor add_inflight_packet
ssrlive d5648d7
minor changes
ssrlive File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| .env | ||
| .vscode/ | ||
| .VSCodeCounter/ | ||
| /target/ | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
| //! | ||
| //! This example must be run as root or administrator privileges. | ||
| //! ``` | ||
| //! sudo target/debug/examples/tun2 --server-addr 127.0.0.1:8080 # Linux or macOS | ||
| //! sudo target/debug/examples/tun --server-addr 127.0.0.1:8080 # Linux or macOS | ||
| //! ``` | ||
| //! Then please run the `echo` example server, which listens on TCP & UDP ports 127.0.0.1:8080. | ||
| //! ``` | ||
|
|
@@ -28,7 +28,7 @@ | |
| //! | ||
|
|
||
| use clap::Parser; | ||
| use etherparse::{IcmpEchoHeader, Icmpv4Header}; | ||
| use etherparse::Icmpv4Header; | ||
| use ipstack::{stream::IpStackStream, IpNumber}; | ||
| use std::net::{Ipv4Addr, SocketAddr}; | ||
| use tokio::net::TcpStream; | ||
|
|
@@ -71,6 +71,7 @@ struct Args { | |
|
|
||
| #[tokio::main] | ||
| async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
| dotenvy::dotenv().ok(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did we use environment variables in this example?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, we use |
||
| let args = Args::parse(); | ||
|
|
||
| let default = format!("{:?}", args.verbosity); | ||
|
|
@@ -154,12 +155,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
| let n = number; | ||
| if u.src_addr().is_ipv4() && u.ip_protocol() == IpNumber::ICMP { | ||
| let (icmp_header, req_payload) = Icmpv4Header::from_slice(u.payload())?; | ||
| if let etherparse::Icmpv4Type::EchoRequest(req) = icmp_header.icmp_type { | ||
| if let etherparse::Icmpv4Type::EchoRequest(echo) = icmp_header.icmp_type { | ||
| log::info!("#{n} ICMPv4 echo"); | ||
| let echo = IcmpEchoHeader { | ||
| id: req.id, | ||
| seq: req.seq, | ||
| }; | ||
| let mut resp = Icmpv4Header::new(etherparse::Icmpv4Type::EchoReply(echo)); | ||
| resp.update_checksum(req_payload); | ||
| let mut payload = resp.to_bytes().to_vec(); | ||
|
|
@@ -174,7 +171,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
| continue; | ||
| } | ||
| IpStackStream::UnknownNetwork(pkt) => { | ||
| log::info!("#{number} unknown transport - {} bytes", pkt.len()); | ||
| log::info!("#{number} unknown network - {} bytes", pkt.len()); | ||
| continue; | ||
| } | ||
| }; | ||
|
|
||
This file contains hidden or 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 hidden or 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 @@ | ||
| max_width = 140 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also rename tun2.rs example to tun.rs if you wish
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok