Files
hpcore/src/p2p/self_node.cpp
Chalith Desaman 9999c28a37 Remove self connection on peer discovery (#269)
* Resetting last shard syncing flags when sync is abandoned. (#268)

* Remove self loopback connection when self is added by peer discovery

* Resolved PR comments

Co-authored-by: Savinda Senevirathne <savindadilsara@gmail.com>
2021-03-12 19:01:58 +05:30

30 lines
769 B
C++

#include "../pchheader.hpp"
#include "peer_session_handler.hpp"
namespace p2p::self
{
// Holds self messages waiting to be processed.
moodycamel::ConcurrentQueue<std::string> msg_queue;
std::optional<conf::peer_ip_port> ip_port;
/**
* Processes the next queued message (if any).
* @return 0 if no messages in queue. 1 if message was processed successfully. -1 on error.
*/
int process_next_message()
{
std::string msg;
if (msg_queue.try_dequeue(msg))
return p2p::handle_self_message(msg);
return 0;
}
void send(std::string_view message)
{
// Passing the ownership of message to the queue.
msg_queue.enqueue(std::string(message));
}
} // namespace p2p::self