protected void OcoTrim(DateTime now)
{
if(_running != 1) {
return;
}
Hashtable used_addrs = new Hashtable();
foreach(TunnelEdge te in _tunnels) {
foreach(Connection con in te.Overlap) {
used_addrs[con.Address] = true;
}
}
ConnectionList cons = _connections;
DateTime timeout = DateTime.UtcNow.AddMilliseconds(-1 * _oco_trim_timeout);
foreach(Connection con in cons) {
if(!con.ConType.Equals(OverlapConnectionOverlord.STRUC_OVERLAP)) {
continue;
}
// If we don't use it or it is still young we'll spare it for now
if(used_addrs.Contains(con.Address) || con.CreationTime > timeout) {
continue;
}
int left_pos = _connections.LeftInclusiveCount(_node.Address, con.Address);
int right_pos = _connections.RightInclusiveCount(_node.Address, con.Address);
if( left_pos >= StructuredNearConnectionOverlord.DESIRED_NEIGHBORS &&
right_pos >= StructuredNearConnectionOverlord.DESIRED_NEIGHBORS )
{
_node.GracefullyClose(con.Edge, "OCO, unused overlapped connection");
}
}
}