-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(http): [#184] extract announce service in Axum tracker
- Loading branch information
1 parent
02e2516
commit 99dbbe4
Showing
6 changed files
with
36 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ pub mod resources; | |
pub mod responses; | ||
pub mod routes; | ||
pub mod server; | ||
pub mod services; |
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,24 @@ | ||
use std::net::IpAddr; | ||
use std::sync::Arc; | ||
|
||
use crate::protocol::info_hash::InfoHash; | ||
use crate::tracker::peer::Peer; | ||
use crate::tracker::{statistics, AnnounceResponse, Tracker}; | ||
|
||
pub async fn invoke(tracker: Arc<Tracker>, info_hash: InfoHash, peer: &mut Peer) -> AnnounceResponse { | ||
let original_peer_ip = peer.peer_addr.ip(); | ||
|
||
// The tracker could change the original peer ip | ||
let response = tracker.announce(&info_hash, peer, &original_peer_ip).await; | ||
|
||
match original_peer_ip { | ||
IpAddr::V4(_) => { | ||
tracker.send_stats_event(statistics::Event::Tcp4Announce).await; | ||
} | ||
IpAddr::V6(_) => { | ||
tracker.send_stats_event(statistics::Event::Tcp6Announce).await; | ||
} | ||
} | ||
|
||
response | ||
} |
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 @@ | ||
pub mod announce; |
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