[Node] Fragment the nodeListResponse send messages
This commit is contained in:
parent
7aaa64f02d
commit
e5a45023f2
@ -278,26 +278,49 @@ namespace Components
|
||||
}
|
||||
|
||||
void Node::SendList(Network::Address address)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _(Node::Mutex);
|
||||
|
||||
// need to keep the message size below 1404 bytes else recipient will just drop it
|
||||
std::vector<std::string> nodeListReponseMessages;
|
||||
|
||||
for (size_t curNode = 0; curNode < Node::Nodes.size();)
|
||||
{
|
||||
Proto::Node::List list;
|
||||
list.set_isnode(Dedicated::IsEnabled());
|
||||
list.set_protocol(PROTOCOL);
|
||||
list.set_port(Node::GetPort());
|
||||
|
||||
std::lock_guard<std::recursive_mutex> _(Node::Mutex);
|
||||
|
||||
for (auto& node : Node::Nodes)
|
||||
for (size_t i = 0; i < NODE_MAX_NODES_TO_SEND;)
|
||||
{
|
||||
if (curNode >= Node::Nodes.size())
|
||||
break;
|
||||
|
||||
auto node = Node::Nodes.at(curNode++);
|
||||
|
||||
if (node.isValid())
|
||||
{
|
||||
std::string* str = list.add_nodes();
|
||||
|
||||
sockaddr addr = node.address.getSockAddr();
|
||||
str->append(reinterpret_cast<char*>(&addr), sizeof(addr));
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
Session::Send(address, "nodeListResponse", list.SerializeAsString());
|
||||
nodeListReponseMessages.push_back(list.SerializeAsString());
|
||||
}
|
||||
|
||||
size_t i = 0;
|
||||
for (auto& nodeListData : nodeListReponseMessages)
|
||||
{
|
||||
Scheduler::OnDelay([nodeListData, i, address]()
|
||||
{
|
||||
NODE_LOG("Sending %d nodeListResponse length to %s\n", nodeListData.length(), address.getCString());
|
||||
Session::Send(address, "nodeListResponse", nodeListData);
|
||||
}, NODE_SEND_RATE * i++);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned short Node::GetPort()
|
||||
|
@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#define NODE_HALFLIFE (3 * 60 * 1000) //3min
|
||||
#define NODE_MAX_NODES_TO_SEND 64
|
||||
#define NODE_SEND_RATE 500ms
|
||||
|
||||
#ifdef NODE_LOG_MESSAGES
|
||||
#define NODE_LOG(x, ...) Logger::Print(x, __VA_ARGS__)
|
||||
|
Loading…
Reference in New Issue
Block a user