Revert "Box<[u8]> instead of Vec<u8> for ByteBufOwned"

This reverts commit deee41cd93.
This commit is contained in:
Igor Katson 2024-03-29 13:00:57 +00:00
parent e862d34cb4
commit f42de46878
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
23 changed files with 124 additions and 106 deletions

View file

@ -1,7 +1,7 @@
use std::net::SocketAddr;
use bencode::from_bytes;
use buffers::{ByteBuf, ByteBufOwned};
use buffers::{ByteBuf, ByteString};
use librqbit_core::{
constants::CHUNK_SIZE,
hash_id::Id20,
@ -30,9 +30,9 @@ pub(crate) async fn read_metainfo_from_peer(
info_hash: Id20,
peer_connection_options: Option<PeerConnectionOptions>,
spawner: BlockingSpawner,
) -> anyhow::Result<TorrentMetaV1Info<ByteBufOwned>> {
) -> anyhow::Result<TorrentMetaV1Info<ByteString>> {
let (result_tx, result_rx) =
tokio::sync::oneshot::channel::<anyhow::Result<TorrentMetaV1Info<ByteBufOwned>>>();
tokio::sync::oneshot::channel::<anyhow::Result<TorrentMetaV1Info<ByteString>>>();
let (writer_tx, writer_rx) = tokio::sync::mpsc::unbounded_channel::<WriterRequest>();
let handler = Handler {
addr,
@ -131,9 +131,8 @@ struct Handler {
addr: SocketAddr,
info_hash: Id20,
writer_tx: UnboundedSender<WriterRequest>,
result_tx: Mutex<
Option<tokio::sync::oneshot::Sender<anyhow::Result<TorrentMetaV1Info<ByteBufOwned>>>>,
>,
result_tx:
Mutex<Option<tokio::sync::oneshot::Sender<anyhow::Result<TorrentMetaV1Info<ByteString>>>>>,
locked: RwLock<Option<HandlerLocked>>,
}
@ -170,7 +169,7 @@ impl PeerConnectionHandler for Handler {
.record_piece(piece, &data, self.info_hash)?;
if piece_ready {
let buf = self.locked.write().take().unwrap().buffer;
let info = from_bytes::<TorrentMetaV1Info<ByteBufOwned>>(&buf);
let info = from_bytes::<TorrentMetaV1Info<ByteString>>(&buf);
self.result_tx
.lock()
.take()