Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
2cb70865
Unverified
Commit
2cb70865
authored
Nov 16, 2019
by
Joseph Noir
Committed by
GitHub
Nov 16, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #970
Generate unique node ID for each actor system
parents
8a212b66
29f60d71
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
5 deletions
+18
-5
libcaf_core/src/node_id.cpp
libcaf_core/src/node_id.cpp
+18
-5
No files found.
libcaf_core/src/node_id.cpp
View file @
2cb70865
...
...
@@ -21,6 +21,7 @@
#include <cstdio>
#include <cstring>
#include <iterator>
#include <random>
#include <sstream>
#include "caf/config.hpp"
...
...
@@ -64,12 +65,24 @@ node_id node_id::default_data::local(const actor_system_config&) {
macs
.
reserve
(
ifs
.
size
());
for
(
auto
&
i
:
ifs
)
macs
.
emplace_back
(
std
::
move
(
i
.
second
));
auto
hd_serial_and_mac_addr
=
join
(
macs
,
""
)
+
detail
::
get_root_uuid
();
auto
seeded_hd_serial_and_mac_addr
=
join
(
macs
,
""
)
+
detail
::
get_root_uuid
();
// By adding 8 random ASCII characters, we make sure to assign a new (random)
// ID to a node every time we start it. Otherwise, we might run into issues
// where a restarted node produces identical actor IDs than the node it
// replaces. Especially when running nodes in a container, because then the
// process ID is most likely the same.
std
::
random_device
rd
;
std
::
minstd_rand
gen
{
rd
()};
std
::
uniform_int_distribution
<>
dis
(
33
,
126
);
for
(
int
i
=
0
;
i
<
8
;
++
i
)
seeded_hd_serial_and_mac_addr
+=
static_cast
<
char
>
(
dis
(
gen
));
// One final tweak: we add another character that makes sure two actor systems
// in the same process won't have the same node ID - even if the user
// manipulates the system to always produce the same seed for its randomness.
auto
sys_seed
=
static_cast
<
char
>
(
system_id
.
fetch_add
(
1
)
+
33
);
seeded_hd_serial_and_mac_addr
+=
sys_seed
;
host_id_type
hid
;
detail
::
ripemd_160
(
hid
,
hd_serial_and_mac_addr
);
// This hack enables multiple actor systems in a single process by overriding
// the last byte in the node ID with the actor system "ID".
hid
.
back
()
=
system_id
.
fetch_add
(
1
);
detail
::
ripemd_160
(
hid
,
seeded_hd_serial_and_mac_addr
);
return
make_node_id
(
detail
::
get_process_id
(),
hid
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment