public BitTorrentPeerInitiator(PeerId localPeerId, IMainLoop mainLoop, IEnumerable <IModule> modules)
 {
     _applicationProtocolLookup = new Dictionary <Sha1Hash, IApplicationProtocol>();
     _localPeerId = localPeerId;
     _mainLoop    = mainLoop;
     _modules     = modules.ToList().AsReadOnly();
 }
Exemple #2
0
        static async Task RunSeederAsync(IMainLoop mainLoop, string transportDir, string contentDir, Metainfo metainfo, CancellationToken ct)
        {
            var client = new TorrentClientBuilder()
                         .UsePeerId(new PeerId(Encoding.ASCII.GetBytes("SEEDER".PadRight(20, 'X'))))
                         .ConfigureServices(services =>
            {
                services.AddLogging(loggingBuilder => loggingBuilder.AddConsole().SetMinimumLevel(LogLevel.Debug));

                services.AddSingleton(mainLoop);
                services.AddSingleton <ITransportProtocol>(s => new FileTransportProtocol(new DirectoryInfo(transportDir), s.GetRequiredService <PeerId>()));
                services.AddSingleton <ITrackerClientFactory>(s => new SingletonTracker(new FileTracker(transportDir, s.GetRequiredService <PeerId>())));
            })
                         .AddBitTorrentApplicationProtocol()
                         .AddDefaultPipeline()
                         .Build();

            var torrent = client.Add(metainfo, contentDir);

            torrent.Start();

            await Task.Run(() => ct.WaitHandle.WaitOne());

            torrent.Stop();
            client.Dispose();
        }
        internal TorrentDownloadManager(PeerId localPeerId,
                                        IMainLoop mainLoop,
                                        IApplicationProtocol <PeerConnection> applicationProtocol,
                                        ITracker tracker,
                                        Metainfo description)
        {
            this.localPeerId    = localPeerId;
            this.mainLoop       = mainLoop;
            ApplicationProtocol = applicationProtocol;
            Description         = description;
            Tracker             = tracker;
            State                     = DownloadState.Pending;
            Downloaded                = 0;
            DownloadRateMeasurer      = new RateMeasurer();
            UploadRateMeasurer        = new RateMeasurer();
            progress                  = new Progress <StatusUpdate>();
            progress.ProgressChanged += ProgressChanged;

            pipeline = new PipelineBuilder()
                       .AddStage <VerifyDownloadedPiecesStage>()
                       .AddStage <DownloadPiecesStage>()
                       .Build();

            stageInterrupt = new StageInterrupt();
        }
Exemple #4
0
 public DownloadPiecesStage(IApplicationProtocol <PeerConnection> application,
                            IMainLoop mainLoop,
                            IPiecePicker piecePicker)
 {
     this.application = application;
     this.mainLoop    = mainLoop;
     this.piecePicker = piecePicker;
 }
 public RemoteUDPClient(IMainLoop loop, NetworkScene ns)
 {
     msgReader.msgHandle = HandleMsg;
     msgReader.mainLoop  = loop;
     ml           = loop;
     networkScene = ns;
     Log.Net("Init UDP: " + loop);
 }
Exemple #6
0
        public void Transfer(IMainLoop loop)
        {
            var socket = new SocketContext(Services, Connection, SignlinkUid);
            var player = Catalogue.Create(
                Model,
                socket,
                loop.Server.Services.ThrowOrGet <IPacketParser>(),
                loop.Server.Services.ThrowOrGet <IPacketHandlerCatalogue>());

            if (!string.IsNullOrEmpty(Greeting))
            {
                player.Get().SystemMessage(Greeting);
            }
        }
