public void ShouldTriggerPeerStatusChangedWhenRemoteInterested() { using (CoordinatorFixture fixture = new CoordinatorFixture()) using (CoordinatorSession session = fixture.Start()) { NetworkConnection connection = A.Fake <NetworkConnection>(); Handshake handshake = new Handshake(PeerHash.Random(), PeerHash.Random(), session.Coordinator.Hash, HandshakeOptions.None); MessageReceived received = new MessageReceived { Type = "interested", Peer = handshake.Remote, Payload = new CoordinatorMessage(0x00, 0x00, 0x00, 0x01, 0x02) }; Trigger handler = Trigger.Bind(ref session.Coordinator.Hooks.OnStatusChanged, data => { data.Peer.Should().Be(handshake.Remote); data.State.IsLocalChokingRemote.Should().BeTrue(); data.State.IsLocalInterestedInRemote.Should().BeFalse(); data.State.IsRemoteChokingLocal.Should().BeTrue(); data.State.IsRemoteInterestedInLocal.Should().BeTrue(); }); session.Coordinator.Connect(connection, handshake); session.Coordinator.Handle(received); handler.Wait().Should().BeTrue(); } }
public void ShouldTriggerStatusChangedWhenLocalHasChoked() { using (CoordinatorFixture fixture = new CoordinatorFixture()) using (CoordinatorSession session = fixture.Start()) { NetworkConnection connection = A.Fake <NetworkConnection>(); Handshake handshake = new Handshake(PeerHash.Random(), PeerHash.Random(), session.Coordinator.Hash, HandshakeOptions.None); session.Coordinator.Connect(connection, handshake); session.Coordinator.Choke(handshake.Remote, false); Trigger handler = Trigger.Bind(ref session.Coordinator.Hooks.OnStatusChanged, data => { data.Peer.Should().Be(handshake.Remote); data.State.IsLocalChokingRemote.Should().BeTrue(); data.State.IsLocalInterestedInRemote.Should().BeFalse(); data.State.IsRemoteChokingLocal.Should().BeTrue(); data.State.IsRemoteInterestedInLocal.Should().BeFalse(); }); session.Coordinator.Choke(handshake.Remote, true); handler.Wait().Should().BeTrue(); } }
public void ShouldTriggerPeerConnected() { using (CoordinatorFixture fixture = new CoordinatorFixture()) using (CoordinatorSession session = fixture.Start()) { NetworkConnection connection = A.Fake <NetworkConnection>(); Handshake handshake = new Handshake(PeerHash.Random(), PeerHash.Random(), session.Coordinator.Hash, HandshakeOptions.None); Trigger handler = Trigger.Bind(ref session.Coordinator.Hooks.OnPeerConnected, data => { data.Peer.Should().Be(handshake.Remote); data.Connection.Should().Be(connection); }); session.Coordinator.Connect(connection, handshake); handler.Wait().Should().BeTrue(); } }