-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
7 changed files
with
336 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: Count Lines of Code | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
cloc: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Count Lines of Code (cloc) | ||
uses: djdefi/cloc-action@6 |
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,49 @@ | ||
use std::net::TcpStream; | ||
use std::sync::{Arc, Mutex}; | ||
use std::time::Duration; | ||
use crate::file::TorrentFile; | ||
use crate::peer::connection::PeerConnection; | ||
use crate::peer::{Peer, PeerId}; | ||
|
||
pub struct PeerWorker { | ||
peers: Arc<Mutex<Vec<Peer>>>, | ||
meta: Arc<TorrentFile>, | ||
client_id: Arc<PeerId> | ||
} | ||
|
||
impl PeerWorker { | ||
pub fn go(&mut self) { | ||
loop { | ||
let mut q = self.peers.lock().unwrap(); | ||
if q.len() == 0 { | ||
return; | ||
} | ||
let peer = q.pop().unwrap(); | ||
drop(q); | ||
let connection = TcpStream::connect_timeout(&peer.addr, Duration::from_secs(5)); | ||
if connection.is_err() { | ||
continue; | ||
} | ||
let connection = | ||
PeerConnection::handshake(connection.unwrap(), &self.meta.info.info_hash, &self.client_id); | ||
if connection.is_err() { | ||
continue; | ||
} | ||
let mut connection = connection.unwrap(); | ||
loop { | ||
match connection.recv() { | ||
Ok(message) => { | ||
println!("message {message}") | ||
} | ||
Err(err) => { | ||
println!("error {err:?}") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub fn new(peers: Arc<Mutex<Vec<Peer>>>, meta: Arc<TorrentFile>, client_id: Arc<PeerId>) -> Self { | ||
Self { peers, meta, client_id } | ||
} | ||
} |
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
Oops, something went wrong.