Ejemplo n.º 1
0
        private void OnDataVerified(DataVerified data)
        {
            Notifications.Enqueue(new DataVerifiedNotification(data.Hash, data.Bitfield));

            DataMap?.Handle(data);
            DataGet?.Handle(data);
        }
Ejemplo n.º 2
0
        public void ShouldSentInterestedWhenPeerHasSomethingToOffer()
        {
            PeerHash other = PeerHash.Random();

            Action <Action <PeerHash, Bitfield, PeerState> > handle = callback =>
            {
                callback.Invoke(other, Bitfield.Complete(1), new PeerState());
            };

            using (DataGetFixture fixture = new DataGetFixture())
                using (DataGetSession session = fixture.Start())
                {
                    DataVerified verified = new DataVerified
                    {
                        Hash     = session.Service.Parameters.Hash,
                        Bitfield = new Bitfield(1)
                    };

                    A.CallTo(() => session.DataMap.Query(A <Action <PeerHash, Bitfield, PeerState> > .Ignored)).Invokes(handle);

                    session.Service.Start();
                    session.Service.Handle(verified);

                    session.Pipeline.Tick();
                    session.Pipeline.Process();

                    A.CallTo(() => session.Glue.SendInterested(other)).MustHaveHappened();
                }
        }
Ejemplo n.º 3
0
        public void Handle(DataVerified data)
        {
            context.Queue.Add(() =>
            {
                context.Verified = true;
            });

            context.Queue.Add(new DataShareTaskInterested());
        }
Ejemplo n.º 4
0
        public void Handle(DataVerified data)
        {
            context.Queue.Add(() =>
            {
                context.Bitfield = data.Bitfield;
                context.Bitfields.Ranking.Complete(data.Bitfield);

                context.Cache  = new OmnibusCache(data.Bitfield.Length);
                context.Pieces = new OmnibusPieceCollection(context);
            });
        }
Ejemplo n.º 5
0
        private void OnDataVerified(DataVerified data)
        {
            Notifications.Enqueue(new DataVerifiedNotification(data.Hash, data.Bitfield));

            DataMap?.Handle(data);
            DataGet?.Handle(data);
            DataShare?.Handle(data);

            Coordinator?.Handle(data);
            TrackerGet.Announce(Hash);
        }
Ejemplo n.º 6
0
        public void ShouldTriggerBlockReservedSequentialForNotCompletedPieces()
        {
            BitfieldChanged bitfieldChangedA = new BitfieldChanged
            {
                Peer     = PeerHash.Random(),
                Bitfield = Bitfield.Sequence(true, true)
            };

            BitfieldChanged bitfieldChangedB = new BitfieldChanged
            {
                Peer     = PeerHash.Random(),
                Bitfield = Bitfield.Sequence(true, false)
            };

            using (OmnibusFixture fixture = new OmnibusFixture())
                using (OmnibusSession session = fixture.Start())
                {
                    DataVerified verified = new DataVerified
                    {
                        Hash     = session.Hash,
                        Bitfield = Bitfield.Sequence(true, false)
                    };

                    Trigger trigger = Trigger.Bind(ref session.Hooks.OnBlockReserved, data =>
                    {
                        data.Block.Should().NotBeNull();
                        data.Block.Piece.Index.Should().Be(1);
                    });

                    session.Service.Start();
                    session.Service.HandleMetafileVerified(session.Metainfo);
                    session.Service.Handle(verified);

                    session.Service.Handle(bitfieldChangedA);
                    session.Service.Handle(bitfieldChangedB);
                    session.Pipeline.Process();

                    session.Service.Schedule(OmnibusStrategy.Sequential, bitfieldChangedA.Peer, 1);
                    session.Pipeline.Process();

                    trigger.Wait().Should().BeTrue();
                }
        }
Ejemplo n.º 7
0
 public void Handle(DataVerified data)
 {
     mine = data.Bitfield;
 }
Ejemplo n.º 8
0
 public void Handle(DataVerified data)
 {
     context.Facts.Handle(data);
 }