aquatic_ws: announce handler fixes, related changes elsewhere

This commit is contained in:
Joakim Frostegård 2020-05-08 01:57:12 +02:00
parent 7ebbb311e1
commit a39c7a5950
3 changed files with 55 additions and 8 deletions

View file

@ -86,9 +86,42 @@ pub fn handle_announce_requests(
messages_out: &mut Vec<(ConnectionMeta, OutMessage)>,
requests: Drain<(ConnectionMeta, AnnounceRequest)>,
){
// if offers are set, fetch same number of peers, send offers to all of them
// if answer is set, fetch that peer, send answer to it
// finally, return announce response, I think
for (sender_meta, request) in requests {
let torrent_data = torrents.entry(request.info_hash)
.or_default();
if let Some(offers) = request.offers {
// if offers are set, fetch same number of peers, send offers to all of them
}
match (request.answer, request.to_peer_id, request.offer_id){
(Some(answer), Some(to_peer_id), Some(offer_id)) => {
if let Some(to_peer) = torrent_data.peers.get(&to_peer_id){
let middleman_answer = MiddlemanAnswerToPeer {
peer_id: request.peer_id,
info_hash: request.info_hash,
answer,
offer_id,
};
messages_out.push((
to_peer.connection_meta,
OutMessage::Answer(middleman_answer)
));
}
},
_ => (),
}
let response = OutMessage::AnnounceResponse(AnnounceResponse {
info_hash: request.info_hash,
complete: torrent_data.seeders,
incomplete: torrent_data.leechers,
announce_interval: 120,
});
messages_out.push((sender_meta, response));
}
}