Exemple #7
0
    public KCPClient(IMainLoop mainLoop, NetworkScene ns)
    {
        kcp                   = new KCP();
        kcp.outputFunc        = this.SendKCPPacket;
        kcp.closeEventHandler = this.KCPClosed;
        //KCP 逻辑处理是在主线程上执行的

        msgReader           = new MessageReader();
        msgReader.mainLoop  = mainLoop;
        msgReader.msgHandle = HandleMsg;
        ml           = mainLoop;
        networkScene = ns;

        ml.queueInUpdate(Update);
    }
        public TorrentClient(
            ILogger <TorrentClient> logger,
            PeerId localPeerId,
            IMainLoop mainLoop,
            ITransportProtocol transport,
            ITrackerClientFactory trackerClientFactory,
            IApplicationProtocolPeerInitiator peerInitiator,
            IServiceProvider services)
        {
            _logger    = logger;
            _downloads = new Dictionary <Sha1Hash, TorrentDownload>();
            _mainLoop  = mainLoop;
            _mainLoop.Start();
            _trackerClientFactory  = trackerClientFactory;
            _services              = services;
            _updateStatisticsTimer = new Timer(UpdateStatistics, null, TimeSpan.Zero, TimeSpan.FromSeconds(10));
            _peerInitiator         = peerInitiator;
            LocalPeerId            = localPeerId;

            Transport = transport;
            transport.AcceptConnectionHandler += _peerInitiator.AcceptIncomingConnection;
            Transport.Start();
        }
        public PipelineRunner(ILogger <PipelineRunner> logger,
                              PeerId localPeerId,
                              IMainLoop mainLoop,
                              IApplicationProtocol applicationProtocol,
                              ITracker tracker,
                              IServiceProvider parentContainer,
                              IPipelineFactory pipelineFactory)
        {
            _logger             = logger;
            _localPeerId        = localPeerId;
            _mainLoop           = mainLoop;
            ApplicationProtocol = applicationProtocol;
            Description         = applicationProtocol.Metainfo;
            _parentContainer    = parentContainer;
            _pipelineFactory    = pipelineFactory;
            Tracker             = tracker;
            State = DownloadState.Pending;
            DownloadRateMeasurer       = new RateMeasurer();
            UploadRateMeasurer         = new RateMeasurer();
            _progress                  = new Progress <StatusUpdate>();
            _progress.ProgressChanged += ProgressChanged;

            _stageInterrupt = new StageInterrupt();
        }
Exemple #10
0
        public void Transfer(IMainLoop ignored)
        {
            if (Existing.IsDead())
            {
                return;
            }

            var entity = Existing.Get();

            var net = entity.GetNetwork();

            if (net == null)
            {
                return;
            }

            if (!net.TryReinitializeUsing(NewConnection, SignlinkUid))
            {
                Log.Normal(this, $"Attempted but failed to reconnected entity {Existing} Disposed?");
                return;
            }

            Log.Normal(this, $"Reconnected entity {Existing}.");
        }
Exemple #11
0
 public QueueingMessageHandler(IMainLoop mainLoop, IPeerMessageHandler underlying)
 {
     _mainLoop   = mainLoop ?? throw new ArgumentNullException(nameof(mainLoop));
     _underlying = underlying ?? throw new ArgumentNullException(nameof(underlying));
 }
Exemple #12
0
 public RemoteClient(IMainLoop loop)
 {
     msgReader.msgHandle = HandleMsg;
     msgReader.mainLoop  = loop;
     ml = loop;
 }
 public void Setup()
 {
     _mainLoop = new MainLoop();
     _mainLoop.Start();
 }
Exemple #14
0
 public UDPRemoteClient(IMainLoop loop)
 {
 }
Exemple #15
0
 public RemoteClient(IMainLoop loop)
 {
     m_messageReader          = new MessageReader();
     m_messageReader.MainLoop = loop;
 }
Exemple #16
0
 public DownloadPiecesStage(BitTorrentApplicationProtocol applicationProtocol, IMainLoop mainLoop, IPiecePicker piecePicker)
 {
     ApplicationProtocol = applicationProtocol;
     _mainLoop           = mainLoop;
     _piecePicker        = piecePicker;
 }
Exemple #17
0
 public QueueingMessageHandler(IMainLoop mainLoop, IPeerMessageHandler underlying)
 {
     this.mainLoop   = mainLoop;
     this.underlying = underlying;
 }