public void Mensaje_entre_red_de_3_nodos()
        {
            using (var loggerFactory = CreateLoggerFactory())
            {
                var channel = new PeerChannelInProc();
                var node1   = new Node(new NodeOptions("Nodo 1", "1111", 1, 2000, "http://localhost:8001"), new BlockBuilder(), loggerFactory, channel);
                var node2   = new Node(new NodeOptions("Nodo 2", "2222", 1, 2000, "http://localhost:8002"), new BlockBuilder(), loggerFactory, channel);
                var node3   = new Node(new NodeOptions("Nodo 3", "3333", 1, 2000, "http://localhost:8003"), new BlockBuilder(), loggerFactory, channel);
                channel.Add(node1);
                channel.Add(node2);
                channel.Add(node3);

                node1.Connect(node2.Host.PublicUrl);
                Assert.AreEqual(1, node1.Peers.Count);
                Assert.AreEqual(1, node2.Peers.Count);
                Assert.AreEqual(0, node3.Peers.Count);

                node2.Connect(node3.Host.PublicUrl);
                Assert.AreEqual(1, node1.Peers.Count);
                Assert.AreEqual(2, node2.Peers.Count);
                Assert.AreEqual(1, node3.Peers.Count);

                node3.Discovery();
                Assert.AreEqual(2, node1.Peers.Count);
                Assert.AreEqual(2, node2.Peers.Count);
                Assert.AreEqual(2, node3.Peers.Count);

                node2.Syncronize();
                node3.Syncronize();

                node1.Add(new Community {
                    Address = new byte[] { 1, 2, 3 }
                });
                Assert.AreEqual(1, node2.Pendings.Count());
                Assert.AreEqual(1, node3.Pendings.Count());
            }
        }
Example #2
0
        partial void test_math_nodeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string log = "";

            Node a = new Node(); // test constructor

            log += "\nNode " + a.ToString();
            a.ID = 0;             // test ID
            Node b = new Node(1); // test constructor

            log += "\n\nNode " + a.ToString();
            log += "\nNode " + b.ToString();
            object[] c0 = { 1.19, 4.23 };
            a.Coordinate = c0;
            object[] c1 = { 2.90, 3.01 };
            b.Coordinate = c1;             // test coordinate
            object[] c2 = { 1.09, 0.98 };
            Node     c  = new Node(2, c2); // test constructor

            Node[] n = { a, b, c };

            log += "\n";
            for (int i = 0; i < n.Length; i++)
            {
                log += "\nNode " + n[i].ToString();
            }

            Math.Vector x, y, z;

            // connect node 0 to node 1 with directed edge
            x = new Math.Vector((double)a.Coordinate[0], (double)a.Coordinate[1]);
            y = new Math.Vector((double)b.Coordinate[0], (double)b.Coordinate[1]);
            z = y - x;
            DirectedEdge e0 = new DirectedEdge(a, b);

            e0.Weight = z.Magnitude;
            a.Add(e0);
            b.Add(e0);
            // connect node 1 to node 2 with directed edge
            x = new Math.Vector((double)b.Coordinate[0], (double)b.Coordinate[1]);
            y = new Math.Vector((double)c.Coordinate[0], (double)c.Coordinate[1]);
            z = y - x;
            DirectedEdge e1 = new DirectedEdge(b, c);

            e1.Weight = z.Magnitude;
            b.Add(e1);
            c.Add(e1);
            // connect node 2 to node 0 with edge
            x = new Math.Vector((double)c.Coordinate[0], (double)c.Coordinate[1]);
            y = new Math.Vector((double)a.Coordinate[0], (double)a.Coordinate[1]);
            z = y - x;
            Edge e2 = (Edge) new Edge()
                      .Configure(c, a);

            e2.Weight = z.Magnitude;
            c.Add(e2);
            a.Add(e2);

            log += "\n";
            for (int i = 0; i < n.Length; i++)
            {
                log += "\nNode " + n[i].ToString();
            }

            richTextBox.Text = log;
        }