/// <summary> /// Create a new database connection object and return a handle to it. /// </summary> /// <param name="ConnectionString">Supplies the connection string. /// </param> /// <param name="Flags">Supplies control flags.</param> /// <returns>The connection handle.</returns> public static int CreateScriptDatabaseConnection(string ConnectionString, ScriptDatabaseConnectionFlags Flags) { int Handle; ScriptDatabaseConnection Connection; if (Flags.HasFlag(ScriptDatabaseConnectionFlags.StandardConnection)) { Handle = 0; if (StandardConnection == null) { ConnectionString = GetStandardDatabaseConnectionString(); Connection = new ScriptDatabaseConnection(ConnectionString, Flags); StandardConnection = Connection; ModuleLinkage.DefaultDatabase = StandardConnection.Database; ConnectionTable.Add(Handle, Connection); } } else { Connection = new ScriptDatabaseConnection(ConnectionString, Flags); Handle = ++NextConnectionHandle; if (Handle == 0) { Handle = ++NextConnectionHandle; } ConnectionTable.Add(Handle, Connection); } if (Flags.HasFlag(ScriptDatabaseConnectionFlags.StandardQueryLog) && StandardQueryLogger == null) { try { StandardQueryLogger = new StreamWriter(ALFA.SystemInfo.GetNWNX4InstallationDirectory() + "StandardQueryLog.txt"); } catch (Exception e) { Logger.Log("ScriptDatabaseConnection.CreateScriptDatabaseConnection: Couldn't open standard query log (StandardQueryLog.txt in NWNX4 directory): Exception: {0}", e); } } return(Handle); }
public void Test() { ITunnelOverlap _ito = new SimpleTunnelOverlap(); Address addr_x = new AHAddress(new RNGCryptoServiceProvider()); byte[] addrbuff = Address.ConvertToAddressBuffer(addr_x.ToBigInteger() + (Address.Full / 2)); Address.SetClass(addrbuff, AHAddress._class); Address addr_y = new AHAddress(addrbuff); ArrayList addresses = new ArrayList(); ConnectionTable ct_x = new ConnectionTable(); ConnectionTable ct_y = new ConnectionTable(); ConnectionTable ct_empty = new ConnectionTable(); for (int i = 1; i <= 10; i++) { addrbuff = Address.ConvertToAddressBuffer(addr_x.ToBigInteger() + (i * Address.Full / 16)); Address.SetClass(addrbuff, AHAddress._class); addresses.Add(new AHAddress(addrbuff)); TransportAddress ta = TransportAddressFactory.CreateInstance("brunet.tcp://158.7.0.1:5000"); Edge fe = new FakeEdge(ta, ta, TransportAddress.TAType.Tcp); ct_x.Add(new Connection(fe, addresses[i - 1] as AHAddress, "structured", null, null)); if (i == 10) { ct_y.Add(new Connection(fe, addresses[i - 1] as AHAddress, "structured", null, null)); } } ConnectionType con_type = ConnectionType.Structured; IDictionary id = _ito.GetSyncMessage(null, addr_x, ct_x.GetConnections(con_type)); Assert.AreEqual(_ito.EvaluateOverlap(ct_y.GetConnections(con_type), id)[0].Address, addresses[9], "Have an overlap!"); Assert.AreEqual(_ito.EvaluateOverlap(ct_empty.GetConnections(con_type), id).Count, 0, "No overlap!"); Assert.AreEqual(addresses.Contains(_ito.EvaluatePotentialOverlap(id)), true, "EvaluatePotentialOverlap returns valid!"); }
public void Test() { Address addr_x = new AHAddress(new RNGCryptoServiceProvider()); byte[] addrbuff = Address.ConvertToAddressBuffer(addr_x.ToBigInteger() + (Address.Full / 2)); Address.SetClass(addrbuff, AHAddress._class); Address addr_y = new AHAddress(addrbuff); List<Connection> connections = new List<Connection>(); ConnectionTable ct_x = new ConnectionTable(); ConnectionTable ct_y = new ConnectionTable(); ConnectionTable ct_empty = new ConnectionTable(); NCService ncservice = new NCService(); Connection fast_con = null; for(int i = 1; i <= 11; i++) { addrbuff = Address.ConvertToAddressBuffer(addr_x.ToBigInteger() + (i * Address.Full / 16)); Address.SetClass(addrbuff, AHAddress._class); Address addr = new AHAddress(addrbuff); Connection con = null; TransportAddress ta = TransportAddressFactory.CreateInstance("brunet.tcp://158.7.0.1:5000"); Edge fe = new FakeEdge(ta, ta, TransportAddress.TAType.Tcp); if(i <= 10) { con = new Connection(fe, addr, "structured", null, null); ct_x.Add(con); if(i % 2 == 0) { ncservice.ProcessSample(DateTime.UtcNow, String.Empty, addr, new Point(new double[] {0, 0}, 0), 0, i*10); } } else { fast_con = new Connection(fe, addr, "structured", null, null); ncservice.ProcessSample(DateTime.UtcNow, String.Empty, addr, new Point(new double[] {0, 0}, 0), 0, 5); } if(i == 10) { ct_y.Add(con); } connections.Add(con); } ITunnelOverlap sto = new SimpleTunnelOverlap(); ITunnelOverlap nto = new NCTunnelOverlap(ncservice); ConnectionType con_type = ConnectionType.Structured; List<Connection> pre_cons = new List<Connection>(); pre_cons.Add(connections[9]); IDictionary id = nto.GetSyncMessage(pre_cons, addr_x, ct_x.GetConnections(con_type)); // We do have some pre-existing overlap Assert.AreEqual(nto.EvaluateOverlap(ct_y.GetConnections(con_type), id)[0], connections[9], "NC: Have an overlap!"); Assert.AreEqual(sto.EvaluateOverlap(ct_y.GetConnections(con_type), id)[0], connections[9], "Simple: Have an overlap!"); // We have no overlap with an empty connection table Assert.AreEqual(nto.EvaluateOverlap(ct_empty.GetConnections(con_type), id).Count, 0, "No overlap!"); Assert.AreEqual(sto.EvaluateOverlap(ct_empty.GetConnections(con_type), id).Count, 0, "No overlap!"); // latency[0] == -1 Assert.AreEqual(connections[1].Address.Equals(nto.EvaluatePotentialOverlap(id)), true, "NC: EvaluatePotentialOverlap returns expected!"); Assert.AreEqual(ct_x.Contains(con_type, sto.EvaluatePotentialOverlap(id)), true, "Simple: EvaluatePotentialOverlap returns valid!"); ct_y.Add(fast_con); ct_x.Add(fast_con); id = nto.GetSyncMessage(pre_cons, addr_x, ct_x.GetConnections(con_type)); Assert.AreEqual(fast_con.Address.Equals(nto.EvaluatePotentialOverlap(id)), true, "NC: EvaluatePotentialOverlap returns expected!"); Assert.AreEqual(nto.EvaluateOverlap(ct_y.GetConnections(con_type), id)[0], fast_con, "NC: Have better overlap!"); }
/** * Get a StatusMessage for this node */ public IDictionary GetStatus(IDictionary status_message, ISender edge) { //we just got s status request if (1 == _disconnecting) { throw new AdrException((int)ErrorMessage.ErrorCode.Disconnecting, "disconnecting"); } StatusMessage sm = new StatusMessage(status_message); Edge from = GetEdge(edge); if (ProtocolLog.LinkDebug.Enabled) { ProtocolLog.Write(ProtocolLog.LinkDebug, String.Format( "{0} -start- sys:link.GetStatus({1},{2})", _node.Address, sm, edge)); } CphState cphstate = null; if (from != null) { cphstate = _edge_to_cphstate[from] as CphState; } /** * StatusMessage objects are used to verify the completion * of the Link protocol. If we receive a StatusMessage request * after we send a LinkMessage response, we know the other * Node got our LinkMessage response, and the connection * is active */ StatusMessage response = null; ConnectionTable tab = _node.ConnectionTable; if (cphstate != null) { try { LinkMessage lm_to_add = cphstate.LM; //This is part of connection process: response = _node.GetStatus(sm.NeighborType, lm_to_add.Local.Address); Connection con = new Connection(from, lm_to_add.Local.Address, lm_to_add.ConTypeString, sm, lm_to_add); tab.Add(con); } finally { from.CloseEvent -= this.CloseHandler; CloseHandler(from, null); } } else { //This is just a "regular" status request //update our table: Address fadd = null; Connection c = tab.GetConnection(from); if (c != null) { fadd = c.Address; tab.UpdateStatus(c, sm); } response = _node.GetStatus(sm.NeighborType, fadd); } if (ProtocolLog.LinkDebug.Enabled) { ProtocolLog.Write(ProtocolLog.LinkDebug, String.Format( "{0} -end- sys:link.GetStatus()->{1}", _node.Address, response)); } return(response.ToDictionary()); }
public void Test() { IRelayOverlap _ito = new SimpleRelayOverlap(); Address addr_x = new AHAddress(new RNGCryptoServiceProvider()); byte[] addrbuff = Address.ConvertToAddressBuffer(addr_x.ToBigInteger() + (Address.Full / 2)); Address.SetClass(addrbuff, AHAddress._class); Address addr_y = new AHAddress(addrbuff); ArrayList addresses = new ArrayList(); ConnectionTable ct_x = new ConnectionTable(); ConnectionTable ct_y = new ConnectionTable(); ConnectionTable ct_empty = new ConnectionTable(); for(int i = 1; i <= 10; i++) { addrbuff = Address.ConvertToAddressBuffer(addr_x.ToBigInteger() + (i * Address.Full / 16)); Address.SetClass(addrbuff, AHAddress._class); addresses.Add(new AHAddress(addrbuff)); TransportAddress ta = TransportAddressFactory.CreateInstance("brunet.tcp://158.7.0.1:5000"); Edge fe = new FakeEdge(ta, ta, TransportAddress.TAType.Tcp); ct_x.Add(new Connection(fe, addresses[i - 1] as AHAddress, "structured", null, null)); if(i == 10) { ct_y.Add(new Connection(fe, addresses[i - 1] as AHAddress, "structured", null, null)); } } ConnectionType con_type = ConnectionType.Structured; IDictionary id = _ito.GetSyncMessage(null, addr_x, ct_x.GetConnections(con_type)); Assert.AreEqual(_ito.EvaluateOverlap(ct_y.GetConnections(con_type), id)[0].Address, addresses[9], "Have an overlap!"); Assert.AreEqual(_ito.EvaluateOverlap(ct_empty.GetConnections(con_type), id).Count, 0, "No overlap!"); Assert.AreEqual(addresses.Contains(_ito.EvaluatePotentialOverlap(id)), true, "EvaluatePotentialOverlap returns valid!"); }
public void Test() { Address addr_x = new AHAddress(new RNGCryptoServiceProvider()); byte[] addrbuff = Address.ConvertToAddressBuffer(addr_x.ToBigInteger() + (Address.Full / 2)); Address.SetClass(addrbuff, AHAddress._class); Address addr_y = new AHAddress(addrbuff); List <Connection> connections = new List <Connection>(); ConnectionTable ct_x = new ConnectionTable(); ConnectionTable ct_y = new ConnectionTable(); ConnectionTable ct_empty = new ConnectionTable(); NCService ncservice = new NCService(); Connection fast_con = null; for (int i = 1; i <= 11; i++) { addrbuff = Address.ConvertToAddressBuffer(addr_x.ToBigInteger() + (i * Address.Full / 16)); Address.SetClass(addrbuff, AHAddress._class); Address addr = new AHAddress(addrbuff); Connection con = null; TransportAddress ta = TransportAddressFactory.CreateInstance("brunet.tcp://158.7.0.1:5000"); Edge fe = new FakeEdge(ta, ta, TransportAddress.TAType.Tcp); if (i <= 10) { con = new Connection(fe, addr, "structured", null, null); ct_x.Add(con); if (i % 2 == 0) { ncservice.ProcessSample(DateTime.UtcNow, String.Empty, addr, new Point(new double[] { 0, 0 }, 0), 0, i * 10); } } else { fast_con = new Connection(fe, addr, "structured", null, null); ncservice.ProcessSample(DateTime.UtcNow, String.Empty, addr, new Point(new double[] { 0, 0 }, 0), 0, 5); } if (i == 10) { ct_y.Add(con); } connections.Add(con); } IRelayOverlap sto = new SimpleRelayOverlap(); IRelayOverlap nto = new NCRelayOverlap(ncservice); ConnectionType con_type = ConnectionType.Structured; List <Connection> pre_cons = new List <Connection>(); pre_cons.Add(connections[9]); IDictionary id = nto.GetSyncMessage(pre_cons, addr_x, ct_x.GetConnections(con_type)); // We do have some pre-existing overlap Assert.AreEqual(nto.EvaluateOverlap(ct_y.GetConnections(con_type), id)[0], connections[9], "NC: Have an overlap!"); Assert.AreEqual(sto.EvaluateOverlap(ct_y.GetConnections(con_type), id)[0], connections[9], "Simple: Have an overlap!"); // We have no overlap with an empty connection table Assert.AreEqual(nto.EvaluateOverlap(ct_empty.GetConnections(con_type), id).Count, 0, "No overlap!"); Assert.AreEqual(sto.EvaluateOverlap(ct_empty.GetConnections(con_type), id).Count, 0, "No overlap!"); // latency[0] == -1 Assert.AreEqual(connections[1].Address.Equals(nto.EvaluatePotentialOverlap(id)), true, "NC: EvaluatePotentialOverlap returns expected!"); Assert.AreEqual(ct_x.Contains(con_type, sto.EvaluatePotentialOverlap(id)), true, "Simple: EvaluatePotentialOverlap returns valid!"); ct_y.Add(fast_con); ct_x.Add(fast_con); id = nto.GetSyncMessage(pre_cons, addr_x, ct_x.GetConnections(con_type)); Assert.AreEqual(fast_con.Address.Equals(nto.EvaluatePotentialOverlap(id)), true, "NC: EvaluatePotentialOverlap returns expected!"); Assert.AreEqual(nto.EvaluateOverlap(ct_y.GetConnections(con_type), id)[0], fast_con, "NC: Have better overlap!"); }