Esempio n. 1
0
        private void StartCoordinator()
        {
            MetadataHooks metadata = new MetadataHooks
            {
                OnMetadataMeasured      = data => MetaGet?.Handle(data),
                OnMetadataPieceReceived = OnMetadataPieceReceived,
                OnMetadataRequestSent   = OnMetadataRequestSent
            };

            CoordinatorHooks hooks = new CoordinatorHooks
            {
                OnPeerConnected      = OnPeerConnected,
                OnPeerDisconnected   = OnPeerDisconnected,
                OnBitfieldChanged    = OnPeerBitfieldChanged,
                OnStatusChanged      = OnPeerStatusChanged,
                OnBlockReceived      = data => DataGet?.Handle(data),
                OnMessageRequested   = data => Sender?.Send(data.Peer, data.Message),
                OnKeepAliveRequested = data => Sender?.SendKeepAlive(data.Peer)
            };

            Coordinator =
                new CoordinatorBuilder()
                .WithHash(Hash)
                .WithMemory(Memory)
                .WithPipeline(Pipeline)
                .WithPlugin(new MetadataPlugin(metadata))
                .Build(hooks);

            Coordinator.Start();
        }
Esempio n. 2
0
 private void OnMetadataPieceReceived(MetadataReceived data)
 {
     Notifications.Enqueue(new MetafileReceivedNotification(data.Hash, new PieceInfo(data.Piece)));
     MetaGet?.Handle(data);
 }