Skip to content

Commit

Permalink
feat: remove request stream in SyncPieces (#214)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Nov 16, 2023
1 parent ac4597d commit 8fdd8c8
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 94 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dragonfly-api"
version = "2.0.51"
version = "2.0.52"
authors = ["Gaius <[email protected]>"]
edition = "2021"
license = "Apache-2.0"
Expand Down
50 changes: 25 additions & 25 deletions pkg/apis/dfdaemon/v2/dfdaemon.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/apis/dfdaemon/v2/dfdaemon.proto
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ service Dfdaemon {
rpc GetPieceNumbers(GetPieceNumbersRequest) returns(GetPieceNumbersResponse);

// SyncPieces syncs pieces from the other peer.
rpc SyncPieces(stream SyncPiecesRequest)returns(stream SyncPiecesResponse);
rpc SyncPieces(SyncPiecesRequest)returns(stream SyncPiecesResponse);

// DownloadTask downloads task back-to-source.
rpc DownloadTask(DownloadTaskRequest) returns(stream DownloadTaskResponse);
Expand Down
35 changes: 15 additions & 20 deletions pkg/apis/dfdaemon/v2/dfdaemon_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 8 additions & 37 deletions pkg/apis/dfdaemon/v2/mocks/dfdaemon_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/dfdaemon.proto
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ service Dfdaemon{
rpc GetPieceNumbers(GetPieceNumbersRequest) returns(GetPieceNumbersResponse);

// SyncPieces syncs pieces from the other peer.
rpc SyncPieces(stream SyncPiecesRequest)returns(stream SyncPiecesResponse);
rpc SyncPieces(SyncPiecesRequest)returns(stream SyncPiecesResponse);

// DownloadTask downloads task back-to-source.
rpc DownloadTask(DownloadTaskRequest) returns(stream DownloadTaskResponse);
Expand Down
Binary file modified src/descriptor.bin
Binary file not shown.
16 changes: 7 additions & 9 deletions src/dfdaemon.v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ pub mod dfdaemon_client {
/// SyncPieces syncs pieces from the other peer.
pub async fn sync_pieces(
&mut self,
request: impl tonic::IntoStreamingRequest<Message = super::SyncPiecesRequest>,
request: impl tonic::IntoRequest<super::SyncPiecesRequest>,
) -> std::result::Result<
tonic::Response<tonic::codec::Streaming<super::SyncPiecesResponse>>,
tonic::Status,
Expand All @@ -251,10 +251,10 @@ pub mod dfdaemon_client {
let path = http::uri::PathAndQuery::from_static(
"/dfdaemon.v2.Dfdaemon/SyncPieces",
);
let mut req = request.into_streaming_request();
let mut req = request.into_request();
req.extensions_mut()
.insert(GrpcMethod::new("dfdaemon.v2.Dfdaemon", "SyncPieces"));
self.inner.streaming(req, path, codec).await
self.inner.server_streaming(req, path, codec).await
}
/// DownloadTask downloads task back-to-source.
pub async fn download_task(
Expand Down Expand Up @@ -380,7 +380,7 @@ pub mod dfdaemon_server {
/// SyncPieces syncs pieces from the other peer.
async fn sync_pieces(
&self,
request: tonic::Request<tonic::Streaming<super::SyncPiecesRequest>>,
request: tonic::Request<super::SyncPiecesRequest>,
) -> std::result::Result<tonic::Response<Self::SyncPiecesStream>, tonic::Status>;
/// Server streaming response type for the DownloadTask method.
type DownloadTaskStream: futures_core::Stream<
Expand Down Expand Up @@ -546,7 +546,7 @@ pub mod dfdaemon_server {
struct SyncPiecesSvc<T: Dfdaemon>(pub Arc<T>);
impl<
T: Dfdaemon,
> tonic::server::StreamingService<super::SyncPiecesRequest>
> tonic::server::ServerStreamingService<super::SyncPiecesRequest>
for SyncPiecesSvc<T> {
type Response = super::SyncPiecesResponse;
type ResponseStream = T::SyncPiecesStream;
Expand All @@ -556,9 +556,7 @@ pub mod dfdaemon_server {
>;
fn call(
&mut self,
request: tonic::Request<
tonic::Streaming<super::SyncPiecesRequest>,
>,
request: tonic::Request<super::SyncPiecesRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move { (*inner).sync_pieces(request).await };
Expand All @@ -583,7 +581,7 @@ pub mod dfdaemon_server {
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.streaming(method, req).await;
let res = grpc.server_streaming(method, req).await;
Ok(res)
};
Box::pin(fut)
Expand Down

0 comments on commit 8fdd8c8

Please sign in to comment.