fgerlits commented on code in PR #1669:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1669#discussion_r1363992709
##########
libminifi/src/c2/ControllerSocketProtocol.cpp:
##########
@@ -371,6 +372,47 @@ void
ControllerSocketProtocol::handleDescribe(io::BaseStream &stream) {
}
}
+void ControllerSocketProtocol::writeDebugBundleResponse(io::BaseStream
&stream) {
+ auto files = update_sink_.getDebugInfo();
+ auto bundle = createDebugBundleArchive(files);
+ io::BufferStream resp;
+ auto op = static_cast<uint8_t>(Operation::transfer);
+ resp.write(&op, 1);
+ if (!bundle) {
+ logger_->log_error(bundle.error().c_str());
+ resp.write(static_cast<size_t>(0));
+ stream.write(resp.getBuffer());
+ return;
+ }
+
+ size_t bundle_size = bundle.value()->size();
+ resp.write(bundle_size);
+ const size_t BUFFER_SIZE = 4096;
+ std::array<std::byte, BUFFER_SIZE> out_buffer{};
+ while (bundle_size > 0) {
+ const auto next_write_size = (std::min)(bundle_size, BUFFER_SIZE);
+ const auto size_read =
bundle.value()->read(std::as_writable_bytes(std::span(out_buffer).subspan(0,
next_write_size)));
+ resp.write(reinterpret_cast<const uint8_t*>(out_buffer.data()), size_read);
+ bundle_size -= size_read;
+ }
+
+ stream.write(resp.getBuffer());
+}
+
+void ControllerSocketProtocol::handleTransfer(io::BaseStream &stream) {
+ std::string what;
+ const auto size = stream.read(what);
+ if (io::isError(size)) {
+ logger_->log_debug("Connection broke");
Review Comment:
this looks like an an error -- should we log it on error level?
##########
libminifi/src/c2/ControllerSocketProtocol.cpp:
##########
@@ -371,6 +372,47 @@ void
ControllerSocketProtocol::handleDescribe(io::BaseStream &stream) {
}
}
+void ControllerSocketProtocol::writeDebugBundleResponse(io::BaseStream
&stream) {
+ auto files = update_sink_.getDebugInfo();
+ auto bundle = createDebugBundleArchive(files);
+ io::BufferStream resp;
+ auto op = static_cast<uint8_t>(Operation::transfer);
+ resp.write(&op, 1);
+ if (!bundle) {
+ logger_->log_error(bundle.error().c_str());
+ resp.write(static_cast<size_t>(0));
+ stream.write(resp.getBuffer());
+ return;
+ }
+
+ size_t bundle_size = bundle.value()->size();
+ resp.write(bundle_size);
+ const size_t BUFFER_SIZE = 4096;
+ std::array<std::byte, BUFFER_SIZE> out_buffer{};
+ while (bundle_size > 0) {
+ const auto next_write_size = (std::min)(bundle_size, BUFFER_SIZE);
+ const auto size_read =
bundle.value()->read(std::as_writable_bytes(std::span(out_buffer).subspan(0,
next_write_size)));
+ resp.write(reinterpret_cast<const uint8_t*>(out_buffer.data()), size_read);
+ bundle_size -= size_read;
+ }
+
+ stream.write(resp.getBuffer());
+}
+
+void ControllerSocketProtocol::handleTransfer(io::BaseStream &stream) {
+ std::string what;
+ const auto size = stream.read(what);
+ if (io::isError(size)) {
+ logger_->log_debug("Connection broke");
+ return;
+ }
+ if (what == "debug") {
+ writeDebugBundleResponse(stream);
+ } else {
+ logger_->log_error("Unknown C2 transfer parameter: %s", what);
Review Comment:
the `%s`s need to be changed to `{}`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]