Strip down message size for MessageBridgeServer
This makes it much much less costly to have a pool of messages we use
for receiving data into on the server side. The server only really
receives the connection message along with any remote timestamps being
sent back.
While we are here, make sure the sha256 is the right length... We were
blindly treating it as a string, and that causes it to overflow the
destination buffer.
Change-Id: Id4bfa0d1d9c25e0beead39248f32b361b722059d
Signed-off-by: Austin Schuh <austin.schuh@bluerivertech.com>
diff --git a/aos/network/message_bridge_protocol.cc b/aos/network/message_bridge_protocol.cc
index a0c68d4..38e16b2 100644
--- a/aos/network/message_bridge_protocol.cc
+++ b/aos/network/message_bridge_protocol.cc
@@ -34,11 +34,16 @@
if (connection->name()->string_view() == node_name &&
channel->source_node()->string_view() == remote_name) {
// Remove the schema to save some space on the wire.
- aos::FlatbufferDetachedBuffer<Channel> cleaned_channel =
- RecursiveCopyFlatBuffer<Channel>(channel);
- cleaned_channel.mutable_message()->clear_schema();
- channel_offsets.emplace_back(
- CopyFlatBuffer<Channel>(&cleaned_channel.message(), &fbb));
+ flatbuffers::Offset<flatbuffers::String> name_offset =
+ fbb.CreateSharedString(channel->name()->string_view());
+ flatbuffers::Offset<flatbuffers::String> type_offset =
+ fbb.CreateSharedString(channel->type()->string_view());
+
+ // We only really care about name, type, and max size.
+ Channel::Builder channel_builder(fbb);
+ channel_builder.add_name(name_offset);
+ channel_builder.add_type(type_offset);
+ channel_offsets.emplace_back(channel_builder.Finish());
}
}
}
diff --git a/aos/network/message_bridge_server_lib.cc b/aos/network/message_bridge_server_lib.cc
index 54a5d53..266c604 100644
--- a/aos/network/message_bridge_server_lib.cc
+++ b/aos/network/message_bridge_server_lib.cc
@@ -13,18 +13,17 @@
#include "aos/network/sctp_server.h"
#include "aos/network/timestamp_channel.h"
#include "glog/logging.h"
+#include "glog/raw_logging.h"
namespace aos {
namespace message_bridge {
namespace chrono = std::chrono;
bool ChannelState::Matches(const Channel *other_channel) {
- // Confirm the normal tuple, plus make sure that the other side isn't going to
- // send more data over than we expect with a mismatching size.
- return (
- channel_->name()->string_view() == other_channel->name()->string_view() &&
- channel_->type()->string_view() == other_channel->type()->string_view() &&
- channel_->max_size() == other_channel->max_size());
+ return channel_->name()->string_view() ==
+ other_channel->name()->string_view() &&
+ channel_->type()->string_view() ==
+ other_channel->type()->string_view();
}
flatbuffers::FlatBufferBuilder ChannelState::PackContext(
@@ -272,9 +271,11 @@
timestamp_state_->SendData(&server_, context);
}),
config_sha256_(std::move(config_sha256)) {
+ CHECK_EQ(config_sha256_.size(), 64u) << ": Wrong length sha256sum";
CHECK(event_loop_->node() != nullptr) << ": No nodes configured.";
- size_t max_size = 0;
+ // Start out with a decent size big enough to hold timestamps.
+ size_t max_size = 204;
// Seed up all the per-node connection state.
// We are making the assumption here that every connection is bidirectional
@@ -327,10 +328,6 @@
any_reliable = true;
}
}
- max_size =
- std::max(static_cast<size_t>(channel->max_size() *
- channel->destination_nodes()->size()),
- max_size);
std::unique_ptr<ChannelState> state(new ChannelState{
channel, channel_index,
any_reliable ? event_loop_->MakeRawFetcher(channel) : nullptr});
@@ -391,7 +388,7 @@
// Buffer up the max size a bit so everything fits nicely.
LOG(INFO) << "Max message size for all clients is " << max_size;
- server_.SetMaxSize(max_size + 100u);
+ server_.SetMaxSize(max_size);
}
void MessageBridgeServer::NodeConnected(sctp_assoc_t assoc_id) {
diff --git a/aos/network/message_bridge_test.cc b/aos/network/message_bridge_test.cc
index 00033f9..02e6a02 100644
--- a/aos/network/message_bridge_test.cc
+++ b/aos/network/message_bridge_test.cc
@@ -1366,7 +1366,8 @@
// We are faking the application names by passing in --application_name=foo
OnPi1();
- MakePi1Server("dummy sha256");
+ MakePi1Server(
+ "dummy sha256 ");
MakePi1Client();
// And build the app for testing.