John Park | 398c74a | 2018-10-20 21:17:39 -0700 | [diff] [blame] | 1 | #include "aos/configuration.h" |
Brian Silverman | 66f079a | 2013-08-26 16:24:30 -0700 | [diff] [blame] | 2 | |
Brian Silverman | 66f079a | 2013-08-26 16:24:30 -0700 | [diff] [blame] | 3 | #include <arpa/inet.h> |
| 4 | #include <ifaddrs.h> |
Austin Schuh | f1fff28 | 2020-03-28 16:57:32 -0700 | [diff] [blame] | 5 | #include <netinet/in.h> |
| 6 | #include <stdlib.h> |
| 7 | #include <string.h> |
| 8 | #include <sys/types.h> |
Brian Silverman | 66f079a | 2013-08-26 16:24:30 -0700 | [diff] [blame] | 9 | #include <unistd.h> |
Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 10 | |
| 11 | #include <set> |
James Kuszmaul | 3ae4226 | 2019-11-08 12:33:41 -0800 | [diff] [blame] | 12 | #include <string_view> |
Brian Silverman | 66f079a | 2013-08-26 16:24:30 -0700 | [diff] [blame] | 13 | |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 14 | #include "absl/container/btree_set.h" |
Austin Schuh | a81454b | 2020-05-12 19:58:36 -0700 | [diff] [blame] | 15 | #include "absl/strings/str_cat.h" |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 16 | #include "aos/configuration_generated.h" |
| 17 | #include "aos/flatbuffer_merge.h" |
| 18 | #include "aos/json_to_flatbuffer.h" |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 19 | #include "aos/network/team_number.h" |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 20 | #include "aos/unique_malloc_ptr.h" |
| 21 | #include "aos/util/file.h" |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 22 | #include "gflags/gflags.h" |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 23 | #include "glog/logging.h" |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 24 | |
Brian Silverman | 66f079a | 2013-08-26 16:24:30 -0700 | [diff] [blame] | 25 | namespace aos { |
Austin Schuh | 1518232 | 2020-10-10 15:25:21 -0700 | [diff] [blame] | 26 | namespace { |
| 27 | bool EndsWith(std::string_view str, std::string_view end) { |
| 28 | if (str.size() < end.size()) { |
| 29 | return false; |
| 30 | } |
| 31 | if (str.substr(str.size() - end.size(), end.size()) != end) { |
| 32 | return false; |
| 33 | } |
| 34 | return true; |
| 35 | } |
| 36 | |
| 37 | std::string MaybeReplaceExtension(std::string_view filename, |
| 38 | std::string_view extension, |
| 39 | std::string_view replacement) { |
| 40 | if (!EndsWith(filename, extension)) { |
| 41 | return std::string(filename); |
| 42 | } |
| 43 | filename.remove_suffix(extension.size()); |
| 44 | return absl::StrCat(filename, replacement); |
| 45 | } |
| 46 | |
| 47 | FlatbufferDetachedBuffer<Configuration> ReadConfigFile(std::string_view path, |
| 48 | bool binary) { |
| 49 | if (binary) { |
| 50 | FlatbufferVector<Configuration> config = |
| 51 | FileToFlatbuffer<Configuration>(path); |
| 52 | return CopySpanAsDetachedBuffer(config.span()); |
| 53 | } |
| 54 | |
| 55 | flatbuffers::DetachedBuffer buffer = JsonToFlatbuffer( |
| 56 | util::ReadFileToStringOrDie(path), ConfigurationTypeTable()); |
| 57 | |
| 58 | CHECK_GT(buffer.size(), 0u) << ": Failed to parse JSON file"; |
| 59 | |
| 60 | return FlatbufferDetachedBuffer<Configuration>(std::move(buffer)); |
| 61 | } |
| 62 | |
| 63 | } // namespace |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 64 | |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 65 | // Define the compare and equal operators for Channel and Application so we can |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 66 | // insert them in the btree below. |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 67 | bool operator<(const FlatbufferDetachedBuffer<Channel> &lhs, |
| 68 | const FlatbufferDetachedBuffer<Channel> &rhs) { |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 69 | int name_compare = lhs.message().name()->string_view().compare( |
| 70 | rhs.message().name()->string_view()); |
| 71 | if (name_compare == 0) { |
| 72 | return lhs.message().type()->string_view() < |
| 73 | rhs.message().type()->string_view(); |
| 74 | } else if (name_compare < 0) { |
| 75 | return true; |
| 76 | } else { |
| 77 | return false; |
| 78 | } |
| 79 | } |
| 80 | |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 81 | bool operator==(const FlatbufferDetachedBuffer<Channel> &lhs, |
| 82 | const FlatbufferDetachedBuffer<Channel> &rhs) { |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 83 | return lhs.message().name()->string_view() == |
| 84 | rhs.message().name()->string_view() && |
| 85 | lhs.message().type()->string_view() == |
| 86 | rhs.message().type()->string_view(); |
| 87 | } |
| 88 | |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 89 | bool operator==(const FlatbufferDetachedBuffer<Application> &lhs, |
| 90 | const FlatbufferDetachedBuffer<Application> &rhs) { |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 91 | return lhs.message().name()->string_view() == |
| 92 | rhs.message().name()->string_view(); |
| 93 | } |
| 94 | |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 95 | bool operator<(const FlatbufferDetachedBuffer<Application> &lhs, |
| 96 | const FlatbufferDetachedBuffer<Application> &rhs) { |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 97 | return lhs.message().name()->string_view() < |
| 98 | rhs.message().name()->string_view(); |
| 99 | } |
| 100 | |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 101 | bool operator==(const FlatbufferDetachedBuffer<Node> &lhs, |
| 102 | const FlatbufferDetachedBuffer<Node> &rhs) { |
| 103 | return lhs.message().name()->string_view() == |
| 104 | rhs.message().name()->string_view(); |
| 105 | } |
| 106 | |
| 107 | bool operator<(const FlatbufferDetachedBuffer<Node> &lhs, |
| 108 | const FlatbufferDetachedBuffer<Node> &rhs) { |
| 109 | return lhs.message().name()->string_view() < |
| 110 | rhs.message().name()->string_view(); |
| 111 | } |
| 112 | |
Brian Silverman | 66f079a | 2013-08-26 16:24:30 -0700 | [diff] [blame] | 113 | namespace configuration { |
| 114 | namespace { |
| 115 | |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 116 | // Extracts the folder part of a path. Returns ./ if there is no path. |
Austin Schuh | f1fff28 | 2020-03-28 16:57:32 -0700 | [diff] [blame] | 117 | std::string_view ExtractFolder(const std::string_view filename) { |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 118 | auto last_slash_pos = filename.find_last_of("/\\"); |
| 119 | |
James Kuszmaul | 3ae4226 | 2019-11-08 12:33:41 -0800 | [diff] [blame] | 120 | return last_slash_pos == std::string_view::npos |
| 121 | ? std::string_view("./") |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 122 | : filename.substr(0, last_slash_pos + 1); |
| 123 | } |
| 124 | |
James Kuszmaul | c0c08da | 2020-05-10 18:56:07 -0700 | [diff] [blame] | 125 | std::string AbsolutePath(const std::string_view filename) { |
| 126 | // Uses an std::string so that we know the input will be null-terminated. |
| 127 | const std::string terminated_file(filename); |
| 128 | char buffer[PATH_MAX]; |
| 129 | PCHECK(NULL != realpath(terminated_file.c_str(), buffer)); |
| 130 | return buffer; |
| 131 | } |
| 132 | |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 133 | FlatbufferDetachedBuffer<Configuration> ReadConfig( |
James Kuszmaul | c0c08da | 2020-05-10 18:56:07 -0700 | [diff] [blame] | 134 | const std::string_view path, absl::btree_set<std::string> *visited_paths, |
| 135 | const std::vector<std::string_view> &extra_import_paths) { |
Austin Schuh | 1518232 | 2020-10-10 15:25:21 -0700 | [diff] [blame] | 136 | std::string binary_path = MaybeReplaceExtension(path, ".json", ".bfbs"); |
| 137 | bool binary_path_exists = util::PathExists(binary_path); |
James Kuszmaul | c0c08da | 2020-05-10 18:56:07 -0700 | [diff] [blame] | 138 | std::string raw_path(path); |
Austin Schuh | 1518232 | 2020-10-10 15:25:21 -0700 | [diff] [blame] | 139 | // For each .json file, look and see if we can find a .bfbs file next to it |
| 140 | // with the same base name. If we can, assume it is the same and use it |
| 141 | // instead. It is much faster to load .bfbs files than .json files. |
| 142 | if (!binary_path_exists && !util::PathExists(raw_path)) { |
| 143 | const bool path_is_absolute = raw_path.size() > 0 && raw_path[0] == '/'; |
James Kuszmaul | c0c08da | 2020-05-10 18:56:07 -0700 | [diff] [blame] | 144 | if (path_is_absolute) { |
| 145 | CHECK(extra_import_paths.empty()) |
| 146 | << "Can't specify extra import paths if attempting to read a config " |
| 147 | "file from an absolute path (path is " |
Austin Schuh | 1518232 | 2020-10-10 15:25:21 -0700 | [diff] [blame] | 148 | << raw_path << ")."; |
James Kuszmaul | c0c08da | 2020-05-10 18:56:07 -0700 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | bool found_path = false; |
| 152 | for (const auto &import_path : extra_import_paths) { |
| 153 | raw_path = std::string(import_path) + "/" + std::string(path); |
Austin Schuh | 1518232 | 2020-10-10 15:25:21 -0700 | [diff] [blame] | 154 | binary_path = MaybeReplaceExtension(raw_path, ".json", ".bfbs"); |
| 155 | binary_path_exists = util::PathExists(binary_path); |
| 156 | if (binary_path_exists) { |
| 157 | found_path = true; |
| 158 | break; |
| 159 | } |
James Kuszmaul | c0c08da | 2020-05-10 18:56:07 -0700 | [diff] [blame] | 160 | if (util::PathExists(raw_path)) { |
| 161 | found_path = true; |
| 162 | break; |
| 163 | } |
| 164 | } |
| 165 | CHECK(found_path) << ": Failed to find file " << path << "."; |
| 166 | } |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 167 | |
Austin Schuh | 1518232 | 2020-10-10 15:25:21 -0700 | [diff] [blame] | 168 | FlatbufferDetachedBuffer<Configuration> config = ReadConfigFile( |
| 169 | binary_path_exists ? binary_path : raw_path, binary_path_exists); |
James Kuszmaul | c0c08da | 2020-05-10 18:56:07 -0700 | [diff] [blame] | 170 | |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 171 | // Depth first. Take the following example: |
| 172 | // |
| 173 | // config1.json: |
| 174 | // { |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 175 | // "channels": [ |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 176 | // { |
| 177 | // "name": "/foo", |
| 178 | // "type": ".aos.bar", |
| 179 | // "max_size": 5 |
| 180 | // } |
| 181 | // ], |
| 182 | // "imports": [ |
| 183 | // "config2.json", |
| 184 | // ] |
| 185 | // } |
| 186 | // |
| 187 | // config2.json: |
| 188 | // { |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 189 | // "channels": [ |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 190 | // { |
| 191 | // "name": "/foo", |
| 192 | // "type": ".aos.bar", |
| 193 | // "max_size": 7 |
| 194 | // } |
| 195 | // ], |
| 196 | // } |
| 197 | // |
| 198 | // We want the main config (config1.json) to be able to override the imported |
| 199 | // config. That means that it needs to be merged into the imported configs, |
| 200 | // not the other way around. |
| 201 | |
Austin Schuh | 1518232 | 2020-10-10 15:25:21 -0700 | [diff] [blame] | 202 | const std::string absolute_path = |
| 203 | AbsolutePath(binary_path_exists ? binary_path : raw_path); |
| 204 | // Track that we have seen this file before recursing. Track the path we |
| 205 | // actually loaded (which should be consistent if imported twice). |
James Kuszmaul | c0c08da | 2020-05-10 18:56:07 -0700 | [diff] [blame] | 206 | if (!visited_paths->insert(absolute_path).second) { |
| 207 | for (const auto &visited_path : *visited_paths) { |
| 208 | LOG(INFO) << "Already visited: " << visited_path; |
| 209 | } |
| 210 | LOG(FATAL) |
| 211 | << "Already imported " << path << " (i.e. " << absolute_path |
| 212 | << "). See above for the files that have already been processed."; |
| 213 | } |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 214 | |
| 215 | if (config.message().has_imports()) { |
| 216 | // Capture the imports. |
| 217 | const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *v = |
| 218 | config.message().imports(); |
| 219 | |
| 220 | // And then wipe them. This gets GCed when we merge later. |
| 221 | config.mutable_message()->clear_imports(); |
| 222 | |
| 223 | // Start with an empty configuration to merge into. |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 224 | FlatbufferDetachedBuffer<Configuration> merged_config = |
| 225 | FlatbufferDetachedBuffer<Configuration>::Empty(); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 226 | |
James Kuszmaul | c0c08da | 2020-05-10 18:56:07 -0700 | [diff] [blame] | 227 | const std::string path_folder(ExtractFolder(path)); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 228 | for (const flatbuffers::String *str : *v) { |
James Kuszmaul | c0c08da | 2020-05-10 18:56:07 -0700 | [diff] [blame] | 229 | const std::string included_config = |
| 230 | path_folder + "/" + std::string(str->string_view()); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 231 | |
| 232 | // And them merge everything in. |
| 233 | merged_config = MergeFlatBuffers( |
James Kuszmaul | c0c08da | 2020-05-10 18:56:07 -0700 | [diff] [blame] | 234 | merged_config, |
| 235 | ReadConfig(included_config, visited_paths, extra_import_paths)); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | // Finally, merge this file in. |
| 239 | config = MergeFlatBuffers(merged_config, config); |
| 240 | } |
| 241 | return config; |
| 242 | } |
| 243 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 244 | // Compares (c < p) a channel, and a name, type tuple. |
| 245 | bool CompareChannels(const Channel *c, |
James Kuszmaul | 3ae4226 | 2019-11-08 12:33:41 -0800 | [diff] [blame] | 246 | ::std::pair<std::string_view, std::string_view> p) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 247 | int name_compare = c->name()->string_view().compare(p.first); |
| 248 | if (name_compare == 0) { |
| 249 | return c->type()->string_view() < p.second; |
| 250 | } else if (name_compare < 0) { |
| 251 | return true; |
| 252 | } else { |
| 253 | return false; |
| 254 | } |
| 255 | }; |
| 256 | |
| 257 | // Compares for equality (c == p) a channel, and a name, type tuple. |
| 258 | bool EqualsChannels(const Channel *c, |
Austin Schuh | f1fff28 | 2020-03-28 16:57:32 -0700 | [diff] [blame] | 259 | ::std::pair<std::string_view, std::string_view> p) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 260 | return c->name()->string_view() == p.first && |
| 261 | c->type()->string_view() == p.second; |
| 262 | } |
| 263 | |
| 264 | // Compares (c < p) an application, and a name; |
James Kuszmaul | 3ae4226 | 2019-11-08 12:33:41 -0800 | [diff] [blame] | 265 | bool CompareApplications(const Application *a, std::string_view name) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 266 | return a->name()->string_view() < name; |
| 267 | }; |
| 268 | |
| 269 | // Compares for equality (c == p) an application, and a name; |
James Kuszmaul | 3ae4226 | 2019-11-08 12:33:41 -0800 | [diff] [blame] | 270 | bool EqualsApplications(const Application *a, std::string_view name) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 271 | return a->name()->string_view() == name; |
| 272 | } |
| 273 | |
| 274 | // Maps name for the provided maps. Modifies name. |
| 275 | void HandleMaps(const flatbuffers::Vector<flatbuffers::Offset<aos::Map>> *maps, |
Austin Schuh | f1fff28 | 2020-03-28 16:57:32 -0700 | [diff] [blame] | 276 | std::string *name, std::string_view type, const Node *node) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 277 | // For the same reason we merge configs in reverse order, we want to process |
| 278 | // maps in reverse order. That lets the outer config overwrite channels from |
| 279 | // the inner configs. |
| 280 | for (auto i = maps->rbegin(); i != maps->rend(); ++i) { |
Austin Schuh | bca6cf0 | 2019-12-22 17:28:34 -0800 | [diff] [blame] | 281 | if (!i->has_match() || !i->match()->has_name()) { |
| 282 | continue; |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 283 | } |
Austin Schuh | bca6cf0 | 2019-12-22 17:28:34 -0800 | [diff] [blame] | 284 | if (!i->has_rename() || !i->rename()->has_name()) { |
| 285 | continue; |
| 286 | } |
| 287 | |
| 288 | // Handle normal maps (now that we know that match and rename are filled |
| 289 | // out). |
Austin Schuh | f1fff28 | 2020-03-28 16:57:32 -0700 | [diff] [blame] | 290 | const std::string_view match_name = i->match()->name()->string_view(); |
| 291 | if (match_name != *name) { |
| 292 | if (match_name.back() == '*' && |
| 293 | std::string_view(*name).substr( |
| 294 | 0, std::min(name->size(), match_name.size() - 1)) == |
| 295 | match_name.substr(0, match_name.size() - 1)) { |
| 296 | CHECK_EQ(match_name.find('*'), match_name.size() - 1); |
| 297 | } else { |
| 298 | continue; |
| 299 | } |
Austin Schuh | bca6cf0 | 2019-12-22 17:28:34 -0800 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | // Handle type specific maps. |
| 303 | if (i->match()->has_type() && i->match()->type()->string_view() != type) { |
| 304 | continue; |
| 305 | } |
| 306 | |
Austin Schuh | f1fff28 | 2020-03-28 16:57:32 -0700 | [diff] [blame] | 307 | // Now handle node specific maps. |
Austin Schuh | bca6cf0 | 2019-12-22 17:28:34 -0800 | [diff] [blame] | 308 | if (node != nullptr && i->match()->has_source_node() && |
| 309 | i->match()->source_node()->string_view() != |
| 310 | node->name()->string_view()) { |
| 311 | continue; |
| 312 | } |
| 313 | |
Austin Schuh | f1fff28 | 2020-03-28 16:57:32 -0700 | [diff] [blame] | 314 | std::string new_name(i->rename()->name()->string_view()); |
| 315 | if (match_name.back() == '*') { |
| 316 | new_name += std::string(name->substr(match_name.size() - 1)); |
| 317 | } |
| 318 | VLOG(1) << "Renamed \"" << *name << "\" to \"" << new_name << "\""; |
| 319 | *name = std::move(new_name); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | |
Austin Schuh | 1518232 | 2020-10-10 15:25:21 -0700 | [diff] [blame] | 323 | void ValidateConfiguration(const Flatbuffer<Configuration> &config) { |
| 324 | // No imports should be left. |
| 325 | CHECK(!config.message().has_imports()); |
| 326 | |
| 327 | // Check that if there is a node list, all the source nodes are filled out and |
| 328 | // valid, and all the destination nodes are valid (and not the source). This |
| 329 | // is a basic consistency check. |
| 330 | if (config.message().has_channels()) { |
| 331 | const Channel *last_channel = nullptr; |
| 332 | for (const Channel *c : *config.message().channels()) { |
| 333 | CHECK(c->has_name()); |
| 334 | CHECK(c->has_type()); |
| 335 | if (c->name()->string_view().back() == '/') { |
| 336 | LOG(FATAL) << "Channel names can't end with '/'"; |
| 337 | } |
| 338 | if (c->name()->string_view().find("//") != std::string_view::npos) { |
| 339 | LOG(FATAL) << ": Invalid channel name " << c->name()->string_view() |
| 340 | << ", can't use //."; |
| 341 | } |
| 342 | for (const char data : c->name()->string_view()) { |
| 343 | if (data >= '0' && data <= '9') { |
| 344 | continue; |
| 345 | } |
| 346 | if (data >= 'a' && data <= 'z') { |
| 347 | continue; |
| 348 | } |
| 349 | if (data >= 'A' && data <= 'Z') { |
| 350 | continue; |
| 351 | } |
| 352 | if (data == '-' || data == '_' || data == '/') { |
| 353 | continue; |
| 354 | } |
| 355 | LOG(FATAL) << "Invalid channel name " << c->name()->string_view() |
| 356 | << ", can only use [-a-zA-Z0-9_/]"; |
| 357 | } |
| 358 | |
| 359 | // Make sure everything is sorted while we are here... If this fails, |
| 360 | // there will be a bunch of weird errors. |
| 361 | if (last_channel != nullptr) { |
| 362 | CHECK(CompareChannels( |
| 363 | last_channel, |
| 364 | std::make_pair(c->name()->string_view(), c->type()->string_view()))) |
| 365 | << ": Channels not sorted!"; |
| 366 | } |
| 367 | last_channel = c; |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | if (config.message().has_nodes() && config.message().has_channels()) { |
| 372 | for (const Channel *c : *config.message().channels()) { |
| 373 | CHECK(c->has_source_node()) << ": Channel " << FlatbufferToJson(c) |
| 374 | << " is missing \"source_node\""; |
| 375 | CHECK(GetNode(&config.message(), c->source_node()->string_view()) != |
| 376 | nullptr) |
| 377 | << ": Channel " << FlatbufferToJson(c) |
| 378 | << " has an unknown \"source_node\""; |
| 379 | |
| 380 | if (c->has_destination_nodes()) { |
| 381 | for (const Connection *connection : *c->destination_nodes()) { |
| 382 | CHECK(connection->has_name()); |
| 383 | CHECK(GetNode(&config.message(), connection->name()->string_view()) != |
| 384 | nullptr) |
| 385 | << ": Channel " << FlatbufferToJson(c) |
| 386 | << " has an unknown \"destination_nodes\" " |
| 387 | << connection->name()->string_view(); |
| 388 | |
| 389 | switch (connection->timestamp_logger()) { |
| 390 | case LoggerConfig::LOCAL_LOGGER: |
| 391 | case LoggerConfig::NOT_LOGGED: |
| 392 | CHECK(!connection->has_timestamp_logger_nodes()); |
| 393 | break; |
| 394 | case LoggerConfig::REMOTE_LOGGER: |
| 395 | case LoggerConfig::LOCAL_AND_REMOTE_LOGGER: |
| 396 | CHECK(connection->has_timestamp_logger_nodes()); |
| 397 | CHECK_GT(connection->timestamp_logger_nodes()->size(), 0u); |
| 398 | for (const flatbuffers::String *timestamp_logger_node : |
| 399 | *connection->timestamp_logger_nodes()) { |
| 400 | CHECK(GetNode(&config.message(), |
| 401 | timestamp_logger_node->string_view()) != nullptr) |
| 402 | << ": Channel " << FlatbufferToJson(c) |
| 403 | << " has an unknown \"timestamp_logger_node\"" |
| 404 | << connection->name()->string_view(); |
| 405 | } |
| 406 | break; |
| 407 | } |
| 408 | |
| 409 | CHECK_NE(connection->name()->string_view(), |
| 410 | c->source_node()->string_view()) |
| 411 | << ": Channel " << FlatbufferToJson(c) |
| 412 | << " is forwarding data to itself"; |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 419 | } // namespace |
| 420 | |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 421 | FlatbufferDetachedBuffer<Configuration> MergeConfiguration( |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 422 | const Flatbuffer<Configuration> &config) { |
James Kuszmaul | 3c99859 | 2020-07-27 21:04:47 -0700 | [diff] [blame] | 423 | // auto_merge_config will contain all the fields of the Configuration that are |
| 424 | // to be passed through unmodified to the result of MergeConfiguration(). |
| 425 | // In the processing below, we mutate auto_merge_config to remove any fields |
| 426 | // which we do need to alter (hence why we can't use the input config |
| 427 | // directly), and then merge auto_merge_config back in at the end. |
| 428 | aos::FlatbufferDetachedBuffer<aos::Configuration> auto_merge_config = |
| 429 | aos::CopyFlatBuffer(&config.message()); |
| 430 | |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 431 | // Store all the channels in a sorted set. This lets us track channels we |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 432 | // have seen before and merge the updates in. |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 433 | absl::btree_set<FlatbufferDetachedBuffer<Channel>> channels; |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 434 | |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 435 | if (config.message().has_channels()) { |
James Kuszmaul | 3c99859 | 2020-07-27 21:04:47 -0700 | [diff] [blame] | 436 | auto_merge_config.mutable_message()->clear_channels(); |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 437 | for (const Channel *c : *config.message().channels()) { |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 438 | // Ignore malformed entries. |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 439 | if (!c->has_name()) { |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 440 | continue; |
| 441 | } |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 442 | if (!c->has_type()) { |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 443 | continue; |
| 444 | } |
| 445 | |
Brian Silverman | 7716297 | 2020-08-12 19:52:40 -0700 | [diff] [blame] | 446 | CHECK_EQ(c->read_method() == ReadMethod::PIN, c->num_readers() != 0) |
| 447 | << ": num_readers may be set if and only if read_method is PIN," |
| 448 | " if you want 0 readers do not set PIN: " |
| 449 | << CleanedChannelToString(c); |
| 450 | |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 451 | // Attempt to insert the channel. |
| 452 | auto result = channels.insert(CopyFlatBuffer(c)); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 453 | if (!result.second) { |
| 454 | // Already there, so merge the new table into the original. |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 455 | *result.first = MergeFlatBuffers(*result.first, CopyFlatBuffer(c)); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 456 | } |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | // Now repeat this for the application list. |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 461 | absl::btree_set<FlatbufferDetachedBuffer<Application>> applications; |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 462 | if (config.message().has_applications()) { |
James Kuszmaul | 3c99859 | 2020-07-27 21:04:47 -0700 | [diff] [blame] | 463 | auto_merge_config.mutable_message()->clear_applications(); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 464 | for (const Application *a : *config.message().applications()) { |
| 465 | if (!a->has_name()) { |
| 466 | continue; |
| 467 | } |
| 468 | |
| 469 | auto result = applications.insert(CopyFlatBuffer(a)); |
| 470 | if (!result.second) { |
| 471 | *result.first = MergeFlatBuffers(*result.first, CopyFlatBuffer(a)); |
| 472 | } |
| 473 | } |
| 474 | } |
| 475 | |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 476 | // Now repeat this for the node list. |
| 477 | absl::btree_set<FlatbufferDetachedBuffer<Node>> nodes; |
| 478 | if (config.message().has_nodes()) { |
James Kuszmaul | 3c99859 | 2020-07-27 21:04:47 -0700 | [diff] [blame] | 479 | auto_merge_config.mutable_message()->clear_nodes(); |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 480 | for (const Node *n : *config.message().nodes()) { |
| 481 | if (!n->has_name()) { |
| 482 | continue; |
| 483 | } |
| 484 | |
| 485 | auto result = nodes.insert(CopyFlatBuffer(n)); |
| 486 | if (!result.second) { |
| 487 | *result.first = MergeFlatBuffers(*result.first, CopyFlatBuffer(n)); |
| 488 | } |
| 489 | } |
| 490 | } |
| 491 | |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 492 | flatbuffers::FlatBufferBuilder fbb; |
Austin Schuh | d7b15da | 2020-02-17 15:06:11 -0800 | [diff] [blame] | 493 | fbb.ForceDefaults(true); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 494 | |
| 495 | // Start by building the vectors. They need to come before the final table. |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 496 | // Channels |
| 497 | flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Channel>>> |
| 498 | channels_offset; |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 499 | { |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 500 | ::std::vector<flatbuffers::Offset<Channel>> channel_offsets; |
| 501 | for (const FlatbufferDetachedBuffer<Channel> &c : channels) { |
Austin Schuh | f1fff28 | 2020-03-28 16:57:32 -0700 | [diff] [blame] | 502 | channel_offsets.emplace_back(CopyFlatBuffer<Channel>(&c.message(), &fbb)); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 503 | } |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 504 | channels_offset = fbb.CreateVector(channel_offsets); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | // Applications |
| 508 | flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Application>>> |
| 509 | applications_offset; |
| 510 | { |
| 511 | ::std::vector<flatbuffers::Offset<Application>> applications_offsets; |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 512 | for (const FlatbufferDetachedBuffer<Application> &a : applications) { |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 513 | applications_offsets.emplace_back( |
| 514 | CopyFlatBuffer<Application>(&a.message(), &fbb)); |
| 515 | } |
| 516 | applications_offset = fbb.CreateVector(applications_offsets); |
| 517 | } |
| 518 | |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 519 | // Nodes |
| 520 | flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Node>>> |
| 521 | nodes_offset; |
| 522 | { |
| 523 | ::std::vector<flatbuffers::Offset<Node>> node_offsets; |
| 524 | for (const FlatbufferDetachedBuffer<Node> &n : nodes) { |
| 525 | node_offsets.emplace_back(CopyFlatBuffer<Node>(&n.message(), &fbb)); |
| 526 | } |
| 527 | nodes_offset = fbb.CreateVector(node_offsets); |
| 528 | } |
| 529 | |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 530 | // And then build a Configuration with them all. |
| 531 | ConfigurationBuilder configuration_builder(fbb); |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 532 | configuration_builder.add_channels(channels_offset); |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 533 | if (config.message().has_applications()) { |
| 534 | configuration_builder.add_applications(applications_offset); |
| 535 | } |
| 536 | if (config.message().has_nodes()) { |
| 537 | configuration_builder.add_nodes(nodes_offset); |
| 538 | } |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 539 | |
| 540 | fbb.Finish(configuration_builder.Finish()); |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 541 | |
James Kuszmaul | 3c99859 | 2020-07-27 21:04:47 -0700 | [diff] [blame] | 542 | aos::FlatbufferDetachedBuffer<aos::Configuration> modified_config( |
| 543 | fbb.Release()); |
| 544 | |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 545 | // Now, validate that if there is a node list, every channel has a source |
| 546 | // node. |
James Kuszmaul | 3c99859 | 2020-07-27 21:04:47 -0700 | [diff] [blame] | 547 | FlatbufferDetachedBuffer<Configuration> result = |
| 548 | MergeFlatBuffers(modified_config, auto_merge_config); |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 549 | |
Austin Schuh | 1518232 | 2020-10-10 15:25:21 -0700 | [diff] [blame] | 550 | ValidateConfiguration(result); |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 551 | |
| 552 | return result; |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 553 | } |
| 554 | |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 555 | FlatbufferDetachedBuffer<Configuration> ReadConfig( |
James Kuszmaul | c0c08da | 2020-05-10 18:56:07 -0700 | [diff] [blame] | 556 | const std::string_view path, |
| 557 | const std::vector<std::string_view> &import_paths) { |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 558 | // We only want to read a file once. So track the visited files in a set. |
| 559 | absl::btree_set<std::string> visited_paths; |
Austin Schuh | 1518232 | 2020-10-10 15:25:21 -0700 | [diff] [blame] | 560 | FlatbufferDetachedBuffer<Configuration> read_config = |
| 561 | ReadConfig(path, &visited_paths, import_paths); |
| 562 | |
| 563 | // If we only read one file, and it had a .bfbs extension, it has to be a |
| 564 | // fully formatted config. Do a quick verification and return it. |
| 565 | if (visited_paths.size() == 1 && EndsWith(*visited_paths.begin(), ".bfbs")) { |
| 566 | ValidateConfiguration(read_config); |
| 567 | return read_config; |
| 568 | } |
| 569 | |
| 570 | return MergeConfiguration(read_config); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Austin Schuh | 8d6cea8 | 2020-02-28 12:17:16 -0800 | [diff] [blame] | 573 | FlatbufferDetachedBuffer<Configuration> MergeWithConfig( |
Brian Silverman | 24f5aa8 | 2020-06-23 16:21:28 -0700 | [diff] [blame] | 574 | const Configuration *config, const Flatbuffer<Configuration> &addition) { |
| 575 | return MergeConfiguration(MergeFlatBuffers(config, &addition.message())); |
| 576 | } |
| 577 | |
| 578 | FlatbufferDetachedBuffer<Configuration> MergeWithConfig( |
Austin Schuh | 8d6cea8 | 2020-02-28 12:17:16 -0800 | [diff] [blame] | 579 | const Configuration *config, std::string_view json) { |
| 580 | FlatbufferDetachedBuffer<Configuration> addition = |
| 581 | JsonToFlatbuffer(json, Configuration::MiniReflectTypeTable()); |
| 582 | |
Brian Silverman | 24f5aa8 | 2020-06-23 16:21:28 -0700 | [diff] [blame] | 583 | return MergeWithConfig(config, addition); |
Austin Schuh | 8d6cea8 | 2020-02-28 12:17:16 -0800 | [diff] [blame] | 584 | } |
| 585 | |
James Kuszmaul | 3ae4226 | 2019-11-08 12:33:41 -0800 | [diff] [blame] | 586 | const Channel *GetChannel(const Configuration *config, std::string_view name, |
| 587 | std::string_view type, |
Austin Schuh | bca6cf0 | 2019-12-22 17:28:34 -0800 | [diff] [blame] | 588 | std::string_view application_name, const Node *node) { |
| 589 | const std::string_view original_name = name; |
Austin Schuh | f1fff28 | 2020-03-28 16:57:32 -0700 | [diff] [blame] | 590 | std::string mutable_name; |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 591 | if (node != nullptr) { |
| 592 | VLOG(1) << "Looking up { \"name\": \"" << name << "\", \"type\": \"" << type |
| 593 | << "\" } on " << aos::FlatbufferToJson(node); |
| 594 | } else { |
| 595 | VLOG(1) << "Looking up { \"name\": \"" << name << "\", \"type\": \"" << type |
| 596 | << "\" }"; |
| 597 | } |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 598 | |
| 599 | // First handle application specific maps. Only do this if we have a matching |
| 600 | // application name, and it has maps. |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 601 | if (config->has_applications()) { |
| 602 | auto application_iterator = std::lower_bound( |
| 603 | config->applications()->cbegin(), config->applications()->cend(), |
| 604 | application_name, CompareApplications); |
| 605 | if (application_iterator != config->applications()->cend() && |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 606 | EqualsApplications(*application_iterator, application_name)) { |
| 607 | if (application_iterator->has_maps()) { |
Austin Schuh | f1fff28 | 2020-03-28 16:57:32 -0700 | [diff] [blame] | 608 | mutable_name = std::string(name); |
| 609 | HandleMaps(application_iterator->maps(), &mutable_name, type, node); |
| 610 | name = std::string_view(mutable_name); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 611 | } |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | // Now do global maps. |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 616 | if (config->has_maps()) { |
Austin Schuh | f1fff28 | 2020-03-28 16:57:32 -0700 | [diff] [blame] | 617 | mutable_name = std::string(name); |
| 618 | HandleMaps(config->maps(), &mutable_name, type, node); |
| 619 | name = std::string_view(mutable_name); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 620 | } |
| 621 | |
Austin Schuh | bca6cf0 | 2019-12-22 17:28:34 -0800 | [diff] [blame] | 622 | if (original_name != name) { |
| 623 | VLOG(1) << "Remapped to { \"name\": \"" << name << "\", \"type\": \"" |
| 624 | << type << "\" }"; |
| 625 | } |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 626 | |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 627 | // Then look for the channel. |
| 628 | auto channel_iterator = |
Austin Schuh | f1fff28 | 2020-03-28 16:57:32 -0700 | [diff] [blame] | 629 | std::lower_bound(config->channels()->cbegin(), config->channels()->cend(), |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 630 | std::make_pair(name, type), CompareChannels); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 631 | |
| 632 | // Make sure we actually found it, and it matches. |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 633 | if (channel_iterator != config->channels()->cend() && |
| 634 | EqualsChannels(*channel_iterator, std::make_pair(name, type))) { |
Austin Schuh | bca6cf0 | 2019-12-22 17:28:34 -0800 | [diff] [blame] | 635 | if (VLOG_IS_ON(2)) { |
| 636 | VLOG(2) << "Found: " << FlatbufferToJson(*channel_iterator); |
| 637 | } else if (VLOG_IS_ON(1)) { |
| 638 | VLOG(1) << "Found: " << CleanedChannelToString(*channel_iterator); |
| 639 | } |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 640 | return *channel_iterator; |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 641 | } else { |
| 642 | VLOG(1) << "No match for { \"name\": \"" << name << "\", \"type\": \"" |
| 643 | << type << "\" }"; |
Austin Schuh | 4b42b25 | 2020-10-19 11:35:20 -0700 | [diff] [blame^] | 644 | if (original_name != name) { |
| 645 | LOG(WARNING) << "Remapped from {\"name\": \"" << original_name |
| 646 | << "\", \"type\": \"" << type << "\"}, to {\"name\": \"" |
| 647 | << name << "\", \"type\": \"" << type |
| 648 | << "\"}, but no channel by that name exists."; |
| 649 | } |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 650 | return nullptr; |
| 651 | } |
| 652 | } |
| 653 | |
Austin Schuh | c9e10ec | 2020-01-26 16:08:28 -0800 | [diff] [blame] | 654 | size_t ChannelIndex(const Configuration *configuration, |
| 655 | const Channel *channel) { |
| 656 | CHECK(configuration->channels() != nullptr) << ": No channels"; |
| 657 | |
| 658 | auto c = std::find(configuration->channels()->begin(), |
| 659 | configuration->channels()->end(), channel); |
| 660 | CHECK(c != configuration->channels()->end()) |
| 661 | << ": Channel pointer not found in configuration()->channels()"; |
| 662 | |
| 663 | return std::distance(configuration->channels()->begin(), c); |
| 664 | } |
| 665 | |
Austin Schuh | bca6cf0 | 2019-12-22 17:28:34 -0800 | [diff] [blame] | 666 | std::string CleanedChannelToString(const Channel *channel) { |
| 667 | FlatbufferDetachedBuffer<Channel> cleaned_channel = CopyFlatBuffer(channel); |
| 668 | cleaned_channel.mutable_message()->clear_schema(); |
| 669 | return FlatbufferToJson(cleaned_channel); |
| 670 | } |
| 671 | |
Austin Schuh | a81454b | 2020-05-12 19:58:36 -0700 | [diff] [blame] | 672 | std::string StrippedChannelToString(const Channel *channel) { |
| 673 | return absl::StrCat("{ \"name\": \"", channel->name()->string_view(), |
| 674 | "\", \"type\": \"", channel->type()->string_view(), |
| 675 | "\" }"); |
| 676 | } |
| 677 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 678 | FlatbufferDetachedBuffer<Configuration> MergeConfiguration( |
| 679 | const Flatbuffer<Configuration> &config, |
| 680 | const std::vector<aos::FlatbufferString<reflection::Schema>> &schemas) { |
| 681 | flatbuffers::FlatBufferBuilder fbb; |
Austin Schuh | d7b15da | 2020-02-17 15:06:11 -0800 | [diff] [blame] | 682 | fbb.ForceDefaults(true); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 683 | |
James Kuszmaul | 3c99859 | 2020-07-27 21:04:47 -0700 | [diff] [blame] | 684 | // auto_merge_config will contain all the fields of the Configuration that are |
| 685 | // to be passed through unmodified to the result of MergeConfiguration(). |
| 686 | // In the processing below, we mutate auto_merge_config to remove any fields |
| 687 | // which we do need to alter (hence why we can't use the input config |
| 688 | // directly), and then merge auto_merge_config back in at the end. |
| 689 | aos::FlatbufferDetachedBuffer<aos::Configuration> auto_merge_config = |
| 690 | aos::CopyFlatBuffer(&config.message()); |
| 691 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 692 | flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Channel>>> |
| 693 | channels_offset; |
| 694 | if (config.message().has_channels()) { |
James Kuszmaul | 3c99859 | 2020-07-27 21:04:47 -0700 | [diff] [blame] | 695 | auto_merge_config.mutable_message()->clear_channels(); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 696 | std::vector<flatbuffers::Offset<Channel>> channel_offsets; |
| 697 | for (const Channel *c : *config.message().channels()) { |
| 698 | flatbuffers::FlatBufferBuilder channel_fbb; |
Austin Schuh | d7b15da | 2020-02-17 15:06:11 -0800 | [diff] [blame] | 699 | channel_fbb.ForceDefaults(true); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 700 | |
| 701 | // Search for a schema with a matching type. |
| 702 | const aos::FlatbufferString<reflection::Schema> *found_schema = nullptr; |
Austin Schuh | f1fff28 | 2020-03-28 16:57:32 -0700 | [diff] [blame] | 703 | for (const aos::FlatbufferString<reflection::Schema> &schema : schemas) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 704 | if (schema.message().root_table() != nullptr) { |
| 705 | if (schema.message().root_table()->name()->string_view() == |
| 706 | c->type()->string_view()) { |
| 707 | found_schema = &schema; |
| 708 | } |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | CHECK(found_schema != nullptr) |
| 713 | << ": Failed to find schema for " << FlatbufferToJson(c); |
| 714 | |
| 715 | // The following is wasteful, but works. |
| 716 | // |
| 717 | // Copy it into a Channel object by creating an object with only the |
| 718 | // schema populated and merge that into the current channel. |
| 719 | flatbuffers::Offset<reflection::Schema> schema_offset = |
| 720 | CopyFlatBuffer<reflection::Schema>(&found_schema->message(), |
| 721 | &channel_fbb); |
| 722 | Channel::Builder channel_builder(channel_fbb); |
| 723 | channel_builder.add_schema(schema_offset); |
| 724 | channel_fbb.Finish(channel_builder.Finish()); |
| 725 | FlatbufferDetachedBuffer<Channel> channel_schema_flatbuffer( |
| 726 | channel_fbb.Release()); |
| 727 | |
| 728 | FlatbufferDetachedBuffer<Channel> merged_channel( |
| 729 | MergeFlatBuffers(channel_schema_flatbuffer, CopyFlatBuffer(c))); |
| 730 | |
| 731 | channel_offsets.emplace_back( |
| 732 | CopyFlatBuffer<Channel>(&merged_channel.message(), &fbb)); |
| 733 | } |
| 734 | channels_offset = fbb.CreateVector(channel_offsets); |
| 735 | } |
| 736 | |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 737 | |
| 738 | // Now insert everything else in unmodified. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 739 | ConfigurationBuilder configuration_builder(fbb); |
| 740 | if (config.message().has_channels()) { |
| 741 | configuration_builder.add_channels(channels_offset); |
| 742 | } |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 743 | fbb.Finish(configuration_builder.Finish()); |
James Kuszmaul | 3c99859 | 2020-07-27 21:04:47 -0700 | [diff] [blame] | 744 | aos::FlatbufferDetachedBuffer<aos::Configuration> modified_config( |
| 745 | fbb.Release()); |
| 746 | |
| 747 | return MergeFlatBuffers(modified_config, auto_merge_config); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 748 | } |
| 749 | |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 750 | const Node *GetNodeFromHostname(const Configuration *config, |
| 751 | std::string_view hostname) { |
| 752 | for (const Node *node : *config->nodes()) { |
Brian Silverman | aa2633f | 2020-02-17 21:04:14 -0800 | [diff] [blame] | 753 | if (node->has_hostname() && node->hostname()->string_view() == hostname) { |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 754 | return node; |
| 755 | } |
Brian Silverman | aa2633f | 2020-02-17 21:04:14 -0800 | [diff] [blame] | 756 | if (node->has_hostnames()) { |
| 757 | for (const auto &candidate : *node->hostnames()) { |
| 758 | if (candidate->string_view() == hostname) { |
| 759 | return node; |
| 760 | } |
| 761 | } |
| 762 | } |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 763 | } |
| 764 | return nullptr; |
| 765 | } |
Austin Schuh | ac0771c | 2020-01-07 18:36:30 -0800 | [diff] [blame] | 766 | |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 767 | const Node *GetMyNode(const Configuration *config) { |
| 768 | const std::string hostname = (FLAGS_override_hostname.size() > 0) |
| 769 | ? FLAGS_override_hostname |
| 770 | : network::GetHostname(); |
| 771 | const Node *node = GetNodeFromHostname(config, hostname); |
| 772 | if (node != nullptr) return node; |
| 773 | |
| 774 | LOG(FATAL) << "Unknown node for host: " << hostname |
| 775 | << ". Consider using --override_hostname if hostname detection " |
| 776 | "is wrong."; |
| 777 | return nullptr; |
| 778 | } |
| 779 | |
Austin Schuh | c9e10ec | 2020-01-26 16:08:28 -0800 | [diff] [blame] | 780 | const Node *GetNode(const Configuration *config, const Node *node) { |
| 781 | if (!MultiNode(config)) { |
| 782 | CHECK(node == nullptr) << ": Provided a node in a single node world."; |
| 783 | return nullptr; |
| 784 | } else { |
| 785 | CHECK(node != nullptr); |
| 786 | CHECK(node->has_name()); |
| 787 | return GetNode(config, node->name()->string_view()); |
| 788 | } |
| 789 | } |
| 790 | |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 791 | const Node *GetNode(const Configuration *config, std::string_view name) { |
Austin Schuh | fd96062 | 2020-01-01 13:22:55 -0800 | [diff] [blame] | 792 | CHECK(config->has_nodes()) |
| 793 | << ": Asking for a node from a single node configuration."; |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 794 | for (const Node *node : *config->nodes()) { |
Austin Schuh | fd96062 | 2020-01-01 13:22:55 -0800 | [diff] [blame] | 795 | CHECK(node->has_name()) << ": Malformed node " << FlatbufferToJson(node); |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 796 | if (node->name()->string_view() == name) { |
| 797 | return node; |
| 798 | } |
| 799 | } |
| 800 | return nullptr; |
| 801 | } |
| 802 | |
Austin Schuh | c9e10ec | 2020-01-26 16:08:28 -0800 | [diff] [blame] | 803 | const Node *GetNodeOrDie(const Configuration *config, const Node *node) { |
| 804 | if (!MultiNode(config)) { |
| 805 | CHECK(node == nullptr) << ": Provided a node in a single node world."; |
| 806 | return nullptr; |
| 807 | } else { |
| 808 | const Node *config_node = GetNode(config, node); |
| 809 | if (config_node == nullptr) { |
| 810 | LOG(FATAL) << "Couldn't find node matching " << FlatbufferToJson(node); |
| 811 | } |
| 812 | return config_node; |
| 813 | } |
| 814 | } |
| 815 | |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 816 | namespace { |
| 817 | int GetNodeIndexFromConfig(const Configuration *config, const Node *node) { |
Austin Schuh | c9e10ec | 2020-01-26 16:08:28 -0800 | [diff] [blame] | 818 | int node_index = 0; |
| 819 | for (const Node *iterated_node : *config->nodes()) { |
| 820 | if (iterated_node == node) { |
| 821 | return node_index; |
| 822 | } |
| 823 | ++node_index; |
| 824 | } |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 825 | return -1; |
| 826 | } |
| 827 | } // namespace |
| 828 | |
| 829 | int GetNodeIndex(const Configuration *config, const Node *node) { |
| 830 | if (!MultiNode(config)) { |
| 831 | return 0; |
| 832 | } |
| 833 | |
| 834 | { |
| 835 | int node_index = GetNodeIndexFromConfig(config, node); |
| 836 | if (node_index != -1) { |
| 837 | return node_index; |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | const Node *result = GetNode(config, node); |
| 842 | CHECK(result != nullptr); |
| 843 | |
| 844 | { |
Austin Schuh | 04408fc | 2020-02-16 21:48:54 -0800 | [diff] [blame] | 845 | int node_index = GetNodeIndexFromConfig(config, result); |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 846 | if (node_index != -1) { |
| 847 | return node_index; |
| 848 | } |
| 849 | } |
| 850 | |
| 851 | LOG(FATAL) << "Node " << FlatbufferToJson(node) |
| 852 | << " not found in the configuration."; |
Austin Schuh | c9e10ec | 2020-01-26 16:08:28 -0800 | [diff] [blame] | 853 | } |
| 854 | |
Austin Schuh | 04408fc | 2020-02-16 21:48:54 -0800 | [diff] [blame] | 855 | int GetNodeIndex(const Configuration *config, std::string_view name) { |
| 856 | if (!MultiNode(config)) { |
| 857 | return 0; |
| 858 | } |
| 859 | |
| 860 | { |
| 861 | int node_index = 0; |
| 862 | for (const Node *iterated_node : *config->nodes()) { |
| 863 | if (iterated_node->name()->string_view() == name) { |
| 864 | return node_index; |
| 865 | } |
| 866 | ++node_index; |
| 867 | } |
| 868 | } |
| 869 | LOG(FATAL) << "Node " << name << " not found in the configuration."; |
| 870 | } |
| 871 | |
Austin Schuh | c9e10ec | 2020-01-26 16:08:28 -0800 | [diff] [blame] | 872 | std::vector<const Node *> GetNodes(const Configuration *config) { |
| 873 | std::vector<const Node *> nodes; |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 874 | if (MultiNode(config)) { |
Austin Schuh | c9e10ec | 2020-01-26 16:08:28 -0800 | [diff] [blame] | 875 | for (const Node *node : *config->nodes()) { |
| 876 | nodes.emplace_back(node); |
| 877 | } |
| 878 | } else { |
| 879 | nodes.emplace_back(nullptr); |
| 880 | } |
| 881 | return nodes; |
| 882 | } |
| 883 | |
Austin Schuh | ac0771c | 2020-01-07 18:36:30 -0800 | [diff] [blame] | 884 | bool MultiNode(const Configuration *config) { return config->has_nodes(); } |
| 885 | |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 886 | bool ChannelIsSendableOnNode(const Channel *channel, const Node *node) { |
Austin Schuh | ca4828c | 2019-12-28 14:21:35 -0800 | [diff] [blame] | 887 | if (node == nullptr) { |
| 888 | return true; |
| 889 | } |
Austin Schuh | 3c5dae5 | 2020-10-06 18:55:18 -0700 | [diff] [blame] | 890 | CHECK(channel->has_source_node()) << FlatbufferToJson(channel); |
| 891 | CHECK(node->has_name()) << FlatbufferToJson(node); |
Austin Schuh | 196a445 | 2020-03-15 23:12:03 -0700 | [diff] [blame] | 892 | return (CHECK_NOTNULL(channel)->source_node()->string_view() == |
| 893 | node->name()->string_view()); |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | bool ChannelIsReadableOnNode(const Channel *channel, const Node *node) { |
Austin Schuh | ca4828c | 2019-12-28 14:21:35 -0800 | [diff] [blame] | 897 | if (node == nullptr) { |
| 898 | return true; |
| 899 | } |
| 900 | |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 901 | if (channel->source_node()->string_view() == node->name()->string_view()) { |
| 902 | return true; |
| 903 | } |
| 904 | |
| 905 | if (!channel->has_destination_nodes()) { |
| 906 | return false; |
| 907 | } |
| 908 | |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 909 | for (const Connection *connection : *channel->destination_nodes()) { |
| 910 | CHECK(connection->has_name()); |
| 911 | if (connection->name()->string_view() == node->name()->string_view()) { |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 912 | return true; |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | return false; |
| 917 | } |
| 918 | |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 919 | bool ChannelMessageIsLoggedOnNode(const Channel *channel, const Node *node) { |
Austin Schuh | f1fff28 | 2020-03-28 16:57:32 -0700 | [diff] [blame] | 920 | switch (channel->logger()) { |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 921 | case LoggerConfig::LOCAL_LOGGER: |
| 922 | if (node == nullptr) { |
| 923 | // Single node world. If there is a local logger, then we want to use |
| 924 | // it. |
| 925 | return true; |
| 926 | } |
| 927 | return channel->source_node()->string_view() == |
| 928 | node->name()->string_view(); |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 929 | case LoggerConfig::LOCAL_AND_REMOTE_LOGGER: |
Austin Schuh | da40e47 | 2020-03-28 15:15:29 -0700 | [diff] [blame] | 930 | CHECK(channel->has_logger_nodes()); |
| 931 | CHECK_GT(channel->logger_nodes()->size(), 0u); |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 932 | |
| 933 | if (channel->source_node()->string_view() == |
| 934 | CHECK_NOTNULL(node)->name()->string_view()) { |
| 935 | return true; |
| 936 | } |
Austin Schuh | da40e47 | 2020-03-28 15:15:29 -0700 | [diff] [blame] | 937 | |
| 938 | [[fallthrough]]; |
| 939 | case LoggerConfig::REMOTE_LOGGER: |
| 940 | CHECK(channel->has_logger_nodes()); |
| 941 | CHECK_GT(channel->logger_nodes()->size(), 0u); |
| 942 | for (const flatbuffers::String *logger_node : *channel->logger_nodes()) { |
| 943 | if (logger_node->string_view() == |
| 944 | CHECK_NOTNULL(node)->name()->string_view()) { |
| 945 | return true; |
| 946 | } |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | return false; |
| 950 | case LoggerConfig::NOT_LOGGED: |
| 951 | return false; |
| 952 | } |
| 953 | |
| 954 | LOG(FATAL) << "Unknown logger config " << static_cast<int>(channel->logger()); |
| 955 | } |
| 956 | |
| 957 | const Connection *ConnectionToNode(const Channel *channel, const Node *node) { |
| 958 | if (!channel->has_destination_nodes()) { |
| 959 | return nullptr; |
| 960 | } |
| 961 | for (const Connection *connection : *channel->destination_nodes()) { |
| 962 | if (connection->name()->string_view() == node->name()->string_view()) { |
| 963 | return connection; |
| 964 | } |
| 965 | } |
| 966 | return nullptr; |
| 967 | } |
| 968 | |
| 969 | bool ConnectionDeliveryTimeIsLoggedOnNode(const Channel *channel, |
| 970 | const Node *node, |
| 971 | const Node *logger_node) { |
| 972 | const Connection *connection = ConnectionToNode(channel, node); |
| 973 | if (connection == nullptr) { |
| 974 | return false; |
| 975 | } |
| 976 | return ConnectionDeliveryTimeIsLoggedOnNode(connection, logger_node); |
| 977 | } |
| 978 | |
| 979 | bool ConnectionDeliveryTimeIsLoggedOnNode(const Connection *connection, |
| 980 | const Node *node) { |
| 981 | switch (connection->timestamp_logger()) { |
| 982 | case LoggerConfig::LOCAL_AND_REMOTE_LOGGER: |
Austin Schuh | da40e47 | 2020-03-28 15:15:29 -0700 | [diff] [blame] | 983 | CHECK(connection->has_timestamp_logger_nodes()); |
| 984 | CHECK_GT(connection->timestamp_logger_nodes()->size(), 0u); |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 985 | if (connection->name()->string_view() == node->name()->string_view()) { |
| 986 | return true; |
| 987 | } |
| 988 | |
Austin Schuh | da40e47 | 2020-03-28 15:15:29 -0700 | [diff] [blame] | 989 | [[fallthrough]]; |
| 990 | case LoggerConfig::REMOTE_LOGGER: |
| 991 | CHECK(connection->has_timestamp_logger_nodes()); |
| 992 | CHECK_GT(connection->timestamp_logger_nodes()->size(), 0u); |
| 993 | for (const flatbuffers::String *timestamp_logger_node : |
| 994 | *connection->timestamp_logger_nodes()) { |
| 995 | if (timestamp_logger_node->string_view() == |
| 996 | node->name()->string_view()) { |
| 997 | return true; |
| 998 | } |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | return false; |
| 1002 | case LoggerConfig::LOCAL_LOGGER: |
| 1003 | return connection->name()->string_view() == node->name()->string_view(); |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 1004 | case LoggerConfig::NOT_LOGGED: |
| 1005 | return false; |
| 1006 | } |
| 1007 | |
| 1008 | LOG(FATAL) << "Unknown logger config " |
| 1009 | << static_cast<int>(connection->timestamp_logger()); |
| 1010 | } |
| 1011 | |
Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 1012 | std::vector<std::string_view> SourceNodeNames(const Configuration *config, |
| 1013 | const Node *my_node) { |
| 1014 | std::set<std::string_view> result_set; |
| 1015 | |
| 1016 | for (const Channel *channel : *config->channels()) { |
| 1017 | if (channel->has_destination_nodes()) { |
| 1018 | for (const Connection *connection : *channel->destination_nodes()) { |
| 1019 | if (connection->name()->string_view() == |
| 1020 | my_node->name()->string_view()) { |
| 1021 | result_set.insert(channel->source_node()->string_view()); |
| 1022 | } |
| 1023 | } |
| 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | std::vector<std::string_view> result; |
| 1028 | for (const std::string_view source : result_set) { |
| 1029 | VLOG(1) << "Found a source node of " << source; |
| 1030 | result.emplace_back(source); |
| 1031 | } |
| 1032 | return result; |
| 1033 | } |
| 1034 | |
| 1035 | std::vector<std::string_view> DestinationNodeNames(const Configuration *config, |
| 1036 | const Node *my_node) { |
| 1037 | std::vector<std::string_view> result; |
| 1038 | |
| 1039 | for (const Channel *channel : *config->channels()) { |
| 1040 | if (channel->has_source_node() && channel->source_node()->string_view() == |
| 1041 | my_node->name()->string_view()) { |
| 1042 | if (!channel->has_destination_nodes()) continue; |
| 1043 | |
| 1044 | if (channel->source_node()->string_view() != |
| 1045 | my_node->name()->string_view()) { |
| 1046 | continue; |
| 1047 | } |
| 1048 | |
| 1049 | for (const Connection *connection : *channel->destination_nodes()) { |
| 1050 | if (std::find(result.begin(), result.end(), |
| 1051 | connection->name()->string_view()) == result.end()) { |
| 1052 | result.emplace_back(connection->name()->string_view()); |
| 1053 | } |
| 1054 | } |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | for (const std::string_view destination : result) { |
| 1059 | VLOG(1) << "Found a destination node of " << destination; |
| 1060 | } |
| 1061 | return result; |
| 1062 | } |
| 1063 | |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1064 | std::vector<const Node *> TimestampNodes(const Configuration *config, |
| 1065 | const Node *my_node) { |
| 1066 | if (!configuration::MultiNode(config)) { |
| 1067 | CHECK(my_node == nullptr); |
| 1068 | return std::vector<const Node *>{}; |
| 1069 | } |
| 1070 | |
| 1071 | std::set<const Node *> timestamp_logger_nodes; |
| 1072 | for (const Channel *channel : *config->channels()) { |
| 1073 | if (!configuration::ChannelIsSendableOnNode(channel, my_node)) { |
| 1074 | continue; |
| 1075 | } |
| 1076 | if (!channel->has_destination_nodes()) { |
| 1077 | continue; |
| 1078 | } |
| 1079 | for (const Connection *connection : *channel->destination_nodes()) { |
| 1080 | const Node *other_node = |
| 1081 | configuration::GetNode(config, connection->name()->string_view()); |
| 1082 | |
| 1083 | if (configuration::ConnectionDeliveryTimeIsLoggedOnNode(connection, |
| 1084 | my_node)) { |
| 1085 | VLOG(1) << "Timestamps are logged from " |
| 1086 | << FlatbufferToJson(other_node); |
| 1087 | timestamp_logger_nodes.insert(other_node); |
| 1088 | } |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | std::vector<const Node *> result; |
| 1093 | for (const Node *node : timestamp_logger_nodes) { |
| 1094 | result.emplace_back(node); |
| 1095 | } |
| 1096 | return result; |
| 1097 | } |
| 1098 | |
Brian Silverman | 66f079a | 2013-08-26 16:24:30 -0700 | [diff] [blame] | 1099 | } // namespace configuration |
| 1100 | } // namespace aos |