How does one actor get remote actor ip within one group?

95 views Asked by At

How does one actor get remote actor ip within one group?

For example, I have two actors A and B which both joined one group chatroom. A and B were spawned on different machines.

Then B send one messge to the group and A can receive and act. Now A wants to know the IP of B for each received message from B. Is there any way to implenment this function?

I found one similar answer from https://github.com/actor-framework/actor-framework/issues/419. But I am not sure this is also proper for group.

1

There are 1 answers

3
neverlord On

When receiving a message, you can get a handle to the sender by calling self->current_sender(). Then you can get the node_id from this handle and, if it's different from your own node_id, ask the middleman about connection details.

auto sender = self->current_sender();
if (!sender)
  return; // anonymous message
auto x = sender->node();
if (x == self->node())
  return; // not a remote actor
auto mm = system.middleman().actor_handle();
self()->request(mm, get_atom::value, x).receive(
  [&](const node_id& nid, const std::string& addr, uint16_t port) {
    assert(nid == x);
    cout << "address: " << addr << ", port = " << port << endl;
  }
);

However, this is not part of the stable API. This means it is likely to change, so keep this in mind.