Brunet.Security.SecurityAssociation.Send C# (CSharp) Method

Send() public method

All outgoing data filters through here.
public Send ( ICopyable app_data ) : void
app_data ICopyable
return void
    public void Send(ICopyable app_data)
    {
      if(Closed) {
        throw new Exception("Cannot send on a closed SA");
      }
      ICopyable data = null;
      if(!HandleOutgoing(app_data, out data)) {
        return;
      }

      _sending = State == States.Active;
      Sender.Send(data);
    }

Usage Example

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);
            SecurityAssociation sa1     = new SecurityAssociation(sender1, spi);

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

            sa1.Subscribe(mdh1, null);
            SecurityAssociation sa2 = new SecurityAssociation(sender2, 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++)
            {
                Thread.Sleep(SecurityAssociation.TIMEOUT * 2 + 5);
                Setup(ref sa1, ref 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.GarbageCollect();
            sa1.GarbageCollect();
            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");
        }
All Usage Examples Of Brunet.Security.SecurityAssociation::Send