public void WrapperEdgeRegressionTest() { AHAddress addr = new AHAddress(new System.Security.Cryptography.RNGCryptoServiceProvider()); TransportAddress ta = TransportAddressFactory.CreateInstance("brunet.tcp://169.0.5.1:5000"); FakeEdge fe = new FakeEdge(ta, ta); WrapperEdge we_fe = new WrapperEdge(fe); Connection fcon = new Connection(we_fe, addr, "structured", null, null); List <Connection> overlap = new List <Connection>(); overlap.Add(fcon); RelayTransportAddress tta = new RelayTransportAddress(addr, overlap); RelayEdge te1 = new RelayEdge(null, tta, tta, new SimpleForwarderSelector(), overlap); WrapperEdge we_te1 = new WrapperEdge(te1); Connection t1con = new Connection(we_te1, addr, "structured", null, null); overlap = new List <Connection>(); overlap.Add(t1con); RelayEdge te2 = new RelayEdge(null, tta, tta, new SimpleForwarderSelector(), overlap); WrapperEdge we_te2 = new WrapperEdge(te2); Connection t2con = new Connection(we_te2, addr, "structured", null, null); overlap = new List <Connection>(); overlap.Add(t2con); RelayEdge te3 = new RelayEdge(null, tta, tta, new SimpleForwarderSelector(), overlap); WrapperEdge we_te3 = new WrapperEdge(te3); Connection t3con = new Connection(we_te3, addr, "structured", null, null); overlap = new List <Connection>(); overlap.Add(t3con); RelayEdge te4 = new RelayEdge(null, tta, tta, new SimpleForwarderSelector(), overlap); WrapperEdge we_te4 = new WrapperEdge(te4); Connection t4con = new Connection(we_te4, addr, "structured", null, null); overlap = new List <Connection>(); overlap.Add(t4con); RelayEdge te5 = new RelayEdge(null, tta, tta, new SimpleForwarderSelector(), overlap); WrapperEdge we_te5 = new WrapperEdge(te5); Connection t5con = new Connection(we_te5, addr, "structured", null, null); Assert.AreEqual(te5.ShouldClose(), false, "Shouldn't close yet..."); te1.DisconnectionHandler(fcon); Assert.AreEqual(te5.ShouldClose(), true, "Should close..."); overlap.Add(t5con); overlap.Add(t3con); overlap.Add(t1con); te2.UpdateNeighborIntersection(overlap); Assert.AreEqual(te5.ShouldClose(), true, "Should close... 2"); }
public void Test() { TransportAddress ta = TransportAddressFactory.CreateInstance("brunet.tcp://169.0.5.1:5000"); FakeEdge fe = new FakeEdge(ta, ta); var rng = new System.Security.Cryptography.RNGCryptoServiceProvider(); var cons = new List <Connection>(); for (int i = 0; i < 50; i++) { var addr = new AHAddress(rng); cons.Add(new Connection(fe, addr, "structured", null, null)); } var start_addr = new AHAddress(rng); IComparer <Connection> distance_comparer = new BroadcastSender.AbsoluteDistanceComparer(start_addr); cons.Sort(distance_comparer); BigInteger current_distance = new BigInteger(0); foreach (Connection con in cons) { AHAddress addr = con.Address as AHAddress; BigInteger next_distance = start_addr.DistanceTo(addr).abs(); Assert.IsTrue(current_distance < next_distance, "DistanceComparer"); current_distance = next_distance; } IComparer <Connection> address_comparer = new BroadcastSender.LeftDistanceComparer(start_addr); cons.Sort(address_comparer); current_distance = new BigInteger(0); foreach (Connection con in cons) { AHAddress addr = con.Address as AHAddress; BigInteger next_distance = start_addr.LeftDistanceTo(addr).abs(); Assert.IsTrue(current_distance < next_distance, "AddressComparer"); current_distance = next_distance; } }
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); } 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!"); }
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!"); }
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() { AHAddress addr = new AHAddress(new System.Security.Cryptography.RNGCryptoServiceProvider()); TransportAddress ta = TransportAddressFactory.CreateInstance("brunet.tcp://169.0.5.1:5000"); FakeEdge fe = new FakeEdge(ta, ta); Connection fcon = new Connection(fe, addr, "structured", null, null); List<Connection> overlap = new List<Connection>(); overlap.Add(fcon); TunnelTransportAddress tta = new TunnelTransportAddress(addr, overlap); TunnelEdge te1 = new TunnelEdge(null, tta, tta, new SimpleForwarderSelector(), overlap); Connection t1con = new Connection(te1, addr, "structured", null, null); overlap = new List<Connection>(); overlap.Add(t1con); TunnelEdge te2 = new TunnelEdge(null, tta, tta, new SimpleForwarderSelector(), overlap); Connection t2con = new Connection(te2, addr, "structured", null, null); overlap = new List<Connection>(); overlap.Add(t2con); TunnelEdge te3 = new TunnelEdge(null, tta, tta, new SimpleForwarderSelector(), overlap); Connection t3con = new Connection(te3, addr, "structured", null, null); overlap = new List<Connection>(); overlap.Add(t3con); TunnelEdge te4 = new TunnelEdge(null, tta, tta, new SimpleForwarderSelector(), overlap); Connection t4con = new Connection(te4, addr, "structured", null, null); overlap = new List<Connection>(); overlap.Add(t4con); TunnelEdge te5 = new TunnelEdge(null, tta, tta, new SimpleForwarderSelector(), overlap); Connection t5con = new Connection(te5, addr, "structured", null, null); Assert.AreEqual(te5.ShouldClose(), false, "Shouldn't close yet..."); te1.DisconnectionHandler(fcon); Assert.AreEqual(te5.ShouldClose(), true, "Should close..."); overlap.Add(t5con); overlap.Add(t3con); overlap.Add(t1con); te2.UpdateNeighborIntersection(overlap); Assert.AreEqual(te5.ShouldClose(), true, "Should close... 2"); }