-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Sync GRPC Session transports, add standalone C++ noise test
Change-Id: I6609c767827f88a89339bb0d3234c2622bec564b
- Loading branch information
Showing
9 changed files
with
301 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2024 The Project Oak Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "cc/transport/grpc_sync_session_client_transport.h" | ||
|
||
#include "absl/status/status.h" | ||
#include "absl/status/statusor.h" | ||
#include "cc/oak_session/client_session.h" | ||
#include "grpcpp/support/sync_stream.h" | ||
#include "proto/session/session.pb.h" | ||
|
||
namespace oak::transport { | ||
|
||
absl::Status GrpcSyncSessionClientTransport::Send( | ||
session::v1::SessionRequest&& message) { | ||
if (!stream_->Write(message)) { | ||
return absl::AbortedError("Failed to write outgoing message."); | ||
} | ||
return absl::OkStatus(); | ||
} | ||
|
||
absl::StatusOr<session::v1::SessionResponse> | ||
GrpcSyncSessionClientTransport::Receive() { | ||
session::v1::SessionResponse response; | ||
if (!stream_->Read(&response)) { | ||
return absl::AbortedError("Failed to readin incoming message."); | ||
} | ||
return response; | ||
} | ||
|
||
}; // namespace oak::transport |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2024 The Project Oak Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef CC_TRANSPORT_GRPC_SYNC_CLIENT_SESSION_TRANSPORT_H_ | ||
#define CC_TRANSPORT_GRPC_SYNC_CLIENT_SESSION_TRANSPORT_H_ | ||
|
||
#include "absl/status/status.h" | ||
#include "absl/status/statusor.h" | ||
#include "cc/client/session_client.h" | ||
#include "cc/oak_session/channel/oak_session_channel.h" | ||
#include "cc/oak_session/client_session.h" | ||
#include "grpcpp/support/sync_stream.h" | ||
#include "proto/session/session.pb.h" | ||
|
||
namespace oak::transport { | ||
|
||
// An implementation of `OakSessionChannel::Transport` for use with | ||
// `OakSessionClient` using the gRPC synchronous streaming interface. | ||
class GrpcSyncSessionClientTransport | ||
: public ::oak::client::OakSessionClient::Channel::Transport { | ||
public: | ||
explicit GrpcSyncSessionClientTransport( | ||
std::unique_ptr<grpc::ClientReaderWriterInterface< | ||
session::v1::SessionRequest, session::v1::SessionResponse>> | ||
stream) | ||
: stream_(std::move(stream)) {} | ||
|
||
absl::Status Send(session::v1::SessionRequest&& message) override; | ||
absl::StatusOr<session::v1::SessionResponse> Receive() override; | ||
|
||
private: | ||
std::unique_ptr<grpc::ClientReaderWriterInterface< | ||
session::v1::SessionRequest, session::v1::SessionResponse>> | ||
stream_; | ||
}; | ||
|
||
} // namespace oak::transport | ||
|
||
#endif // CC_TRANSPORT_GRPC_SYNC_CLIENT_SESSION_TRANSPORT_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2024 The Project Oak Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "cc/transport/grpc_sync_session_server_transport.h" | ||
|
||
#include "absl/status/status.h" | ||
#include "absl/status/statusor.h" | ||
#include "cc/oak_session/server_session.h" | ||
#include "proto/session/session.pb.h" | ||
|
||
namespace oak::transport { | ||
|
||
absl::Status GrpcSyncSessionServerTransport::Send( | ||
session::v1::SessionResponse&& message) { | ||
if (!stream_->Write(message)) { | ||
return absl::AbortedError("Failed to write outgoing message."); | ||
} | ||
return absl::OkStatus(); | ||
} | ||
|
||
absl::StatusOr<session::v1::SessionRequest> | ||
GrpcSyncSessionServerTransport::Receive() { | ||
session::v1::SessionRequest request; | ||
if (!stream_->Read(&request)) { | ||
return absl::AbortedError("Failed to read incoming message."); | ||
} | ||
return request; | ||
} | ||
|
||
} // namespace oak::transport |
Oops, something went wrong.