Skip to content

Commit

Permalink
improved node data exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
seuffert committed Nov 21, 2011
1 parent 8fb3818 commit c7b4fd8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions XBSlink/xbs_node.cs
Expand Up @@ -119,8 +119,8 @@ class xbs_node
private List<xbs_xbox> xbox_list;

private volatile int _last_ping_delay_ms;
public int last_ping_delay_ms { get { return _last_ping_delay_ms; } private set { _last_ping_delay_ms = value; } }
private DateTime lastPingTime = new DateTime(0);
public int last_ping_delay_ms { get { return _last_ping_delay_ms; } private set { _last_ping_delay_ms = value; } }
private DateTime lastPingTime = DateTime.MinValue;
public TimeSpan timeSinceLastPing { get { return (DateTime.Now - lastPingTime); } }
private DateTime lastPongTime = DateTime.Now;
public TimeSpan timeSinceLastPong { get { return (DateTime.Now - lastPongTime); } }
Expand Down
22 changes: 14 additions & 8 deletions XBSlink/xbs_node_list.cs
Expand Up @@ -43,6 +43,7 @@ class xbs_node_list
public const int MAX_PING_NO_RESPONSE_SECONDS = 30;
public const int MAX_ADD_NODE_TIMEOUT_SECONDS = 2;
public const int MAX_ASK_CLOUDHELPER_COUNT = 3;
public const int MIN_REFRESH_NODE_DELAY = 2;
private volatile bool run_ping_nodes_loop = true;

public volatile bool notify_on_new_node = true;
Expand Down Expand Up @@ -238,7 +239,7 @@ public void sendLogOff()
informNodesOnDelNode(local_node);
}

public void pingAllnodes()
public void refreshAllNodes()
{
DateTime now = DateTime.Now;
List<xbs_node> del_list = new List<xbs_node>();
Expand All @@ -253,15 +254,20 @@ public void pingAllnodes()
time_since_last_ping = (int)n.timeSinceLastPing.TotalSeconds;
time_since_last_pong = (int)n.timeSinceLastPong.TotalSeconds;
if (time_since_last_ping > xbs_node_list.MIN_PING_DELAY_SECONDS || time_since_last_pong > xbs_node_list.MIN_PING_DELAY_SECONDS)
{
n.sendPing();
if (n.client_version == xbs_node.CLIENT_VERSION_UNKNOWN)
n.sendGetClientVersion();
if (n.nickname_received == false)
n.sendGetNickname();
}

if (time_since_last_pong > xbs_node_list.MAX_PING_NO_RESPONSE_SECONDS)
del_list.Add(n);
else
if ((DateTime.Now.Second % 2) == 0) // every 2 seconds check if all node data is available
{
if (n.client_version == xbs_node.CLIENT_VERSION_UNKNOWN)
n.sendGetClientVersion();
if (n.nickname_received == false)
n.sendGetNickname();
if (n.last_ping_delay_ms < 0 )
n.sendPing();
}
}
foreach (xbs_node n in del_list)
{
Expand Down Expand Up @@ -302,7 +308,7 @@ private void ping_nodes_thread()
while (run_ping_nodes_loop)
{
if(xbs_udp_listener.getInstance()!=null)
pingAllnodes();
refreshAllNodes();
checkNodesInAddingList();
if (run_ping_nodes_loop)
Thread.Sleep(1000);
Expand Down
2 changes: 2 additions & 0 deletions XBSlink/xbs_udp_listener.cs
Expand Up @@ -369,6 +369,8 @@ public void dispatch_in_msg(ref xbs_udp_message udp_msg)

case xbs_node_message_type.KNOWNNODE:
xbs_node_message_knownnode msg_knownnode = new xbs_node_message_knownnode(udp_msg.data);

// only accept KNOWNNODE messages when not part of a cloud
if (!xbs_cloudlist.getInstance().part_of_cloud)
{
tmp_node = node_list.findNode(msg_knownnode.ip, msg_knownnode.port);
Expand Down

0 comments on commit c7b4fd8

Please sign in to comment.