-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathUtil.cpp
64 lines (58 loc) · 2.72 KB
/
Util.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//------------------------------------------------------------------------------
/*
This file is part of consensus-sim
Copyright (c) 2013, Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include "Core.h"
void Message::addPositions(const std::map<int, NodeState>& update)
{
// add this information to our message
for (std::map<int, NodeState>::const_iterator update_iterator = update.begin();
update_iterator != update.end(); ++update_iterator)
{
if (update_iterator->first != to_node)
{
// don't tell a node about itself
std::map<int, NodeState>::iterator message_iterator=data.find(update_iterator->first);
if(message_iterator != data.end() && message_iterator->first)
{
// we already had data about this node going in this message
if (update_iterator->second.ts > message_iterator->second.ts)
{
message_iterator->second.ts = update_iterator->second.ts;
message_iterator->second.state = update_iterator->second.state;
}
}
else
data.insert(std::make_pair(update_iterator->first, update_iterator->second));
}
}
}
void Message::subPositions(const std::map<int, NodeState>& received)
{
// we received this information from this node, so no need to send it
for (std::map<int, NodeState>::const_iterator received_iterator = received.begin();
received_iterator != received.end(); ++received_iterator)
{
if (received_iterator->first != to_node)
{
std::map<int, NodeState>::iterator message_iterator=data.find(received_iterator->first);
if( (message_iterator != data.end()) &&
(received_iterator->second.ts >= message_iterator->second.ts) )
{
data.erase(message_iterator); // The node doesn't need the data
}
}
}
}