Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

detect connections from/to self and access local actors directly inst…

…ead, relates #67
  • Loading branch information...
commit c86f6e3a893af8e4d641efee26fbb00162dd6fc4 1 parent 92a71cf
neverlord authored
Showing with 23 additions and 6 deletions.
  1. +15 −2 src/middleman.cpp
  2. +8 −4 src/unicast_network.cpp
View
17 src/middleman.cpp
@@ -58,6 +58,9 @@
using namespace std;
+//#define VERBOSE_MIDDLEMAN
+
+#ifdef VERBOSE_MIDDLEMAN
#define DEBUG(arg) { \
ostringstream oss; \
oss << "[process id: " \
@@ -65,9 +68,9 @@ using namespace std;
<< "] " << arg << endl; \
cout << oss.str(); \
} (void) 0
-
-#undef DEBUG
+#else
#define DEBUG(unused) ((void) 0)
+#endif
namespace cppa { namespace detail {
@@ -398,6 +401,16 @@ bool peer_connection::continue_reading() {
memcpy(node_id.data(), m_rd_buf.data() + sizeof(uint32_t),
process_information::node_id_size);
m_peer.reset(new process_information(process_id, node_id));
+ if (*(parent()->pself()) == *m_peer) {
+# ifdef VERBOSE_MIDDLEMAN
+ DEBUG("incoming connection from self");
+# elif defined(CPPA_DEBUG)
+ std::cerr << "*** middleman warning: "
+ "incoming connection from self"
+ << std::endl;
+# endif
+ throw std::ios_base::failure("refused connection from self");
+ }
parent()->add_peer(*m_peer, this);
// initialization done
m_rd_state = wait_for_msg_size;
View
12 src/unicast_network.cpp
@@ -57,10 +57,6 @@
#include "cppa/detail/actor_proxy_cache.hpp"
#include "cppa/detail/singleton_manager.hpp"
-
-using std::cout;
-using std::endl;
-
namespace cppa {
void publish(actor_ptr whom, std::unique_ptr<util::acceptor> acceptor) {
@@ -82,6 +78,14 @@ actor_ptr remote_actor(util::io_stream_ptr_pair peer) {
peer.first->read(&peer_pid, sizeof(std::uint32_t));
peer.first->read(peer_node_id.data(), peer_node_id.size());
process_information_ptr pinfptr(new process_information(peer_pid, peer_node_id));
+ if (*pinf == *pinfptr) {
+ // dude, this is not a remote actor, it's a local actor!
+# ifdef CPPA_DEBUG
+ std::cerr << "*** warning: remote_actor() called to access a local actor\n"
+ << std::flush;
+# endif
+ return detail::singleton_manager::get_actor_registry()->get(remote_actor_id);
+ }
//auto key = std::make_tuple(remote_actor_id, pinfptr->process_id(), pinfptr->node_id());
detail::middleman_add_peer(peer, pinfptr);
return detail::get_actor_proxy_cache().get_or_put(remote_actor_id,
Please sign in to comment.
Something went wrong with that request. Please try again.