mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 18:25: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 {
|
pub struct ConnectionMeta {
|
||||||
/// Index of socket worker responsible for this connection. Required for
|
/// Index of socket worker responsible for this connection. Required for
|
||||||
/// sending back response through correct channel to correct worker.
|
/// sending back response through correct channel to correct worker.
|
||||||
pub socket_worker_index: usize,
|
pub worker_index: usize,
|
||||||
/// SocketAddr of peer
|
pub peer_addr: SocketAddr,
|
||||||
pub peer_socket_addr: SocketAddr,
|
pub poll_token: Token,
|
||||||
/// Slab index of PeerConnection
|
|
||||||
pub socket_worker_poll_token: Token,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -115,6 +113,6 @@ impl OutMessageSender {
|
||||||
meta: ConnectionMeta,
|
meta: ConnectionMeta,
|
||||||
message: OutMessage
|
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
|
// Since peers have access to each others peer_id's, they could send
|
||||||
// requests using them, causing all sorts of issues.
|
// requests using them, causing all sorts of issues.
|
||||||
if let Some(previous_peer) = torrent_data.peers.get(&peer_id){
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ pub enum ConnectionStage {
|
||||||
|
|
||||||
pub struct PeerConnection {
|
pub struct PeerConnection {
|
||||||
pub ws: WebSocket<TcpStream>,
|
pub ws: WebSocket<TcpStream>,
|
||||||
pub peer_socket_addr: SocketAddr,
|
pub peer_addr: SocketAddr,
|
||||||
pub valid_until: ValidUntil,
|
pub valid_until: ValidUntil,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -248,11 +248,11 @@ pub fn handle_handshake_result(
|
||||||
Ok(mut ws) => {
|
Ok(mut ws) => {
|
||||||
println!("handshake established");
|
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 {
|
let peer_connection = PeerConnection {
|
||||||
ws,
|
ws,
|
||||||
peer_socket_addr,
|
peer_addr,
|
||||||
valid_until,
|
valid_until,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -353,9 +353,9 @@ pub fn run_handshake_and_read_messages(
|
||||||
dbg!(in_message.clone());
|
dbg!(in_message.clone());
|
||||||
|
|
||||||
let meta = ConnectionMeta {
|
let meta = ConnectionMeta {
|
||||||
socket_worker_index,
|
worker_index: socket_worker_index,
|
||||||
socket_worker_poll_token: poll_token,
|
poll_token,
|
||||||
peer_socket_addr: peer_connection.peer_socket_addr
|
peer_addr: peer_connection.peer_addr
|
||||||
};
|
};
|
||||||
|
|
||||||
in_message_sender.send((meta, in_message));
|
in_message_sender.send((meta, in_message));
|
||||||
|
|
@ -400,11 +400,11 @@ pub fn send_out_messages(
|
||||||
// Read messages from channel, send to peers
|
// Read messages from channel, send to peers
|
||||||
for (meta, out_message) in out_message_receiver {
|
for (meta, out_message) in out_message_receiver {
|
||||||
let opt_connection = connections
|
let opt_connection = connections
|
||||||
.get_mut(&meta.socket_worker_poll_token)
|
.get_mut(&meta.poll_token)
|
||||||
.map(|v| &mut v.stage);
|
.map(|v| &mut v.stage);
|
||||||
|
|
||||||
if let Some(ConnectionStage::Established(connection)) = opt_connection {
|
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");
|
eprintln!("socket worker: peer socket addrs didn't match");
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -424,14 +424,14 @@ pub fn send_out_messages(
|
||||||
remove_connection_if_exists(
|
remove_connection_if_exists(
|
||||||
poll,
|
poll,
|
||||||
connections,
|
connections,
|
||||||
meta.socket_worker_poll_token
|
meta.poll_token
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
Err(tungstenite::Error::ConnectionClosed) => {
|
Err(tungstenite::Error::ConnectionClosed) => {
|
||||||
remove_connection_if_exists(
|
remove_connection_if_exists(
|
||||||
poll,
|
poll,
|
||||||
connections,
|
connections,
|
||||||
meta.socket_worker_poll_token
|
meta.poll_token
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ pub struct AnnounceRequest {
|
||||||
pub peer_id: PeerId,
|
pub peer_id: PeerId,
|
||||||
/// Just called "left" in protocol
|
/// Just called "left" in protocol
|
||||||
#[serde(rename = "left")]
|
#[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"
|
/// Can be empty. Then, default is "update"
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub event: AnnounceEvent,
|
pub event: AnnounceEvent,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue