Example #1
0
        public void Test()
        {
            int                spi     = SecurityPolicy.DefaultSPI;
            MockSender         sender1 = new MockSender(null, null, null, 2);
            MockSender         sender2 = new MockSender(null, null, null, 2);
            PeerSecAssociation sa1     = new PeerSecAssociation(sender1, null, spi);

            sa1.StateChangeEvent += StateChange;
            sender2.Receiver      = sa1;
            MockDataHandler mdh1 = new MockDataHandler();

            sa1.Subscribe(mdh1, null);
            PeerSecAssociation sa2 = new PeerSecAssociation(sender2, null, spi);

            sender1.Receiver = sa2;
            MockDataHandler mdh2 = new MockDataHandler();

            sa2.Subscribe(mdh2, null);

            byte[]   b    = null;
            Random   rand = new Random();
            MemBlock mb   = null;

            int current_epoch = sa1.CurrentEpoch;

            for (int i = 0; i < 5; i++)
            {
                Setup(sa1, sa2);

                b = new byte[128];
                rand.NextBytes(b);
                mb = MemBlock.Reference(b);
                sa1.Send(mb);

                Assert.IsTrue(mdh2.Contains(mb), "Contains" + i);
                Assert.AreEqual(state, sa1.State, "State == Active" + i);
                Assert.IsFalse(current_epoch == sa1.CurrentEpoch, "Current epoch " + i);
                current_epoch = sa1.CurrentEpoch;
            }

            sa1.CheckState();
            sa1.CheckState();
            b = new byte[128];
            rand.NextBytes(b);
            mb = MemBlock.Reference(b);
            try {
                sa1.Send(mb);
            } catch {}
            Assert.IsTrue(!mdh2.Contains(mb), "Failed!");
            Assert.AreEqual(state, sa1.State, "State == Failed");
        }
Example #2
0
        public void SHUpdateTest()
        {
            callback_count = 0;
            int                spi     = SecurityPolicy.DefaultSPI;
            MockSender         sender1 = new MockSender(null, null, null, 2);
            MockSender         sender2 = new MockSender(null, null, null, 2);
            PeerSecAssociation sa1     = new PeerSecAssociation(sender1, null, spi);

            sa1.StateChangeEvent += StateChange;
            sender2.Receiver      = sa1;
            MockDataHandler mdh1 = new MockDataHandler();

            sa1.Subscribe(mdh1, null);
            PeerSecAssociation sa2 = new PeerSecAssociation(sender2, null, spi);

            sender1.Receiver = sa2;
            MockDataHandler mdh2 = new MockDataHandler();

            sa2.Subscribe(mdh2, null);

            Setup(sa1, sa2);

            sa1.RequestUpdate += Callback;
            sa2.RequestUpdate += Callback;

            byte[]   b    = null;
            Random   rand = new Random();
            MemBlock mb   = null;

            int current_epoch = sa1.CurrentEpoch;

            for (int i = 0; i < 80; i++)
            {
                b = new byte[128];
                rand.NextBytes(b);
                mb = MemBlock.Reference(b);
                sa1.Send(mb);
                Assert.IsTrue(mdh2.Contains(mb), "Contains" + i);
                if (i % 20 == 0 && i != 0)
                {
                    Assert.AreEqual(callback_count, 1, "Callback count " + i);
                    callback_count = 0;
                    Setup(sa1, sa2);
                }
                else
                {
                    if (i % 20 == 1 && i != 1)
                    {
                        Assert.IsFalse(current_epoch == sa1.CurrentEpoch, "Current epoch " + i);
                        current_epoch = sa1.CurrentEpoch;
                    }
                    Assert.AreEqual(current_epoch, sa1.CurrentEpoch, "Current epoch " + i);
                }
            }
        }
Example #3
0
    public void SHUpdateTest() {
      callback_count = 0;
      int spi = SecurityPolicy.DefaultSPI;
      MockSender sender1 = new MockSender(null, null, null, 2);
      MockSender sender2 = new MockSender(null, null, null, 2);
      PeerSecAssociation sa1 = new PeerSecAssociation(sender1, null, spi); 
      sa1.StateChangeEvent += StateChange;
      sender2.Receiver = sa1;
      MockDataHandler mdh1 = new MockDataHandler();
      sa1.Subscribe(mdh1, null);
      PeerSecAssociation sa2 = new PeerSecAssociation(sender2, null, spi); 
      sender1.Receiver = sa2;
      MockDataHandler mdh2 = new MockDataHandler();
      sa2.Subscribe(mdh2, null);

      Setup(sa1, sa2);

      sa1.RequestUpdate += Callback;
      sa2.RequestUpdate += Callback;

      byte[] b = null;
      Random rand = new Random();
      MemBlock mb = null;

      int current_epoch = sa1.CurrentEpoch;
      for(int i = 0; i < 80; i++) {
        b = new byte[128];
        rand.NextBytes(b);
        mb = MemBlock.Reference(b);
        sa1.Send(mb);
        Assert.IsTrue(mdh2.Contains(mb), "Contains" + i);
        if(i % 20 == 0 && i != 0) {
          Assert.AreEqual(callback_count, 1, "Callback count " + i);
          callback_count = 0;
          Setup(sa1, sa2);
        } else {
          if(i % 20 == 1 && i != 1) {
            Assert.IsFalse(current_epoch == sa1.CurrentEpoch, "Current epoch " + i);
            current_epoch = sa1.CurrentEpoch;
          }
          Assert.AreEqual(current_epoch, sa1.CurrentEpoch, "Current epoch " + i);
        }
      }
    }
Example #4
0
    public void Test() {
      int spi = SecurityPolicy.DefaultSPI;
      MockSender sender1 = new MockSender(null, null, null, 2);
      MockSender sender2 = new MockSender(null, null, null, 2);
      PeerSecAssociation sa1 = new PeerSecAssociation(sender1, null, spi); 
      sa1.StateChangeEvent += StateChange;
      sender2.Receiver = sa1;
      MockDataHandler mdh1 = new MockDataHandler();
      sa1.Subscribe(mdh1, null);
      PeerSecAssociation sa2 = new PeerSecAssociation(sender2, null, spi); 
      sender1.Receiver = sa2;
      MockDataHandler mdh2 = new MockDataHandler();
      sa2.Subscribe(mdh2, null);

      byte[] b = null;
      Random rand = new Random();
      MemBlock mb = null;

      int current_epoch = sa1.CurrentEpoch;
      for(int i = 0; i < 5; i++) {
        Setup(sa1, sa2);

        b = new byte[128];
        rand.NextBytes(b);
        mb = MemBlock.Reference(b);
        sa1.Send(mb);

        Assert.IsTrue(mdh2.Contains(mb), "Contains" + i);
        Assert.AreEqual(state, sa1.State, "State == Active" + i);
        Assert.IsFalse(current_epoch == sa1.CurrentEpoch, "Current epoch " + i);
        current_epoch = sa1.CurrentEpoch;
      }

      sa1.CheckState();
      sa1.CheckState();
      b = new byte[128];
      rand.NextBytes(b);
      mb = MemBlock.Reference(b);
      try {
        sa1.Send(mb);
      } catch {}
      Assert.IsTrue(!mdh2.Contains(mb), "Failed!");
      Assert.AreEqual(state, sa1.State, "State == Failed");
    }