Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 1 | #include "aos/events/simulated_network_bridge.h" |
| 2 | |
Austin Schuh | 0de30f3 | 2020-12-06 12:44:28 -0800 | [diff] [blame] | 3 | #include "absl/strings/str_cat.h" |
| 4 | #include "aos/configuration.h" |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 5 | #include "aos/events/event_loop.h" |
| 6 | #include "aos/events/simulated_event_loop.h" |
Austin Schuh | 0de30f3 | 2020-12-06 12:44:28 -0800 | [diff] [blame] | 7 | #include "aos/network/remote_message_generated.h" |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 8 | |
| 9 | namespace aos { |
| 10 | namespace message_bridge { |
| 11 | |
| 12 | // This class delays messages forwarded between two factories. |
| 13 | // |
| 14 | // The basic design is that we need to use the distributed_clock to convert |
| 15 | // monotonic times from the source to the destination node. We also use a |
| 16 | // fetcher to manage the queue of data, and a timer to schedule the sends. |
| 17 | class RawMessageDelayer { |
| 18 | public: |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 19 | RawMessageDelayer(const Channel *channel, const Connection *connection, |
| 20 | aos::NodeEventLoopFactory *fetch_node_factory, |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 21 | aos::NodeEventLoopFactory *send_node_factory, |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 22 | size_t destination_node_index, bool delivery_time_is_logged) |
| 23 | : channel_(channel), |
| 24 | connection_(connection), |
| 25 | fetch_node_factory_(fetch_node_factory), |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 26 | send_node_factory_(send_node_factory), |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 27 | destination_node_index_(destination_node_index), |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 28 | channel_index_(configuration::ChannelIndex( |
| 29 | fetch_node_factory_->configuration(), channel_)), |
| 30 | delivery_time_is_logged_(delivery_time_is_logged) {} |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 31 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 32 | bool forwarding_disabled() const { return forwarding_disabled_; } |
| 33 | void set_forwarding_disabled(bool forwarding_disabled) { |
| 34 | forwarding_disabled_ = forwarding_disabled; |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 35 | } |
| 36 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 37 | void SetFetchEventLoop(aos::EventLoop *fetch_event_loop, |
| 38 | MessageBridgeServerStatus *server_status, |
| 39 | ChannelTimestampSender *timestamp_loggers) { |
| 40 | sent_ = false; |
| 41 | fetch_event_loop_ = fetch_event_loop; |
| 42 | if (fetch_event_loop_) { |
| 43 | fetcher_ = fetch_event_loop_->MakeRawFetcher(channel_); |
| 44 | } else { |
| 45 | fetcher_ = nullptr; |
| 46 | } |
| 47 | |
| 48 | server_status_ = server_status; |
| 49 | if (server_status) { |
| 50 | server_connection_ = |
| 51 | server_status_->FindServerConnection(send_node_factory_->node()); |
| 52 | } |
| 53 | if (delivery_time_is_logged_ && timestamp_loggers != nullptr) { |
| 54 | timestamp_logger_ = |
| 55 | timestamp_loggers->SenderForChannel(channel_, connection_); |
| 56 | } else { |
| 57 | timestamp_logger_ = nullptr; |
| 58 | } |
| 59 | |
| 60 | if (fetch_event_loop_) { |
| 61 | timestamp_timer_ = |
| 62 | fetch_event_loop_->AddTimer([this]() { SendTimestamp(); }); |
| 63 | if (send_event_loop_) { |
milind | 1f1dca3 | 2021-07-03 13:50:07 -0700 | [diff] [blame] | 64 | std::string timer_name = |
| 65 | absl::StrCat(send_event_loop_->node()->name()->string_view(), " ", |
| 66 | fetcher_->channel()->name()->string_view(), " ", |
| 67 | fetcher_->channel()->type()->string_view()); |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 68 | if (timer_) { |
| 69 | timer_->set_name(timer_name); |
| 70 | } |
| 71 | timestamp_timer_->set_name(absl::StrCat(timer_name, " timestamps")); |
| 72 | } |
| 73 | } else { |
| 74 | timestamp_timer_ = nullptr; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | void SetSendEventLoop(aos::EventLoop *send_event_loop, |
| 79 | MessageBridgeClientStatus *client_status) { |
| 80 | sent_ = false; |
| 81 | send_event_loop_ = send_event_loop; |
| 82 | if (send_event_loop_) { |
| 83 | sender_ = send_event_loop_->MakeRawSender(channel_); |
| 84 | } else { |
| 85 | sender_ = nullptr; |
| 86 | } |
| 87 | |
| 88 | client_status_ = client_status; |
| 89 | if (client_status_) { |
| 90 | client_index_ = client_status_->FindClientIndex( |
| 91 | channel_->source_node()->string_view()); |
| 92 | client_connection_ = client_status_->GetClientConnection(client_index_); |
| 93 | } else { |
| 94 | client_index_ = -1; |
| 95 | client_connection_ = nullptr; |
| 96 | } |
| 97 | |
| 98 | if (send_event_loop_) { |
| 99 | timer_ = send_event_loop_->AddTimer([this]() { Send(); }); |
| 100 | if (fetcher_) { |
| 101 | std::string timer_name = |
| 102 | absl::StrCat(send_event_loop_->node()->name()->string_view(), " ", |
| 103 | fetcher_->channel()->name()->string_view(), " ", |
| 104 | fetcher_->channel()->type()->string_view()); |
| 105 | timer_->set_name(timer_name); |
| 106 | if (timestamp_timer_) { |
| 107 | timestamp_timer_->set_name(absl::StrCat(timer_name, " timestamps")); |
| 108 | } |
| 109 | } |
| 110 | } else { |
| 111 | timer_ = nullptr; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | const Channel *channel() const { return channel_; } |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 116 | |
Austin Schuh | 4c570ea | 2020-11-19 23:13:24 -0800 | [diff] [blame] | 117 | uint32_t time_to_live() { |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 118 | return configuration::ConnectionToNode(channel_, send_node_factory_->node()) |
Austin Schuh | 4c570ea | 2020-11-19 23:13:24 -0800 | [diff] [blame] | 119 | ->time_to_live(); |
| 120 | } |
| 121 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 122 | void ScheduleReliable() { |
| 123 | if (forwarding_disabled()) return; |
| 124 | |
| 125 | if (!fetcher_) { |
| 126 | return; |
| 127 | } |
| 128 | if (fetcher_->context().data == nullptr || sent_) { |
| 129 | sent_ = !fetcher_->Fetch(); |
| 130 | } |
| 131 | |
| 132 | FetchNext(); |
| 133 | if (fetcher_->context().data == nullptr || sent_) { |
| 134 | return; |
| 135 | } |
| 136 | CHECK(!timer_scheduled_); |
| 137 | |
| 138 | // Send at startup. It is the best we can do. |
| 139 | const monotonic_clock::time_point monotonic_delivered_time = |
| 140 | send_node_factory_->monotonic_now() + |
| 141 | send_node_factory_->network_delay(); |
| 142 | |
| 143 | CHECK_GE(monotonic_delivered_time, send_node_factory_->monotonic_now()) |
| 144 | << ": Trying to deliver message in the past on channel " |
| 145 | << configuration::StrippedChannelToString(fetcher_->channel()) |
| 146 | << " to node " << send_event_loop_->node()->name()->string_view() |
| 147 | << " sent from " << fetcher_->channel()->source_node()->string_view() |
| 148 | << " at " << fetch_node_factory_->monotonic_now(); |
| 149 | |
| 150 | if (timer_) { |
| 151 | server_connection_->mutate_sent_packets( |
| 152 | server_connection_->sent_packets() + 1); |
| 153 | timer_->Setup(monotonic_delivered_time); |
| 154 | timer_scheduled_ = true; |
| 155 | } else { |
| 156 | server_connection_->mutate_dropped_packets( |
| 157 | server_connection_->dropped_packets() + 1); |
| 158 | sent_ = true; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | bool timer_scheduled_ = false; |
| 163 | |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 164 | // Kicks us to re-fetch and schedule the timer. |
| 165 | void Schedule() { |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 166 | CHECK(!forwarding_disabled()); |
| 167 | if (!fetcher_) { |
| 168 | return; |
| 169 | } |
| 170 | if (timer_scheduled_) { |
| 171 | return; |
| 172 | } |
| 173 | FetchNext(); |
| 174 | if (fetcher_->context().data == nullptr || sent_) { |
| 175 | return; |
| 176 | } |
| 177 | |
| 178 | // Compute the time to publish this message. |
| 179 | const monotonic_clock::time_point monotonic_delivered_time = |
| 180 | DeliveredTime(fetcher_->context()); |
| 181 | |
| 182 | CHECK_GE(monotonic_delivered_time, send_node_factory_->monotonic_now()) |
| 183 | << ": Trying to deliver message in the past on channel " |
| 184 | << configuration::StrippedChannelToString(fetcher_->channel()) |
| 185 | << " to node " << send_event_loop_->node()->name()->string_view() |
| 186 | << " sent from " << fetcher_->channel()->source_node()->string_view() |
| 187 | << " at " << fetch_node_factory_->monotonic_now(); |
| 188 | |
| 189 | if (timer_) { |
| 190 | server_connection_->mutate_sent_packets( |
| 191 | server_connection_->sent_packets() + 1); |
| 192 | timer_->Setup(monotonic_delivered_time); |
| 193 | timer_scheduled_ = true; |
| 194 | } else { |
| 195 | server_connection_->mutate_dropped_packets( |
| 196 | server_connection_->dropped_packets() + 1); |
| 197 | sent_ = true; |
| 198 | Schedule(); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | private: |
| 203 | void FetchNext() { |
| 204 | CHECK(server_connection_); |
Austin Schuh | 6aa77be | 2020-02-22 21:06:40 -0800 | [diff] [blame] | 205 | // Keep pulling messages out of the fetcher until we find one in the future. |
| 206 | while (true) { |
| 207 | if (fetcher_->context().data == nullptr || sent_) { |
| 208 | sent_ = !fetcher_->FetchNext(); |
| 209 | } |
| 210 | if (sent_) { |
| 211 | break; |
| 212 | } |
Austin Schuh | c0b0f72 | 2020-12-12 18:36:06 -0800 | [diff] [blame] | 213 | |
| 214 | if (server_connection_->state() != State::CONNECTED) { |
| 215 | sent_ = true; |
| 216 | server_connection_->mutate_dropped_packets( |
| 217 | server_connection_->dropped_packets() + 1); |
| 218 | continue; |
| 219 | } |
| 220 | |
Austin Schuh | 6aa77be | 2020-02-22 21:06:40 -0800 | [diff] [blame] | 221 | if (fetcher_->context().monotonic_event_time + |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 222 | send_node_factory_->network_delay() + |
| 223 | send_node_factory_->send_delay() > |
| 224 | fetch_node_factory_->monotonic_now() || |
| 225 | time_to_live() == 0) { |
Austin Schuh | 6aa77be | 2020-02-22 21:06:40 -0800 | [diff] [blame] | 226 | break; |
| 227 | } |
| 228 | |
| 229 | // TODO(austin): Not cool. We want to actually forward these. This means |
| 230 | // we need a more sophisticated concept of what is running. |
James Kuszmaul | 29c5952 | 2022-02-12 16:44:26 -0800 | [diff] [blame] | 231 | // TODO(james): This fails if multiple messages are sent on the same channel |
| 232 | // within the same callback. |
Austin Schuh | 6aa77be | 2020-02-22 21:06:40 -0800 | [diff] [blame] | 233 | LOG(WARNING) << "Not forwarding message on " |
| 234 | << configuration::CleanedChannelToString(fetcher_->channel()) |
| 235 | << " because we aren't running. Set at " |
| 236 | << fetcher_->context().monotonic_event_time << " now is " |
| 237 | << fetch_node_factory_->monotonic_now(); |
| 238 | sent_ = true; |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 239 | server_connection_->mutate_dropped_packets( |
| 240 | server_connection_->dropped_packets() + 1); |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 241 | } |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 242 | } |
| 243 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 244 | // Actually sends the message, and reschedules. |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 245 | void Send() { |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 246 | timer_scheduled_ = false; |
| 247 | CHECK(sender_); |
| 248 | CHECK(client_status_); |
Austin Schuh | c0b0f72 | 2020-12-12 18:36:06 -0800 | [diff] [blame] | 249 | if (server_connection_->state() != State::CONNECTED) { |
| 250 | sent_ = true; |
| 251 | Schedule(); |
| 252 | return; |
| 253 | } |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 254 | // Fill out the send times. |
milind | 1f1dca3 | 2021-07-03 13:50:07 -0700 | [diff] [blame] | 255 | sender_->CheckOk(sender_->Send( |
| 256 | fetcher_->context().data, fetcher_->context().size, |
| 257 | fetcher_->context().monotonic_event_time, |
| 258 | fetcher_->context().realtime_event_time, |
| 259 | fetcher_->context().queue_index, fetcher_->context().source_boot_uuid)); |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 260 | |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 261 | // And simulate message_bridge's offset recovery. |
Austin Schuh | 367a7f4 | 2021-11-23 23:04:36 -0800 | [diff] [blame] | 262 | client_status_->SampleFilter( |
| 263 | client_index_, fetcher_->context().monotonic_event_time, |
| 264 | sender_->monotonic_sent_time(), fetcher_->context().source_boot_uuid); |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 265 | |
| 266 | client_connection_->mutate_received_packets( |
| 267 | client_connection_->received_packets() + 1); |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 268 | |
| 269 | if (timestamp_logger_) { |
Austin Schuh | eeaa202 | 2021-01-02 21:52:03 -0800 | [diff] [blame] | 270 | flatbuffers::FlatBufferBuilder fbb; |
Austin Schuh | 5e2bfb8 | 2021-03-13 22:46:55 -0800 | [diff] [blame] | 271 | fbb.ForceDefaults(true); |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 272 | // Reset the filter every time the UUID changes. There's probably a more |
| 273 | // clever way to do this, but that means a better concept of rebooting. |
| 274 | if (server_status_->BootUUID(destination_node_index_) != |
Austin Schuh | 5e2bfb8 | 2021-03-13 22:46:55 -0800 | [diff] [blame] | 275 | send_node_factory_->boot_uuid()) { |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 276 | server_status_->ResetFilter(destination_node_index_); |
Austin Schuh | 5e2bfb8 | 2021-03-13 22:46:55 -0800 | [diff] [blame] | 277 | server_status_->SetBootUUID(destination_node_index_, |
| 278 | send_node_factory_->boot_uuid()); |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 279 | } |
| 280 | |
Austin Schuh | cdd9027 | 2021-03-15 12:46:16 -0700 | [diff] [blame] | 281 | flatbuffers::Offset<flatbuffers::Vector<uint8_t>> boot_uuid_offset = |
| 282 | send_node_factory_->boot_uuid().PackVector(&fbb); |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 283 | |
Austin Schuh | eeaa202 | 2021-01-02 21:52:03 -0800 | [diff] [blame] | 284 | RemoteMessage::Builder message_header_builder(fbb); |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 285 | |
| 286 | message_header_builder.add_channel_index(channel_index_); |
| 287 | |
| 288 | // Swap the remote and sent metrics. They are from the sender's |
| 289 | // perspective, not the receiver's perspective. |
| 290 | message_header_builder.add_monotonic_remote_time( |
| 291 | fetcher_->context().monotonic_event_time.time_since_epoch().count()); |
| 292 | message_header_builder.add_realtime_remote_time( |
| 293 | fetcher_->context().realtime_event_time.time_since_epoch().count()); |
| 294 | message_header_builder.add_remote_queue_index( |
| 295 | fetcher_->context().queue_index); |
| 296 | |
| 297 | message_header_builder.add_monotonic_sent_time( |
| 298 | sender_->monotonic_sent_time().time_since_epoch().count()); |
| 299 | message_header_builder.add_realtime_sent_time( |
| 300 | sender_->realtime_sent_time().time_since_epoch().count()); |
| 301 | message_header_builder.add_queue_index(sender_->sent_queue_index()); |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 302 | message_header_builder.add_boot_uuid(boot_uuid_offset); |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 303 | |
Austin Schuh | eeaa202 | 2021-01-02 21:52:03 -0800 | [diff] [blame] | 304 | fbb.Finish(message_header_builder.Finish()); |
| 305 | |
| 306 | remote_timestamps_.emplace_back( |
| 307 | FlatbufferDetachedBuffer<RemoteMessage>(fbb.Release()), |
| 308 | fetch_node_factory_->monotonic_now() + |
| 309 | send_node_factory_->network_delay()); |
| 310 | ScheduleTimestamp(); |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 313 | sent_ = true; |
| 314 | Schedule(); |
| 315 | } |
| 316 | |
Austin Schuh | eeaa202 | 2021-01-02 21:52:03 -0800 | [diff] [blame] | 317 | // Schedules sending the next timestamp in remote_timestamps_ if there is one. |
| 318 | void ScheduleTimestamp() { |
| 319 | if (remote_timestamps_.empty()) { |
| 320 | timestamp_timer_->Disable(); |
| 321 | return; |
| 322 | } |
| 323 | |
| 324 | if (scheduled_time_ != |
| 325 | remote_timestamps_.front().monotonic_timestamp_time) { |
| 326 | timestamp_timer_->Setup( |
| 327 | remote_timestamps_.front().monotonic_timestamp_time); |
| 328 | scheduled_time_ = remote_timestamps_.front().monotonic_timestamp_time; |
| 329 | return; |
| 330 | } else { |
| 331 | scheduled_time_ = monotonic_clock::min_time; |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | // Sends the next timestamp in remote_timestamps_. |
| 336 | void SendTimestamp() { |
| 337 | CHECK(!remote_timestamps_.empty()); |
| 338 | |
| 339 | // Send out all timestamps at the currently scheduled time. |
| 340 | while (remote_timestamps_.front().monotonic_timestamp_time == |
| 341 | scheduled_time_) { |
| 342 | if (server_connection_->state() == State::CONNECTED) { |
milind | 1f1dca3 | 2021-07-03 13:50:07 -0700 | [diff] [blame] | 343 | timestamp_logger_->CheckOk(timestamp_logger_->Send( |
| 344 | std::move(remote_timestamps_.front().remote_message))); |
Austin Schuh | eeaa202 | 2021-01-02 21:52:03 -0800 | [diff] [blame] | 345 | } |
| 346 | remote_timestamps_.pop_front(); |
| 347 | if (remote_timestamps_.empty()) { |
| 348 | break; |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | ScheduleTimestamp(); |
| 353 | } |
| 354 | |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 355 | // Converts from time on the sending node to time on the receiving node. |
| 356 | monotonic_clock::time_point DeliveredTime(const Context &context) const { |
| 357 | const distributed_clock::time_point distributed_sent_time = |
| 358 | fetch_node_factory_->ToDistributedClock(context.monotonic_event_time); |
| 359 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 360 | const logger::BootTimestamp t = send_node_factory_->FromDistributedClock( |
Austin Schuh | 2febf0d | 2020-09-21 22:24:30 -0700 | [diff] [blame] | 361 | distributed_sent_time + send_node_factory_->network_delay() + |
| 362 | send_node_factory_->send_delay()); |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 363 | CHECK_EQ(t.boot, send_node_factory_->boot_count()); |
| 364 | return t.time; |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 365 | } |
| 366 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 367 | const Channel *channel_; |
| 368 | const Connection *connection_; |
| 369 | |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 370 | // Factories used for time conversion. |
| 371 | aos::NodeEventLoopFactory *fetch_node_factory_; |
| 372 | aos::NodeEventLoopFactory *send_node_factory_; |
| 373 | |
Austin Schuh | eeaa202 | 2021-01-02 21:52:03 -0800 | [diff] [blame] | 374 | // Event loop which fetching and sending timestamps are scheduled on. |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 375 | aos::EventLoop *fetch_event_loop_ = nullptr; |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 376 | // Event loop which sending is scheduled on. |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 377 | aos::EventLoop *send_event_loop_ = nullptr; |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 378 | // Timer used to send. |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 379 | aos::TimerHandler *timer_ = nullptr; |
Austin Schuh | eeaa202 | 2021-01-02 21:52:03 -0800 | [diff] [blame] | 380 | // Timer used to send timestamps out. |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 381 | aos::TimerHandler *timestamp_timer_ = nullptr; |
Austin Schuh | eeaa202 | 2021-01-02 21:52:03 -0800 | [diff] [blame] | 382 | // Time that the timer is scheduled for. Used to track if it needs to be |
| 383 | // rescheduled. |
| 384 | monotonic_clock::time_point scheduled_time_ = monotonic_clock::min_time; |
| 385 | |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 386 | // Fetcher used to receive messages. |
| 387 | std::unique_ptr<aos::RawFetcher> fetcher_; |
| 388 | // Sender to send them back out. |
| 389 | std::unique_ptr<aos::RawSender> sender_; |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 390 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 391 | MessageBridgeServerStatus *server_status_ = nullptr; |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 392 | const size_t destination_node_index_; |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 393 | // True if we have sent the message in the fetcher. |
| 394 | bool sent_ = false; |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 395 | |
| 396 | ServerConnection *server_connection_ = nullptr; |
| 397 | MessageBridgeClientStatus *client_status_ = nullptr; |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 398 | int client_index_ = -1; |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 399 | ClientConnection *client_connection_ = nullptr; |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 400 | |
| 401 | size_t channel_index_; |
Austin Schuh | 0de30f3 | 2020-12-06 12:44:28 -0800 | [diff] [blame] | 402 | aos::Sender<RemoteMessage> *timestamp_logger_ = nullptr; |
Austin Schuh | eeaa202 | 2021-01-02 21:52:03 -0800 | [diff] [blame] | 403 | |
| 404 | struct Timestamp { |
| 405 | Timestamp(FlatbufferDetachedBuffer<RemoteMessage> new_remote_message, |
| 406 | monotonic_clock::time_point new_monotonic_timestamp_time) |
| 407 | : remote_message(std::move(new_remote_message)), |
| 408 | monotonic_timestamp_time(new_monotonic_timestamp_time) {} |
| 409 | FlatbufferDetachedBuffer<RemoteMessage> remote_message; |
| 410 | monotonic_clock::time_point monotonic_timestamp_time; |
| 411 | }; |
| 412 | |
| 413 | std::deque<Timestamp> remote_timestamps_; |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 414 | |
| 415 | bool delivery_time_is_logged_; |
| 416 | |
| 417 | bool forwarding_disabled_ = false; |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 418 | }; |
| 419 | |
| 420 | SimulatedMessageBridge::SimulatedMessageBridge( |
| 421 | SimulatedEventLoopFactory *simulated_event_loop_factory) { |
| 422 | CHECK( |
| 423 | configuration::MultiNode(simulated_event_loop_factory->configuration())); |
| 424 | |
| 425 | // Pre-build up event loops for every node. They are pretty cheap anyways. |
| 426 | for (const Node *node : simulated_event_loop_factory->nodes()) { |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 427 | NodeEventLoopFactory *node_factory = |
| 428 | simulated_event_loop_factory->GetNodeEventLoopFactory(node); |
| 429 | auto it = event_loop_map_.emplace(node, node_factory); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 430 | CHECK(it.second); |
| 431 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 432 | node_factory->OnStartup( |
| 433 | [this, simulated_event_loop_factory, node_state = &it.first->second]() { |
| 434 | node_state->MakeEventLoop(); |
| 435 | const size_t my_node_index = configuration::GetNodeIndex( |
| 436 | simulated_event_loop_factory->configuration(), |
| 437 | node_state->event_loop->node()); |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 438 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 439 | size_t node_index = 0; |
| 440 | for (ServerConnection *connection : |
| 441 | node_state->server_status->server_connection()) { |
| 442 | if (connection != nullptr) { |
| 443 | node_state->server_status->ResetFilter(node_index); |
| 444 | } |
| 445 | ++node_index; |
| 446 | } |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 447 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 448 | for (const ClientConnection *client_connections : |
| 449 | *node_state->client_status->mutable_client_statistics() |
| 450 | ->connections()) { |
| 451 | const Node *client_node = configuration::GetNode( |
| 452 | simulated_event_loop_factory->configuration(), |
| 453 | client_connections->node()->name()->string_view()); |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 454 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 455 | auto client_event_loop = event_loop_map_.find(client_node); |
| 456 | client_event_loop->second.SetBootUUID( |
| 457 | my_node_index, node_state->event_loop->boot_uuid()); |
| 458 | } |
| 459 | }); |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 460 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 461 | node_factory->OnShutdown([node_state = &it.first->second]() { |
| 462 | node_state->SetEventLoop(nullptr); |
| 463 | }); |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 464 | } |
| 465 | |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 466 | for (const Channel *channel : |
| 467 | *simulated_event_loop_factory->configuration()->channels()) { |
| 468 | if (!channel->has_destination_nodes()) { |
| 469 | continue; |
| 470 | } |
| 471 | |
| 472 | // Find the sending node. |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 473 | const Node *source_node = |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 474 | configuration::GetNode(simulated_event_loop_factory->configuration(), |
| 475 | channel->source_node()->string_view()); |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 476 | auto source_event_loop = event_loop_map_.find(source_node); |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 477 | CHECK(source_event_loop != event_loop_map_.end()); |
| 478 | |
| 479 | std::unique_ptr<DelayersVector> delayers = |
| 480 | std::make_unique<DelayersVector>(); |
| 481 | |
| 482 | // And then build up a RawMessageDelayer for each destination. |
| 483 | for (const Connection *connection : *channel->destination_nodes()) { |
| 484 | const Node *destination_node = |
| 485 | configuration::GetNode(simulated_event_loop_factory->configuration(), |
| 486 | connection->name()->string_view()); |
| 487 | auto destination_event_loop = event_loop_map_.find(destination_node); |
| 488 | CHECK(destination_event_loop != event_loop_map_.end()); |
| 489 | |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 490 | const size_t destination_node_index = configuration::GetNodeIndex( |
| 491 | simulated_event_loop_factory->configuration(), destination_node); |
| 492 | |
| 493 | const bool delivery_time_is_logged = |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 494 | configuration::ConnectionDeliveryTimeIsLoggedOnNode(connection, |
| 495 | source_node); |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 496 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 497 | delayers->v.emplace_back(std::make_unique<RawMessageDelayer>( |
| 498 | channel, connection, |
| 499 | simulated_event_loop_factory->GetNodeEventLoopFactory(source_node), |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 500 | simulated_event_loop_factory->GetNodeEventLoopFactory( |
| 501 | destination_node), |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 502 | destination_node_index, delivery_time_is_logged)); |
| 503 | |
| 504 | source_event_loop->second.AddSourceDelayer(delayers->v.back().get()); |
| 505 | destination_event_loop->second.AddDestinationDelayer( |
| 506 | delayers->v.back().get()); |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 507 | } |
| 508 | |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 509 | const Channel *const timestamp_channel = configuration::GetChannel( |
| 510 | simulated_event_loop_factory->configuration(), "/aos", |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 511 | Timestamp::GetFullyQualifiedName(), "message_bridge", source_node); |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 512 | |
| 513 | if (channel == timestamp_channel) { |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 514 | source_event_loop->second.SetSendData( |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 515 | [captured_delayers = delayers.get()](const Context &) { |
| 516 | for (std::unique_ptr<RawMessageDelayer> &delayer : |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 517 | captured_delayers->v) { |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 518 | delayer->Schedule(); |
| 519 | } |
| 520 | }); |
| 521 | } else { |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 522 | source_event_loop->second.AddDelayerWatcher(channel, delayers.get()); |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 523 | } |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 524 | delayers_list_.emplace_back(std::move(delayers)); |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | SimulatedMessageBridge::~SimulatedMessageBridge() {} |
| 529 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 530 | void SimulatedMessageBridge::DisableForwarding(const Channel *channel) { |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 531 | for (std::unique_ptr<DelayersVector> &delayers : delayers_list_) { |
| 532 | if (delayers->v.size() > 0) { |
| 533 | if (delayers->v[0]->channel() == channel) { |
| 534 | delayers->disable_forwarding = true; |
| 535 | for (std::unique_ptr<RawMessageDelayer> &delayer : delayers->v) { |
| 536 | delayer->set_forwarding_disabled(true); |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 537 | } |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | } |
| 541 | } |
| 542 | |
Austin Schuh | c0b0f72 | 2020-12-12 18:36:06 -0800 | [diff] [blame] | 543 | void SimulatedMessageBridge::Disconnect(const Node *source, |
| 544 | const Node *destination) { |
| 545 | SetState(source, destination, message_bridge::State::DISCONNECTED); |
| 546 | } |
| 547 | |
| 548 | void SimulatedMessageBridge::Connect(const Node *source, |
| 549 | const Node *destination) { |
| 550 | SetState(source, destination, message_bridge::State::CONNECTED); |
| 551 | } |
| 552 | void SimulatedMessageBridge::SetState(const Node *source, |
| 553 | const Node *destination, |
| 554 | message_bridge::State state) { |
| 555 | auto source_state = event_loop_map_.find(source); |
| 556 | CHECK(source_state != event_loop_map_.end()); |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 557 | source_state->second.SetServerState(destination, state); |
Austin Schuh | c0b0f72 | 2020-12-12 18:36:06 -0800 | [diff] [blame] | 558 | |
| 559 | auto destination_state = event_loop_map_.find(destination); |
| 560 | CHECK(destination_state != event_loop_map_.end()); |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 561 | destination_state->second.SetClientState(source, state); |
Austin Schuh | c0b0f72 | 2020-12-12 18:36:06 -0800 | [diff] [blame] | 562 | } |
| 563 | |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 564 | void SimulatedMessageBridge::DisableStatistics() { |
| 565 | for (std::pair<const Node *const, State> &state : event_loop_map_) { |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 566 | state.second.DisableStatistics(); |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 567 | } |
| 568 | } |
| 569 | |
Austin Schuh | 48205e6 | 2021-11-12 14:13:18 -0800 | [diff] [blame] | 570 | void SimulatedMessageBridge::DisableStatistics(const Node *node) { |
| 571 | auto it = event_loop_map_.find(node); |
| 572 | CHECK(it != event_loop_map_.end()); |
| 573 | it->second.DisableStatistics(); |
| 574 | } |
| 575 | |
| 576 | void SimulatedMessageBridge::EnableStatistics() { |
| 577 | for (std::pair<const Node *const, State> &state : event_loop_map_) { |
| 578 | state.second.EnableStatistics(); |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | void SimulatedMessageBridge::EnableStatistics(const Node *node) { |
| 583 | auto it = event_loop_map_.find(node); |
| 584 | CHECK(it != event_loop_map_.end()); |
| 585 | it->second.EnableStatistics(); |
| 586 | } |
| 587 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 588 | void SimulatedMessageBridge::State::SetEventLoop( |
| 589 | std::unique_ptr<aos::EventLoop> loop) { |
| 590 | if (!loop) { |
| 591 | timestamp_loggers = ChannelTimestampSender(nullptr); |
| 592 | server_status.reset(); |
| 593 | client_status.reset(); |
| 594 | for (RawMessageDelayer *source_delayer : source_delayers_) { |
| 595 | source_delayer->SetFetchEventLoop(nullptr, nullptr, nullptr); |
| 596 | } |
| 597 | for (RawMessageDelayer *destination_delayer : destination_delayers_) { |
| 598 | destination_delayer->SetSendEventLoop(nullptr, nullptr); |
| 599 | } |
| 600 | event_loop = std::move(loop); |
| 601 | return; |
| 602 | } else { |
| 603 | CHECK(!event_loop); |
| 604 | } |
| 605 | event_loop = std::move(loop); |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 606 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 607 | event_loop->SkipTimingReport(); |
| 608 | event_loop->SkipAosLog(); |
| 609 | |
| 610 | for (std::pair<const Channel *, DelayersVector *> &watcher : |
| 611 | delayer_watchers_) { |
| 612 | // Don't register watchers if we know we aren't forwarding. |
| 613 | if (watcher.second->disable_forwarding) continue; |
| 614 | event_loop->MakeRawNoArgWatcher( |
| 615 | watcher.first, [captured_delayers = watcher.second](const Context &) { |
| 616 | // We might get told after registering, so don't forward at that point |
| 617 | // too. |
| 618 | for (std::unique_ptr<RawMessageDelayer> &delayer : |
| 619 | captured_delayers->v) { |
| 620 | delayer->Schedule(); |
| 621 | } |
| 622 | }); |
| 623 | } |
| 624 | |
| 625 | timestamp_loggers = ChannelTimestampSender(event_loop.get()); |
| 626 | server_status = std::make_unique<MessageBridgeServerStatus>(event_loop.get()); |
Austin Schuh | 48205e6 | 2021-11-12 14:13:18 -0800 | [diff] [blame] | 627 | if (disable_statistics_) { |
| 628 | server_status->DisableStatistics(); |
| 629 | } |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 630 | |
| 631 | { |
| 632 | size_t node_index = 0; |
| 633 | for (ServerConnection *connection : server_status->server_connection()) { |
| 634 | if (connection) { |
| 635 | if (boot_uuids_[node_index] != UUID::Zero()) { |
Austin Schuh | 367a7f4 | 2021-11-23 23:04:36 -0800 | [diff] [blame] | 636 | switch (server_state_[node_index]) { |
| 637 | case message_bridge::State::DISCONNECTED: |
| 638 | server_status->Disconnect(node_index); |
| 639 | break; |
| 640 | case message_bridge::State::CONNECTED: |
| 641 | server_status->Connect(node_index, event_loop->monotonic_now()); |
| 642 | break; |
| 643 | } |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 644 | } else { |
Austin Schuh | 367a7f4 | 2021-11-23 23:04:36 -0800 | [diff] [blame] | 645 | server_status->Disconnect(node_index); |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 646 | } |
| 647 | } |
| 648 | ++node_index; |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | for (size_t i = 0; i < boot_uuids_.size(); ++i) { |
| 653 | if (boot_uuids_[i] != UUID::Zero()) { |
| 654 | server_status->SetBootUUID(i, boot_uuids_[i]); |
| 655 | } |
| 656 | } |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 657 | if (fn_) { |
| 658 | server_status->set_send_data(fn_); |
| 659 | } |
| 660 | client_status = std::make_unique<MessageBridgeClientStatus>(event_loop.get()); |
| 661 | if (disable_statistics_) { |
| 662 | client_status->DisableStatistics(); |
| 663 | } |
| 664 | |
| 665 | for (size_t i = 0; |
| 666 | i < client_status->mutable_client_statistics()->connections()->size(); |
| 667 | ++i) { |
| 668 | ClientConnection *client_connection = |
| 669 | client_status->mutable_client_statistics() |
| 670 | ->mutable_connections() |
| 671 | ->GetMutableObject(i); |
| 672 | const Node *client_node = configuration::GetNode( |
| 673 | node_factory_->configuration(), |
| 674 | client_connection->node()->name()->string_view()); |
| 675 | const size_t client_node_index = configuration::GetNodeIndex( |
| 676 | node_factory_->configuration(), client_node); |
| 677 | if (boot_uuids_[client_node_index] != UUID::Zero()) { |
Austin Schuh | 367a7f4 | 2021-11-23 23:04:36 -0800 | [diff] [blame] | 678 | if (client_connection->state() != client_state_[client_node_index]) { |
| 679 | switch (client_state_[client_node_index]) { |
| 680 | case message_bridge::State::DISCONNECTED: |
| 681 | client_status->Disconnect(i); |
| 682 | break; |
| 683 | case message_bridge::State::CONNECTED: |
| 684 | client_status->Connect(i); |
| 685 | break; |
| 686 | } |
| 687 | } |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 688 | } else { |
Austin Schuh | 367a7f4 | 2021-11-23 23:04:36 -0800 | [diff] [blame] | 689 | client_status->Disconnect(i); |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 693 | for (const Channel *channel : *event_loop->configuration()->channels()) { |
| 694 | CHECK(channel->has_source_node()); |
| 695 | |
| 696 | // Sent by us. |
| 697 | if (configuration::ChannelIsSendableOnNode(channel, event_loop->node()) && |
| 698 | channel->has_destination_nodes()) { |
| 699 | for (const Connection *connection : *channel->destination_nodes()) { |
| 700 | const bool delivery_time_is_logged = |
| 701 | configuration::ConnectionDeliveryTimeIsLoggedOnNode( |
| 702 | connection, event_loop->node()); |
| 703 | |
| 704 | // And the timestamps are then logged back by us again. |
| 705 | if (!delivery_time_is_logged) { |
| 706 | continue; |
| 707 | } |
| 708 | |
Austin Schuh | 89c9b81 | 2021-02-20 14:42:10 -0800 | [diff] [blame] | 709 | timestamp_loggers.SenderForChannel(channel, connection); |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 710 | } |
| 711 | } |
| 712 | } |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 713 | |
| 714 | for (RawMessageDelayer *source_delayer : source_delayers_) { |
| 715 | source_delayer->SetFetchEventLoop(event_loop.get(), server_status.get(), |
| 716 | ×tamp_loggers); |
| 717 | } |
| 718 | for (RawMessageDelayer *destination_delayer : destination_delayers_) { |
| 719 | destination_delayer->SetSendEventLoop(event_loop.get(), |
| 720 | client_status.get()); |
| 721 | } |
| 722 | event_loop->OnRun([this]() { |
| 723 | for (RawMessageDelayer *destination_delayer : destination_delayers_) { |
| 724 | if (destination_delayer->time_to_live() == 0) { |
| 725 | destination_delayer->ScheduleReliable(); |
| 726 | } |
| 727 | } |
| 728 | }); |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 729 | } |
| 730 | |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 731 | } // namespace message_bridge |
| 732 | } // namespace aos |