blob: 834ab5ba0c7ecefb339a938752cbf110af0a0dfc [file] [log] [blame]
John Park398c74a2018-10-20 21:17:39 -07001#include "aos/configuration.h"
Brian Silverman66f079a2013-08-26 16:24:30 -07002
Brian Silverman66f079a2013-08-26 16:24:30 -07003#include <arpa/inet.h>
4#include <ifaddrs.h>
Austin Schuhf1fff282020-03-28 16:57:32 -07005#include <netinet/in.h>
6#include <stdlib.h>
7#include <string.h>
8#include <sys/types.h>
Brian Silverman66f079a2013-08-26 16:24:30 -07009#include <unistd.h>
Austin Schuhe84c3ed2019-12-14 15:29:48 -080010
11#include <set>
James Kuszmaul3ae42262019-11-08 12:33:41 -080012#include <string_view>
Brian Silverman66f079a2013-08-26 16:24:30 -070013
Austin Schuhcb108412019-10-13 16:09:54 -070014#include "absl/container/btree_set.h"
Austin Schuha81454b2020-05-12 19:58:36 -070015#include "absl/strings/str_cat.h"
Austin Schuhcb108412019-10-13 16:09:54 -070016#include "aos/configuration_generated.h"
17#include "aos/flatbuffer_merge.h"
18#include "aos/json_to_flatbuffer.h"
Austin Schuh217a9782019-12-21 23:02:50 -080019#include "aos/network/team_number.h"
Austin Schuhcb108412019-10-13 16:09:54 -070020#include "aos/unique_malloc_ptr.h"
21#include "aos/util/file.h"
Austin Schuh217a9782019-12-21 23:02:50 -080022#include "gflags/gflags.h"
Austin Schuhcb108412019-10-13 16:09:54 -070023#include "glog/logging.h"
Austin Schuh217a9782019-12-21 23:02:50 -080024
Brian Silverman66f079a2013-08-26 16:24:30 -070025namespace aos {
Austin Schuhcb108412019-10-13 16:09:54 -070026
Austin Schuh40485ed2019-10-26 21:51:44 -070027// Define the compare and equal operators for Channel and Application so we can
Austin Schuhcb108412019-10-13 16:09:54 -070028// insert them in the btree below.
Austin Schuh40485ed2019-10-26 21:51:44 -070029bool operator<(const FlatbufferDetachedBuffer<Channel> &lhs,
30 const FlatbufferDetachedBuffer<Channel> &rhs) {
Austin Schuhcb108412019-10-13 16:09:54 -070031 int name_compare = lhs.message().name()->string_view().compare(
32 rhs.message().name()->string_view());
33 if (name_compare == 0) {
34 return lhs.message().type()->string_view() <
35 rhs.message().type()->string_view();
36 } else if (name_compare < 0) {
37 return true;
38 } else {
39 return false;
40 }
41}
42
Austin Schuh40485ed2019-10-26 21:51:44 -070043bool operator==(const FlatbufferDetachedBuffer<Channel> &lhs,
44 const FlatbufferDetachedBuffer<Channel> &rhs) {
Austin Schuhcb108412019-10-13 16:09:54 -070045 return lhs.message().name()->string_view() ==
46 rhs.message().name()->string_view() &&
47 lhs.message().type()->string_view() ==
48 rhs.message().type()->string_view();
49}
50
Austin Schuh40485ed2019-10-26 21:51:44 -070051bool operator==(const FlatbufferDetachedBuffer<Application> &lhs,
52 const FlatbufferDetachedBuffer<Application> &rhs) {
Austin Schuhcb108412019-10-13 16:09:54 -070053 return lhs.message().name()->string_view() ==
54 rhs.message().name()->string_view();
55}
56
Austin Schuh40485ed2019-10-26 21:51:44 -070057bool operator<(const FlatbufferDetachedBuffer<Application> &lhs,
58 const FlatbufferDetachedBuffer<Application> &rhs) {
Austin Schuhcb108412019-10-13 16:09:54 -070059 return lhs.message().name()->string_view() <
60 rhs.message().name()->string_view();
61}
62
Austin Schuh217a9782019-12-21 23:02:50 -080063bool operator==(const FlatbufferDetachedBuffer<Node> &lhs,
64 const FlatbufferDetachedBuffer<Node> &rhs) {
65 return lhs.message().name()->string_view() ==
66 rhs.message().name()->string_view();
67}
68
69bool operator<(const FlatbufferDetachedBuffer<Node> &lhs,
70 const FlatbufferDetachedBuffer<Node> &rhs) {
71 return lhs.message().name()->string_view() <
72 rhs.message().name()->string_view();
73}
74
Brian Silverman66f079a2013-08-26 16:24:30 -070075namespace configuration {
76namespace {
77
Austin Schuhcb108412019-10-13 16:09:54 -070078// Extracts the folder part of a path. Returns ./ if there is no path.
Austin Schuhf1fff282020-03-28 16:57:32 -070079std::string_view ExtractFolder(const std::string_view filename) {
Austin Schuhcb108412019-10-13 16:09:54 -070080 auto last_slash_pos = filename.find_last_of("/\\");
81
James Kuszmaul3ae42262019-11-08 12:33:41 -080082 return last_slash_pos == std::string_view::npos
83 ? std::string_view("./")
Austin Schuhcb108412019-10-13 16:09:54 -070084 : filename.substr(0, last_slash_pos + 1);
85}
86
James Kuszmaulc0c08da2020-05-10 18:56:07 -070087std::string AbsolutePath(const std::string_view filename) {
88 // Uses an std::string so that we know the input will be null-terminated.
89 const std::string terminated_file(filename);
90 char buffer[PATH_MAX];
91 PCHECK(NULL != realpath(terminated_file.c_str(), buffer));
92 return buffer;
93}
94
Austin Schuh40485ed2019-10-26 21:51:44 -070095FlatbufferDetachedBuffer<Configuration> ReadConfig(
James Kuszmaulc0c08da2020-05-10 18:56:07 -070096 const std::string_view path, absl::btree_set<std::string> *visited_paths,
97 const std::vector<std::string_view> &extra_import_paths) {
98 std::string raw_path(path);
99 if (!util::PathExists(path)) {
100 const bool path_is_absolute = path.size() > 0 && path[0] == '/';
101 if (path_is_absolute) {
102 CHECK(extra_import_paths.empty())
103 << "Can't specify extra import paths if attempting to read a config "
104 "file from an absolute path (path is "
105 << path << ").";
106 }
107
108 bool found_path = false;
109 for (const auto &import_path : extra_import_paths) {
110 raw_path = std::string(import_path) + "/" + std::string(path);
111 if (util::PathExists(raw_path)) {
112 found_path = true;
113 break;
114 }
115 }
116 CHECK(found_path) << ": Failed to find file " << path << ".";
117 }
Alex Perrycb7da4b2019-08-28 19:35:56 -0700118 flatbuffers::DetachedBuffer buffer = JsonToFlatbuffer(
James Kuszmaulc0c08da2020-05-10 18:56:07 -0700119 util::ReadFileToStringOrDie(raw_path), ConfigurationTypeTable());
Alex Perrycb7da4b2019-08-28 19:35:56 -0700120
121 CHECK_GT(buffer.size(), 0u) << ": Failed to parse JSON file";
122
123 FlatbufferDetachedBuffer<Configuration> config(std::move(buffer));
James Kuszmaulc0c08da2020-05-10 18:56:07 -0700124
Austin Schuhcb108412019-10-13 16:09:54 -0700125 // Depth first. Take the following example:
126 //
127 // config1.json:
128 // {
Austin Schuh40485ed2019-10-26 21:51:44 -0700129 // "channels": [
Austin Schuhcb108412019-10-13 16:09:54 -0700130 // {
131 // "name": "/foo",
132 // "type": ".aos.bar",
133 // "max_size": 5
134 // }
135 // ],
136 // "imports": [
137 // "config2.json",
138 // ]
139 // }
140 //
141 // config2.json:
142 // {
Austin Schuh40485ed2019-10-26 21:51:44 -0700143 // "channels": [
Austin Schuhcb108412019-10-13 16:09:54 -0700144 // {
145 // "name": "/foo",
146 // "type": ".aos.bar",
147 // "max_size": 7
148 // }
149 // ],
150 // }
151 //
152 // We want the main config (config1.json) to be able to override the imported
153 // config. That means that it needs to be merged into the imported configs,
154 // not the other way around.
155
James Kuszmaulc0c08da2020-05-10 18:56:07 -0700156 const std::string absolute_path = AbsolutePath(raw_path);
Austin Schuhcb108412019-10-13 16:09:54 -0700157 // Track that we have seen this file before recursing.
James Kuszmaulc0c08da2020-05-10 18:56:07 -0700158 if (!visited_paths->insert(absolute_path).second) {
159 for (const auto &visited_path : *visited_paths) {
160 LOG(INFO) << "Already visited: " << visited_path;
161 }
162 LOG(FATAL)
163 << "Already imported " << path << " (i.e. " << absolute_path
164 << "). See above for the files that have already been processed.";
165 }
Austin Schuhcb108412019-10-13 16:09:54 -0700166
167 if (config.message().has_imports()) {
168 // Capture the imports.
169 const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *v =
170 config.message().imports();
171
172 // And then wipe them. This gets GCed when we merge later.
173 config.mutable_message()->clear_imports();
174
175 // Start with an empty configuration to merge into.
Austin Schuh40485ed2019-10-26 21:51:44 -0700176 FlatbufferDetachedBuffer<Configuration> merged_config =
177 FlatbufferDetachedBuffer<Configuration>::Empty();
Austin Schuhcb108412019-10-13 16:09:54 -0700178
James Kuszmaulc0c08da2020-05-10 18:56:07 -0700179 const std::string path_folder(ExtractFolder(path));
Austin Schuhcb108412019-10-13 16:09:54 -0700180 for (const flatbuffers::String *str : *v) {
James Kuszmaulc0c08da2020-05-10 18:56:07 -0700181 const std::string included_config =
182 path_folder + "/" + std::string(str->string_view());
Austin Schuhcb108412019-10-13 16:09:54 -0700183
184 // And them merge everything in.
185 merged_config = MergeFlatBuffers(
James Kuszmaulc0c08da2020-05-10 18:56:07 -0700186 merged_config,
187 ReadConfig(included_config, visited_paths, extra_import_paths));
Austin Schuhcb108412019-10-13 16:09:54 -0700188 }
189
190 // Finally, merge this file in.
191 config = MergeFlatBuffers(merged_config, config);
192 }
193 return config;
194}
195
Alex Perrycb7da4b2019-08-28 19:35:56 -0700196// Compares (c < p) a channel, and a name, type tuple.
197bool CompareChannels(const Channel *c,
James Kuszmaul3ae42262019-11-08 12:33:41 -0800198 ::std::pair<std::string_view, std::string_view> p) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700199 int name_compare = c->name()->string_view().compare(p.first);
200 if (name_compare == 0) {
201 return c->type()->string_view() < p.second;
202 } else if (name_compare < 0) {
203 return true;
204 } else {
205 return false;
206 }
207};
208
209// Compares for equality (c == p) a channel, and a name, type tuple.
210bool EqualsChannels(const Channel *c,
Austin Schuhf1fff282020-03-28 16:57:32 -0700211 ::std::pair<std::string_view, std::string_view> p) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700212 return c->name()->string_view() == p.first &&
213 c->type()->string_view() == p.second;
214}
215
216// Compares (c < p) an application, and a name;
James Kuszmaul3ae42262019-11-08 12:33:41 -0800217bool CompareApplications(const Application *a, std::string_view name) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700218 return a->name()->string_view() < name;
219};
220
221// Compares for equality (c == p) an application, and a name;
James Kuszmaul3ae42262019-11-08 12:33:41 -0800222bool EqualsApplications(const Application *a, std::string_view name) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700223 return a->name()->string_view() == name;
224}
225
226// Maps name for the provided maps. Modifies name.
227void HandleMaps(const flatbuffers::Vector<flatbuffers::Offset<aos::Map>> *maps,
Austin Schuhf1fff282020-03-28 16:57:32 -0700228 std::string *name, std::string_view type, const Node *node) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700229 // For the same reason we merge configs in reverse order, we want to process
230 // maps in reverse order. That lets the outer config overwrite channels from
231 // the inner configs.
232 for (auto i = maps->rbegin(); i != maps->rend(); ++i) {
Austin Schuhbca6cf02019-12-22 17:28:34 -0800233 if (!i->has_match() || !i->match()->has_name()) {
234 continue;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700235 }
Austin Schuhbca6cf02019-12-22 17:28:34 -0800236 if (!i->has_rename() || !i->rename()->has_name()) {
237 continue;
238 }
239
240 // Handle normal maps (now that we know that match and rename are filled
241 // out).
Austin Schuhf1fff282020-03-28 16:57:32 -0700242 const std::string_view match_name = i->match()->name()->string_view();
243 if (match_name != *name) {
244 if (match_name.back() == '*' &&
245 std::string_view(*name).substr(
246 0, std::min(name->size(), match_name.size() - 1)) ==
247 match_name.substr(0, match_name.size() - 1)) {
248 CHECK_EQ(match_name.find('*'), match_name.size() - 1);
249 } else {
250 continue;
251 }
Austin Schuhbca6cf02019-12-22 17:28:34 -0800252 }
253
254 // Handle type specific maps.
255 if (i->match()->has_type() && i->match()->type()->string_view() != type) {
256 continue;
257 }
258
Austin Schuhf1fff282020-03-28 16:57:32 -0700259 // Now handle node specific maps.
Austin Schuhbca6cf02019-12-22 17:28:34 -0800260 if (node != nullptr && i->match()->has_source_node() &&
261 i->match()->source_node()->string_view() !=
262 node->name()->string_view()) {
263 continue;
264 }
265
Austin Schuhf1fff282020-03-28 16:57:32 -0700266 std::string new_name(i->rename()->name()->string_view());
267 if (match_name.back() == '*') {
268 new_name += std::string(name->substr(match_name.size() - 1));
269 }
270 VLOG(1) << "Renamed \"" << *name << "\" to \"" << new_name << "\"";
271 *name = std::move(new_name);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700272 }
273}
274
275} // namespace
276
Austin Schuh40485ed2019-10-26 21:51:44 -0700277FlatbufferDetachedBuffer<Configuration> MergeConfiguration(
Austin Schuhcb108412019-10-13 16:09:54 -0700278 const Flatbuffer<Configuration> &config) {
James Kuszmaul3c998592020-07-27 21:04:47 -0700279 // auto_merge_config will contain all the fields of the Configuration that are
280 // to be passed through unmodified to the result of MergeConfiguration().
281 // In the processing below, we mutate auto_merge_config to remove any fields
282 // which we do need to alter (hence why we can't use the input config
283 // directly), and then merge auto_merge_config back in at the end.
284 aos::FlatbufferDetachedBuffer<aos::Configuration> auto_merge_config =
285 aos::CopyFlatBuffer(&config.message());
286
Austin Schuh40485ed2019-10-26 21:51:44 -0700287 // Store all the channels in a sorted set. This lets us track channels we
Austin Schuhcb108412019-10-13 16:09:54 -0700288 // have seen before and merge the updates in.
Austin Schuh40485ed2019-10-26 21:51:44 -0700289 absl::btree_set<FlatbufferDetachedBuffer<Channel>> channels;
Austin Schuhcb108412019-10-13 16:09:54 -0700290
Austin Schuh40485ed2019-10-26 21:51:44 -0700291 if (config.message().has_channels()) {
James Kuszmaul3c998592020-07-27 21:04:47 -0700292 auto_merge_config.mutable_message()->clear_channels();
Austin Schuh40485ed2019-10-26 21:51:44 -0700293 for (const Channel *c : *config.message().channels()) {
Austin Schuhcb108412019-10-13 16:09:54 -0700294 // Ignore malformed entries.
Austin Schuh40485ed2019-10-26 21:51:44 -0700295 if (!c->has_name()) {
Austin Schuhcb108412019-10-13 16:09:54 -0700296 continue;
297 }
Austin Schuh40485ed2019-10-26 21:51:44 -0700298 if (!c->has_type()) {
Austin Schuhcb108412019-10-13 16:09:54 -0700299 continue;
300 }
301
Brian Silverman77162972020-08-12 19:52:40 -0700302 CHECK_EQ(c->read_method() == ReadMethod::PIN, c->num_readers() != 0)
303 << ": num_readers may be set if and only if read_method is PIN,"
304 " if you want 0 readers do not set PIN: "
305 << CleanedChannelToString(c);
306
Austin Schuh40485ed2019-10-26 21:51:44 -0700307 // Attempt to insert the channel.
308 auto result = channels.insert(CopyFlatBuffer(c));
Austin Schuhcb108412019-10-13 16:09:54 -0700309 if (!result.second) {
310 // Already there, so merge the new table into the original.
Austin Schuh40485ed2019-10-26 21:51:44 -0700311 *result.first = MergeFlatBuffers(*result.first, CopyFlatBuffer(c));
Austin Schuhcb108412019-10-13 16:09:54 -0700312 }
313 }
314 }
315
316 // Now repeat this for the application list.
Austin Schuh40485ed2019-10-26 21:51:44 -0700317 absl::btree_set<FlatbufferDetachedBuffer<Application>> applications;
Austin Schuhcb108412019-10-13 16:09:54 -0700318 if (config.message().has_applications()) {
James Kuszmaul3c998592020-07-27 21:04:47 -0700319 auto_merge_config.mutable_message()->clear_applications();
Austin Schuhcb108412019-10-13 16:09:54 -0700320 for (const Application *a : *config.message().applications()) {
321 if (!a->has_name()) {
322 continue;
323 }
324
325 auto result = applications.insert(CopyFlatBuffer(a));
326 if (!result.second) {
327 *result.first = MergeFlatBuffers(*result.first, CopyFlatBuffer(a));
328 }
329 }
330 }
331
Austin Schuh217a9782019-12-21 23:02:50 -0800332 // Now repeat this for the node list.
333 absl::btree_set<FlatbufferDetachedBuffer<Node>> nodes;
334 if (config.message().has_nodes()) {
James Kuszmaul3c998592020-07-27 21:04:47 -0700335 auto_merge_config.mutable_message()->clear_nodes();
Austin Schuh217a9782019-12-21 23:02:50 -0800336 for (const Node *n : *config.message().nodes()) {
337 if (!n->has_name()) {
338 continue;
339 }
340
341 auto result = nodes.insert(CopyFlatBuffer(n));
342 if (!result.second) {
343 *result.first = MergeFlatBuffers(*result.first, CopyFlatBuffer(n));
344 }
345 }
346 }
347
Austin Schuhcb108412019-10-13 16:09:54 -0700348 flatbuffers::FlatBufferBuilder fbb;
Austin Schuhd7b15da2020-02-17 15:06:11 -0800349 fbb.ForceDefaults(true);
Austin Schuhcb108412019-10-13 16:09:54 -0700350
351 // Start by building the vectors. They need to come before the final table.
Austin Schuh40485ed2019-10-26 21:51:44 -0700352 // Channels
353 flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Channel>>>
354 channels_offset;
Austin Schuhcb108412019-10-13 16:09:54 -0700355 {
Austin Schuh40485ed2019-10-26 21:51:44 -0700356 ::std::vector<flatbuffers::Offset<Channel>> channel_offsets;
357 for (const FlatbufferDetachedBuffer<Channel> &c : channels) {
Austin Schuhf1fff282020-03-28 16:57:32 -0700358 channel_offsets.emplace_back(CopyFlatBuffer<Channel>(&c.message(), &fbb));
Austin Schuhcb108412019-10-13 16:09:54 -0700359 }
Austin Schuh40485ed2019-10-26 21:51:44 -0700360 channels_offset = fbb.CreateVector(channel_offsets);
Austin Schuhcb108412019-10-13 16:09:54 -0700361 }
362
363 // Applications
364 flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Application>>>
365 applications_offset;
366 {
367 ::std::vector<flatbuffers::Offset<Application>> applications_offsets;
Austin Schuh40485ed2019-10-26 21:51:44 -0700368 for (const FlatbufferDetachedBuffer<Application> &a : applications) {
Austin Schuhcb108412019-10-13 16:09:54 -0700369 applications_offsets.emplace_back(
370 CopyFlatBuffer<Application>(&a.message(), &fbb));
371 }
372 applications_offset = fbb.CreateVector(applications_offsets);
373 }
374
Austin Schuh217a9782019-12-21 23:02:50 -0800375 // Nodes
376 flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Node>>>
377 nodes_offset;
378 {
379 ::std::vector<flatbuffers::Offset<Node>> node_offsets;
380 for (const FlatbufferDetachedBuffer<Node> &n : nodes) {
381 node_offsets.emplace_back(CopyFlatBuffer<Node>(&n.message(), &fbb));
382 }
383 nodes_offset = fbb.CreateVector(node_offsets);
384 }
385
Austin Schuhcb108412019-10-13 16:09:54 -0700386 // And then build a Configuration with them all.
387 ConfigurationBuilder configuration_builder(fbb);
Austin Schuh40485ed2019-10-26 21:51:44 -0700388 configuration_builder.add_channels(channels_offset);
Austin Schuh217a9782019-12-21 23:02:50 -0800389 if (config.message().has_applications()) {
390 configuration_builder.add_applications(applications_offset);
391 }
392 if (config.message().has_nodes()) {
393 configuration_builder.add_nodes(nodes_offset);
394 }
Austin Schuhcb108412019-10-13 16:09:54 -0700395
396 fbb.Finish(configuration_builder.Finish());
Austin Schuh217a9782019-12-21 23:02:50 -0800397
James Kuszmaul3c998592020-07-27 21:04:47 -0700398 aos::FlatbufferDetachedBuffer<aos::Configuration> modified_config(
399 fbb.Release());
400
Austin Schuh217a9782019-12-21 23:02:50 -0800401 // Now, validate that if there is a node list, every channel has a source
402 // node.
James Kuszmaul3c998592020-07-27 21:04:47 -0700403 FlatbufferDetachedBuffer<Configuration> result =
404 MergeFlatBuffers(modified_config, auto_merge_config);
Austin Schuh217a9782019-12-21 23:02:50 -0800405
406 // Check that if there is a node list, all the source nodes are filled out and
407 // valid, and all the destination nodes are valid (and not the source). This
408 // is a basic consistency check.
Austin Schuhf1fff282020-03-28 16:57:32 -0700409 if (result.message().has_channels()) {
410 for (const Channel *c : *result.message().channels()) {
411 if (c->name()->string_view().back() == '/') {
412 LOG(FATAL) << "Channel names can't end with '/'";
413 }
414 if(c->name()->string_view().find("//")!= std::string_view::npos) {
415 LOG(FATAL) << ": Invalid channel name " << c->name()->string_view()
416 << ", can't use //.";
417 }
418 for (const char data : c->name()->string_view()) {
419 if (data >= '0' && data <= '9') {
420 continue;
421 }
422 if (data >= 'a' && data <= 'z') {
423 continue;
424 }
425 if (data >= 'A' && data <= 'Z') {
426 continue;
427 }
428 if (data == '-' || data == '_' || data == '/') {
429 continue;
430 }
431 LOG(FATAL) << "Invalid channel name " << c->name()->string_view()
432 << ", can only use [-a-zA-Z0-9_/]";
433 }
434 }
435 }
436
437 if (result.message().has_nodes() && result.message().has_channels()) {
438 for (const Channel *c : *result.message().channels()) {
Austin Schuh217a9782019-12-21 23:02:50 -0800439 CHECK(c->has_source_node()) << ": Channel " << FlatbufferToJson(c)
440 << " is missing \"source_node\"";
441 CHECK(GetNode(&result.message(), c->source_node()->string_view()) !=
442 nullptr)
443 << ": Channel " << FlatbufferToJson(c)
444 << " has an unknown \"source_node\"";
445
446 if (c->has_destination_nodes()) {
Austin Schuh719946b2019-12-28 14:51:01 -0800447 for (const Connection *connection : *c->destination_nodes()) {
448 CHECK(connection->has_name());
449 CHECK(GetNode(&result.message(), connection->name()->string_view()) !=
450 nullptr)
Austin Schuh217a9782019-12-21 23:02:50 -0800451 << ": Channel " << FlatbufferToJson(c)
Austin Schuh719946b2019-12-28 14:51:01 -0800452 << " has an unknown \"destination_nodes\" "
453 << connection->name()->string_view();
Austin Schuh217a9782019-12-21 23:02:50 -0800454
Austin Schuh719946b2019-12-28 14:51:01 -0800455 switch (connection->timestamp_logger()) {
456 case LoggerConfig::LOCAL_LOGGER:
457 case LoggerConfig::NOT_LOGGED:
Austin Schuhda40e472020-03-28 15:15:29 -0700458 CHECK(!connection->has_timestamp_logger_nodes());
Austin Schuh719946b2019-12-28 14:51:01 -0800459 break;
460 case LoggerConfig::REMOTE_LOGGER:
461 case LoggerConfig::LOCAL_AND_REMOTE_LOGGER:
Austin Schuhda40e472020-03-28 15:15:29 -0700462 CHECK(connection->has_timestamp_logger_nodes());
463 CHECK_GT(connection->timestamp_logger_nodes()->size(), 0u);
464 for (const flatbuffers::String *timestamp_logger_node :
465 *connection->timestamp_logger_nodes()) {
466 CHECK(GetNode(&result.message(),
467 timestamp_logger_node->string_view()) != nullptr)
468 << ": Channel " << FlatbufferToJson(c)
469 << " has an unknown \"timestamp_logger_node\""
470 << connection->name()->string_view();
471 }
Austin Schuh719946b2019-12-28 14:51:01 -0800472 break;
473 }
474
475 CHECK_NE(connection->name()->string_view(),
476 c->source_node()->string_view())
Austin Schuh217a9782019-12-21 23:02:50 -0800477 << ": Channel " << FlatbufferToJson(c)
478 << " is forwarding data to itself";
479 }
480 }
481 }
482 }
483
484 return result;
Austin Schuhcb108412019-10-13 16:09:54 -0700485}
486
Austin Schuh40485ed2019-10-26 21:51:44 -0700487FlatbufferDetachedBuffer<Configuration> ReadConfig(
James Kuszmaulc0c08da2020-05-10 18:56:07 -0700488 const std::string_view path,
489 const std::vector<std::string_view> &import_paths) {
Austin Schuhcb108412019-10-13 16:09:54 -0700490 // We only want to read a file once. So track the visited files in a set.
491 absl::btree_set<std::string> visited_paths;
James Kuszmaulc0c08da2020-05-10 18:56:07 -0700492 return MergeConfiguration(ReadConfig(path, &visited_paths, import_paths));
Austin Schuhcb108412019-10-13 16:09:54 -0700493}
494
Austin Schuh8d6cea82020-02-28 12:17:16 -0800495FlatbufferDetachedBuffer<Configuration> MergeWithConfig(
Brian Silverman24f5aa82020-06-23 16:21:28 -0700496 const Configuration *config, const Flatbuffer<Configuration> &addition) {
497 return MergeConfiguration(MergeFlatBuffers(config, &addition.message()));
498}
499
500FlatbufferDetachedBuffer<Configuration> MergeWithConfig(
Austin Schuh8d6cea82020-02-28 12:17:16 -0800501 const Configuration *config, std::string_view json) {
502 FlatbufferDetachedBuffer<Configuration> addition =
503 JsonToFlatbuffer(json, Configuration::MiniReflectTypeTable());
504
Brian Silverman24f5aa82020-06-23 16:21:28 -0700505 return MergeWithConfig(config, addition);
Austin Schuh8d6cea82020-02-28 12:17:16 -0800506}
507
James Kuszmaul3ae42262019-11-08 12:33:41 -0800508const Channel *GetChannel(const Configuration *config, std::string_view name,
509 std::string_view type,
Austin Schuhbca6cf02019-12-22 17:28:34 -0800510 std::string_view application_name, const Node *node) {
511 const std::string_view original_name = name;
Austin Schuhf1fff282020-03-28 16:57:32 -0700512 std::string mutable_name;
Austin Schuhcb108412019-10-13 16:09:54 -0700513 VLOG(1) << "Looking up { \"name\": \"" << name << "\", \"type\": \"" << type
514 << "\" }";
515
516 // First handle application specific maps. Only do this if we have a matching
517 // application name, and it has maps.
Austin Schuh40485ed2019-10-26 21:51:44 -0700518 if (config->has_applications()) {
519 auto application_iterator = std::lower_bound(
520 config->applications()->cbegin(), config->applications()->cend(),
521 application_name, CompareApplications);
522 if (application_iterator != config->applications()->cend() &&
Austin Schuhcb108412019-10-13 16:09:54 -0700523 EqualsApplications(*application_iterator, application_name)) {
524 if (application_iterator->has_maps()) {
Austin Schuhf1fff282020-03-28 16:57:32 -0700525 mutable_name = std::string(name);
526 HandleMaps(application_iterator->maps(), &mutable_name, type, node);
527 name = std::string_view(mutable_name);
Austin Schuhcb108412019-10-13 16:09:54 -0700528 }
529 }
530 }
531
532 // Now do global maps.
Austin Schuh40485ed2019-10-26 21:51:44 -0700533 if (config->has_maps()) {
Austin Schuhf1fff282020-03-28 16:57:32 -0700534 mutable_name = std::string(name);
535 HandleMaps(config->maps(), &mutable_name, type, node);
536 name = std::string_view(mutable_name);
Austin Schuhcb108412019-10-13 16:09:54 -0700537 }
538
Austin Schuhbca6cf02019-12-22 17:28:34 -0800539 if (original_name != name) {
540 VLOG(1) << "Remapped to { \"name\": \"" << name << "\", \"type\": \""
541 << type << "\" }";
542 }
Alex Perrycb7da4b2019-08-28 19:35:56 -0700543
Austin Schuh40485ed2019-10-26 21:51:44 -0700544 // Then look for the channel.
545 auto channel_iterator =
Austin Schuhf1fff282020-03-28 16:57:32 -0700546 std::lower_bound(config->channels()->cbegin(), config->channels()->cend(),
Austin Schuh40485ed2019-10-26 21:51:44 -0700547 std::make_pair(name, type), CompareChannels);
Austin Schuhcb108412019-10-13 16:09:54 -0700548
549 // Make sure we actually found it, and it matches.
Austin Schuh40485ed2019-10-26 21:51:44 -0700550 if (channel_iterator != config->channels()->cend() &&
551 EqualsChannels(*channel_iterator, std::make_pair(name, type))) {
Austin Schuhbca6cf02019-12-22 17:28:34 -0800552 if (VLOG_IS_ON(2)) {
553 VLOG(2) << "Found: " << FlatbufferToJson(*channel_iterator);
554 } else if (VLOG_IS_ON(1)) {
555 VLOG(1) << "Found: " << CleanedChannelToString(*channel_iterator);
556 }
Austin Schuh40485ed2019-10-26 21:51:44 -0700557 return *channel_iterator;
Austin Schuhcb108412019-10-13 16:09:54 -0700558 } else {
559 VLOG(1) << "No match for { \"name\": \"" << name << "\", \"type\": \""
560 << type << "\" }";
561 return nullptr;
562 }
563}
564
Austin Schuhc9e10ec2020-01-26 16:08:28 -0800565size_t ChannelIndex(const Configuration *configuration,
566 const Channel *channel) {
567 CHECK(configuration->channels() != nullptr) << ": No channels";
568
569 auto c = std::find(configuration->channels()->begin(),
570 configuration->channels()->end(), channel);
571 CHECK(c != configuration->channels()->end())
572 << ": Channel pointer not found in configuration()->channels()";
573
574 return std::distance(configuration->channels()->begin(), c);
575}
576
Austin Schuhbca6cf02019-12-22 17:28:34 -0800577std::string CleanedChannelToString(const Channel *channel) {
578 FlatbufferDetachedBuffer<Channel> cleaned_channel = CopyFlatBuffer(channel);
579 cleaned_channel.mutable_message()->clear_schema();
580 return FlatbufferToJson(cleaned_channel);
581}
582
Austin Schuha81454b2020-05-12 19:58:36 -0700583std::string StrippedChannelToString(const Channel *channel) {
584 return absl::StrCat("{ \"name\": \"", channel->name()->string_view(),
585 "\", \"type\": \"", channel->type()->string_view(),
586 "\" }");
587}
588
Alex Perrycb7da4b2019-08-28 19:35:56 -0700589FlatbufferDetachedBuffer<Configuration> MergeConfiguration(
590 const Flatbuffer<Configuration> &config,
591 const std::vector<aos::FlatbufferString<reflection::Schema>> &schemas) {
592 flatbuffers::FlatBufferBuilder fbb;
Austin Schuhd7b15da2020-02-17 15:06:11 -0800593 fbb.ForceDefaults(true);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700594
James Kuszmaul3c998592020-07-27 21:04:47 -0700595 // auto_merge_config will contain all the fields of the Configuration that are
596 // to be passed through unmodified to the result of MergeConfiguration().
597 // In the processing below, we mutate auto_merge_config to remove any fields
598 // which we do need to alter (hence why we can't use the input config
599 // directly), and then merge auto_merge_config back in at the end.
600 aos::FlatbufferDetachedBuffer<aos::Configuration> auto_merge_config =
601 aos::CopyFlatBuffer(&config.message());
602
Alex Perrycb7da4b2019-08-28 19:35:56 -0700603 flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Channel>>>
604 channels_offset;
605 if (config.message().has_channels()) {
James Kuszmaul3c998592020-07-27 21:04:47 -0700606 auto_merge_config.mutable_message()->clear_channels();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700607 std::vector<flatbuffers::Offset<Channel>> channel_offsets;
608 for (const Channel *c : *config.message().channels()) {
609 flatbuffers::FlatBufferBuilder channel_fbb;
Austin Schuhd7b15da2020-02-17 15:06:11 -0800610 channel_fbb.ForceDefaults(true);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700611
612 // Search for a schema with a matching type.
613 const aos::FlatbufferString<reflection::Schema> *found_schema = nullptr;
Austin Schuhf1fff282020-03-28 16:57:32 -0700614 for (const aos::FlatbufferString<reflection::Schema> &schema : schemas) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700615 if (schema.message().root_table() != nullptr) {
616 if (schema.message().root_table()->name()->string_view() ==
617 c->type()->string_view()) {
618 found_schema = &schema;
619 }
620 }
621 }
622
623 CHECK(found_schema != nullptr)
624 << ": Failed to find schema for " << FlatbufferToJson(c);
625
626 // The following is wasteful, but works.
627 //
628 // Copy it into a Channel object by creating an object with only the
629 // schema populated and merge that into the current channel.
630 flatbuffers::Offset<reflection::Schema> schema_offset =
631 CopyFlatBuffer<reflection::Schema>(&found_schema->message(),
632 &channel_fbb);
633 Channel::Builder channel_builder(channel_fbb);
634 channel_builder.add_schema(schema_offset);
635 channel_fbb.Finish(channel_builder.Finish());
636 FlatbufferDetachedBuffer<Channel> channel_schema_flatbuffer(
637 channel_fbb.Release());
638
639 FlatbufferDetachedBuffer<Channel> merged_channel(
640 MergeFlatBuffers(channel_schema_flatbuffer, CopyFlatBuffer(c)));
641
642 channel_offsets.emplace_back(
643 CopyFlatBuffer<Channel>(&merged_channel.message(), &fbb));
644 }
645 channels_offset = fbb.CreateVector(channel_offsets);
646 }
647
Austin Schuh217a9782019-12-21 23:02:50 -0800648
649 // Now insert everything else in unmodified.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700650 ConfigurationBuilder configuration_builder(fbb);
651 if (config.message().has_channels()) {
652 configuration_builder.add_channels(channels_offset);
653 }
Alex Perrycb7da4b2019-08-28 19:35:56 -0700654 fbb.Finish(configuration_builder.Finish());
James Kuszmaul3c998592020-07-27 21:04:47 -0700655 aos::FlatbufferDetachedBuffer<aos::Configuration> modified_config(
656 fbb.Release());
657
658 return MergeFlatBuffers(modified_config, auto_merge_config);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700659}
660
Austin Schuh217a9782019-12-21 23:02:50 -0800661const Node *GetNodeFromHostname(const Configuration *config,
662 std::string_view hostname) {
663 for (const Node *node : *config->nodes()) {
Brian Silvermanaa2633f2020-02-17 21:04:14 -0800664 if (node->has_hostname() && node->hostname()->string_view() == hostname) {
Austin Schuh217a9782019-12-21 23:02:50 -0800665 return node;
666 }
Brian Silvermanaa2633f2020-02-17 21:04:14 -0800667 if (node->has_hostnames()) {
668 for (const auto &candidate : *node->hostnames()) {
669 if (candidate->string_view() == hostname) {
670 return node;
671 }
672 }
673 }
Austin Schuh217a9782019-12-21 23:02:50 -0800674 }
675 return nullptr;
676}
Austin Schuhac0771c2020-01-07 18:36:30 -0800677
Austin Schuh217a9782019-12-21 23:02:50 -0800678const Node *GetMyNode(const Configuration *config) {
679 const std::string hostname = (FLAGS_override_hostname.size() > 0)
680 ? FLAGS_override_hostname
681 : network::GetHostname();
682 const Node *node = GetNodeFromHostname(config, hostname);
683 if (node != nullptr) return node;
684
685 LOG(FATAL) << "Unknown node for host: " << hostname
686 << ". Consider using --override_hostname if hostname detection "
687 "is wrong.";
688 return nullptr;
689}
690
Austin Schuhc9e10ec2020-01-26 16:08:28 -0800691const Node *GetNode(const Configuration *config, const Node *node) {
692 if (!MultiNode(config)) {
693 CHECK(node == nullptr) << ": Provided a node in a single node world.";
694 return nullptr;
695 } else {
696 CHECK(node != nullptr);
697 CHECK(node->has_name());
698 return GetNode(config, node->name()->string_view());
699 }
700}
701
Austin Schuh217a9782019-12-21 23:02:50 -0800702const Node *GetNode(const Configuration *config, std::string_view name) {
Austin Schuhfd960622020-01-01 13:22:55 -0800703 CHECK(config->has_nodes())
704 << ": Asking for a node from a single node configuration.";
Austin Schuh217a9782019-12-21 23:02:50 -0800705 for (const Node *node : *config->nodes()) {
Austin Schuhfd960622020-01-01 13:22:55 -0800706 CHECK(node->has_name()) << ": Malformed node " << FlatbufferToJson(node);
Austin Schuh217a9782019-12-21 23:02:50 -0800707 if (node->name()->string_view() == name) {
708 return node;
709 }
710 }
711 return nullptr;
712}
713
Austin Schuhc9e10ec2020-01-26 16:08:28 -0800714const Node *GetNodeOrDie(const Configuration *config, const Node *node) {
715 if (!MultiNode(config)) {
716 CHECK(node == nullptr) << ": Provided a node in a single node world.";
717 return nullptr;
718 } else {
719 const Node *config_node = GetNode(config, node);
720 if (config_node == nullptr) {
721 LOG(FATAL) << "Couldn't find node matching " << FlatbufferToJson(node);
722 }
723 return config_node;
724 }
725}
726
Austin Schuh8bd96322020-02-13 21:18:22 -0800727namespace {
728int GetNodeIndexFromConfig(const Configuration *config, const Node *node) {
Austin Schuhc9e10ec2020-01-26 16:08:28 -0800729 int node_index = 0;
730 for (const Node *iterated_node : *config->nodes()) {
731 if (iterated_node == node) {
732 return node_index;
733 }
734 ++node_index;
735 }
Austin Schuh8bd96322020-02-13 21:18:22 -0800736 return -1;
737}
738} // namespace
739
740int GetNodeIndex(const Configuration *config, const Node *node) {
741 if (!MultiNode(config)) {
742 return 0;
743 }
744
745 {
746 int node_index = GetNodeIndexFromConfig(config, node);
747 if (node_index != -1) {
748 return node_index;
749 }
750 }
751
752 const Node *result = GetNode(config, node);
753 CHECK(result != nullptr);
754
755 {
Austin Schuh04408fc2020-02-16 21:48:54 -0800756 int node_index = GetNodeIndexFromConfig(config, result);
Austin Schuh8bd96322020-02-13 21:18:22 -0800757 if (node_index != -1) {
758 return node_index;
759 }
760 }
761
762 LOG(FATAL) << "Node " << FlatbufferToJson(node)
763 << " not found in the configuration.";
Austin Schuhc9e10ec2020-01-26 16:08:28 -0800764}
765
Austin Schuh04408fc2020-02-16 21:48:54 -0800766int GetNodeIndex(const Configuration *config, std::string_view name) {
767 if (!MultiNode(config)) {
768 return 0;
769 }
770
771 {
772 int node_index = 0;
773 for (const Node *iterated_node : *config->nodes()) {
774 if (iterated_node->name()->string_view() == name) {
775 return node_index;
776 }
777 ++node_index;
778 }
779 }
780 LOG(FATAL) << "Node " << name << " not found in the configuration.";
781}
782
Austin Schuhc9e10ec2020-01-26 16:08:28 -0800783std::vector<const Node *> GetNodes(const Configuration *config) {
784 std::vector<const Node *> nodes;
Austin Schuh8bd96322020-02-13 21:18:22 -0800785 if (MultiNode(config)) {
Austin Schuhc9e10ec2020-01-26 16:08:28 -0800786 for (const Node *node : *config->nodes()) {
787 nodes.emplace_back(node);
788 }
789 } else {
790 nodes.emplace_back(nullptr);
791 }
792 return nodes;
793}
794
Austin Schuhac0771c2020-01-07 18:36:30 -0800795bool MultiNode(const Configuration *config) { return config->has_nodes(); }
796
Austin Schuh217a9782019-12-21 23:02:50 -0800797bool ChannelIsSendableOnNode(const Channel *channel, const Node *node) {
Austin Schuhca4828c2019-12-28 14:21:35 -0800798 if (node == nullptr) {
799 return true;
800 }
Austin Schuh196a4452020-03-15 23:12:03 -0700801 return (CHECK_NOTNULL(channel)->source_node()->string_view() ==
802 node->name()->string_view());
Austin Schuh217a9782019-12-21 23:02:50 -0800803}
804
805bool ChannelIsReadableOnNode(const Channel *channel, const Node *node) {
Austin Schuhca4828c2019-12-28 14:21:35 -0800806 if (node == nullptr) {
807 return true;
808 }
809
Austin Schuh217a9782019-12-21 23:02:50 -0800810 if (channel->source_node()->string_view() == node->name()->string_view()) {
811 return true;
812 }
813
814 if (!channel->has_destination_nodes()) {
815 return false;
816 }
817
Austin Schuh719946b2019-12-28 14:51:01 -0800818 for (const Connection *connection : *channel->destination_nodes()) {
819 CHECK(connection->has_name());
820 if (connection->name()->string_view() == node->name()->string_view()) {
Austin Schuh217a9782019-12-21 23:02:50 -0800821 return true;
822 }
823 }
824
825 return false;
826}
827
Austin Schuh719946b2019-12-28 14:51:01 -0800828bool ChannelMessageIsLoggedOnNode(const Channel *channel, const Node *node) {
Austin Schuhf1fff282020-03-28 16:57:32 -0700829 switch (channel->logger()) {
Austin Schuh719946b2019-12-28 14:51:01 -0800830 case LoggerConfig::LOCAL_LOGGER:
831 if (node == nullptr) {
832 // Single node world. If there is a local logger, then we want to use
833 // it.
834 return true;
835 }
836 return channel->source_node()->string_view() ==
837 node->name()->string_view();
Austin Schuh719946b2019-12-28 14:51:01 -0800838 case LoggerConfig::LOCAL_AND_REMOTE_LOGGER:
Austin Schuhda40e472020-03-28 15:15:29 -0700839 CHECK(channel->has_logger_nodes());
840 CHECK_GT(channel->logger_nodes()->size(), 0u);
Austin Schuh719946b2019-12-28 14:51:01 -0800841
842 if (channel->source_node()->string_view() ==
843 CHECK_NOTNULL(node)->name()->string_view()) {
844 return true;
845 }
Austin Schuhda40e472020-03-28 15:15:29 -0700846
847 [[fallthrough]];
848 case LoggerConfig::REMOTE_LOGGER:
849 CHECK(channel->has_logger_nodes());
850 CHECK_GT(channel->logger_nodes()->size(), 0u);
851 for (const flatbuffers::String *logger_node : *channel->logger_nodes()) {
852 if (logger_node->string_view() ==
853 CHECK_NOTNULL(node)->name()->string_view()) {
854 return true;
855 }
Austin Schuh719946b2019-12-28 14:51:01 -0800856 }
857
858 return false;
859 case LoggerConfig::NOT_LOGGED:
860 return false;
861 }
862
863 LOG(FATAL) << "Unknown logger config " << static_cast<int>(channel->logger());
864}
865
866const Connection *ConnectionToNode(const Channel *channel, const Node *node) {
867 if (!channel->has_destination_nodes()) {
868 return nullptr;
869 }
870 for (const Connection *connection : *channel->destination_nodes()) {
871 if (connection->name()->string_view() == node->name()->string_view()) {
872 return connection;
873 }
874 }
875 return nullptr;
876}
877
878bool ConnectionDeliveryTimeIsLoggedOnNode(const Channel *channel,
879 const Node *node,
880 const Node *logger_node) {
881 const Connection *connection = ConnectionToNode(channel, node);
882 if (connection == nullptr) {
883 return false;
884 }
885 return ConnectionDeliveryTimeIsLoggedOnNode(connection, logger_node);
886}
887
888bool ConnectionDeliveryTimeIsLoggedOnNode(const Connection *connection,
889 const Node *node) {
890 switch (connection->timestamp_logger()) {
891 case LoggerConfig::LOCAL_AND_REMOTE_LOGGER:
Austin Schuhda40e472020-03-28 15:15:29 -0700892 CHECK(connection->has_timestamp_logger_nodes());
893 CHECK_GT(connection->timestamp_logger_nodes()->size(), 0u);
Austin Schuh719946b2019-12-28 14:51:01 -0800894 if (connection->name()->string_view() == node->name()->string_view()) {
895 return true;
896 }
897
Austin Schuhda40e472020-03-28 15:15:29 -0700898 [[fallthrough]];
899 case LoggerConfig::REMOTE_LOGGER:
900 CHECK(connection->has_timestamp_logger_nodes());
901 CHECK_GT(connection->timestamp_logger_nodes()->size(), 0u);
902 for (const flatbuffers::String *timestamp_logger_node :
903 *connection->timestamp_logger_nodes()) {
904 if (timestamp_logger_node->string_view() ==
905 node->name()->string_view()) {
906 return true;
907 }
Austin Schuh719946b2019-12-28 14:51:01 -0800908 }
909
910 return false;
911 case LoggerConfig::LOCAL_LOGGER:
912 return connection->name()->string_view() == node->name()->string_view();
Austin Schuh719946b2019-12-28 14:51:01 -0800913 case LoggerConfig::NOT_LOGGED:
914 return false;
915 }
916
917 LOG(FATAL) << "Unknown logger config "
918 << static_cast<int>(connection->timestamp_logger());
919}
920
Austin Schuhe84c3ed2019-12-14 15:29:48 -0800921std::vector<std::string_view> SourceNodeNames(const Configuration *config,
922 const Node *my_node) {
923 std::set<std::string_view> result_set;
924
925 for (const Channel *channel : *config->channels()) {
926 if (channel->has_destination_nodes()) {
927 for (const Connection *connection : *channel->destination_nodes()) {
928 if (connection->name()->string_view() ==
929 my_node->name()->string_view()) {
930 result_set.insert(channel->source_node()->string_view());
931 }
932 }
933 }
934 }
935
936 std::vector<std::string_view> result;
937 for (const std::string_view source : result_set) {
938 VLOG(1) << "Found a source node of " << source;
939 result.emplace_back(source);
940 }
941 return result;
942}
943
944std::vector<std::string_view> DestinationNodeNames(const Configuration *config,
945 const Node *my_node) {
946 std::vector<std::string_view> result;
947
948 for (const Channel *channel : *config->channels()) {
949 if (channel->has_source_node() && channel->source_node()->string_view() ==
950 my_node->name()->string_view()) {
951 if (!channel->has_destination_nodes()) continue;
952
953 if (channel->source_node()->string_view() !=
954 my_node->name()->string_view()) {
955 continue;
956 }
957
958 for (const Connection *connection : *channel->destination_nodes()) {
959 if (std::find(result.begin(), result.end(),
960 connection->name()->string_view()) == result.end()) {
961 result.emplace_back(connection->name()->string_view());
962 }
963 }
964 }
965 }
966
967 for (const std::string_view destination : result) {
968 VLOG(1) << "Found a destination node of " << destination;
969 }
970 return result;
971}
972
Brian Silverman66f079a2013-08-26 16:24:30 -0700973} // namespace configuration
974} // namespace aos