mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 02:05:30 +00:00
aquatic_ws: shorten field names in ConnectionMeta, PeerConnection
This commit is contained in:
parent
da2d5986b9
commit
b76f8cdebc
4 changed files with 16 additions and 18 deletions
|
|
@ -16,11 +16,9 @@ use crate::protocol::*;
|
|||
pub struct ConnectionMeta {
|
||||
/// Index of socket worker responsible for this connection. Required for
|
||||
/// sending back response through correct channel to correct worker.
|
||||
pub socket_worker_index: usize,
|
||||
/// SocketAddr of peer
|
||||
pub peer_socket_addr: SocketAddr,
|
||||
/// Slab index of PeerConnection
|
||||
pub socket_worker_poll_token: Token,
|
||||
pub worker_index: usize,
|
||||
pub peer_addr: SocketAddr,
|
||||
pub poll_token: Token,
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -115,6 +113,6 @@ impl OutMessageSender {
|
|||
meta: ConnectionMeta,
|
||||
message: OutMessage
|
||||
){
|
||||
self.0[meta.socket_worker_index].send((meta, message));
|
||||
self.0[meta.worker_index].send((meta, message));
|
||||
}
|
||||
}
|
||||
|
|
@ -97,7 +97,7 @@ pub fn handle_announce_requests(
|
|||
// Since peers have access to each others peer_id's, they could send
|
||||
// requests using them, causing all sorts of issues.
|
||||
if let Some(previous_peer) = torrent_data.peers.get(&peer_id){
|
||||
if sender_meta.peer_socket_addr != previous_peer.connection_meta.peer_socket_addr {
|
||||
if sender_meta.peer_addr != previous_peer.connection_meta.peer_addr {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ pub enum ConnectionStage {
|
|||
|
||||
pub struct PeerConnection {
|
||||
pub ws: WebSocket<TcpStream>,
|
||||
pub peer_socket_addr: SocketAddr,
|
||||
pub peer_addr: SocketAddr,
|
||||
pub valid_until: ValidUntil,
|
||||
}
|
||||
|
||||
|
|
@ -248,11 +248,11 @@ pub fn handle_handshake_result(
|
|||
Ok(mut ws) => {
|
||||
println!("handshake established");
|
||||
|
||||
let peer_socket_addr = ws.get_mut().peer_addr().unwrap();
|
||||
let peer_addr = ws.get_mut().peer_addr().unwrap();
|
||||
|
||||
let peer_connection = PeerConnection {
|
||||
ws,
|
||||
peer_socket_addr,
|
||||
peer_addr,
|
||||
valid_until,
|
||||
};
|
||||
|
||||
|
|
@ -353,9 +353,9 @@ pub fn run_handshake_and_read_messages(
|
|||
dbg!(in_message.clone());
|
||||
|
||||
let meta = ConnectionMeta {
|
||||
socket_worker_index,
|
||||
socket_worker_poll_token: poll_token,
|
||||
peer_socket_addr: peer_connection.peer_socket_addr
|
||||
worker_index: socket_worker_index,
|
||||
poll_token,
|
||||
peer_addr: peer_connection.peer_addr
|
||||
};
|
||||
|
||||
in_message_sender.send((meta, in_message));
|
||||
|
|
@ -400,11 +400,11 @@ pub fn send_out_messages(
|
|||
// Read messages from channel, send to peers
|
||||
for (meta, out_message) in out_message_receiver {
|
||||
let opt_connection = connections
|
||||
.get_mut(&meta.socket_worker_poll_token)
|
||||
.get_mut(&meta.poll_token)
|
||||
.map(|v| &mut v.stage);
|
||||
|
||||
if let Some(ConnectionStage::Established(connection)) = opt_connection {
|
||||
if connection.peer_socket_addr != meta.peer_socket_addr {
|
||||
if connection.peer_addr != meta.peer_addr {
|
||||
eprintln!("socket worker: peer socket addrs didn't match");
|
||||
|
||||
continue;
|
||||
|
|
@ -424,14 +424,14 @@ pub fn send_out_messages(
|
|||
remove_connection_if_exists(
|
||||
poll,
|
||||
connections,
|
||||
meta.socket_worker_poll_token
|
||||
meta.poll_token
|
||||
);
|
||||
},
|
||||
Err(tungstenite::Error::ConnectionClosed) => {
|
||||
remove_connection_if_exists(
|
||||
poll,
|
||||
connections,
|
||||
meta.socket_worker_poll_token
|
||||
meta.poll_token
|
||||
);
|
||||
},
|
||||
Err(err) => {
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ pub struct AnnounceRequest {
|
|||
pub peer_id: PeerId,
|
||||
/// Just called "left" in protocol
|
||||
#[serde(rename = "left")]
|
||||
pub bytes_left: Option<usize>, // FIXME: I had this set as bool before, check!
|
||||
pub bytes_left: Option<usize>,
|
||||
/// Can be empty. Then, default is "update"
|
||||
#[serde(default)]
|
||||
pub event: AnnounceEvent,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue