Пример #1
0
        public BitTorrentManager(BitTorrentCache bittorrentCache, string selfNameSpace,
            DictionaryServiceProxy dhtProxy, DictionaryServiceTracker dhtTracker, ClientEngine clientEngine,
            TorrentSettings torrentDefaults, TorrentHelper torrentHelper,
            bool startSeedingAtStartup)
        {
            _bittorrentCache = bittorrentCache;
              SelfNameSpace = selfNameSpace;
              _dictProxy = dhtProxy;
              _dictTracker = dhtTracker;
              _torrentDefaults = torrentDefaults;
              _startSeedingAtStartup = startSeedingAtStartup;

              RegisterClientEngineEventHandlers(clientEngine);
              _clientEngine = clientEngine;

              _torrentHelper = torrentHelper;

              try {
            _fastResumeData = BEncodedValue.Decode<BEncodedDictionary>(
              File.ReadAllBytes(_bittorrentCache.FastResumeFilePath));
              } catch {
            _fastResumeData = new BEncodedDictionary();
              }

              // CacheRegistry is created here because the default cache registry file path is
              // defined here.
              CacheRegistry = new CacheRegistry(_bittorrentCache.CacheRegistryFilePath, selfNameSpace);
              CacheRegistry.LoadCacheDir(_bittorrentCache.DownloadsDirPath);
        }
Пример #2
0
        public BitTorrentManager(BitTorrentCache bittorrentCache, string selfNameSpace,
                                 DictionaryServiceProxy dhtProxy, DictionaryServiceTracker dhtTracker, ClientEngine clientEngine,
                                 TorrentSettings torrentDefaults, TorrentHelper torrentHelper,
                                 bool startSeedingAtStartup)
        {
            _bittorrentCache       = bittorrentCache;
            SelfNameSpace          = selfNameSpace;
            _dictProxy             = dhtProxy;
            _dictTracker           = dhtTracker;
            _torrentDefaults       = torrentDefaults;
            _startSeedingAtStartup = startSeedingAtStartup;

            RegisterClientEngineEventHandlers(clientEngine);
            _clientEngine = clientEngine;

            _torrentHelper = torrentHelper;

            try {
                _fastResumeData = BEncodedValue.Decode <BEncodedDictionary>(
                    File.ReadAllBytes(_bittorrentCache.FastResumeFilePath));
            } catch {
                _fastResumeData = new BEncodedDictionary();
            }

            // CacheRegistry is created here because the default cache registry file path is
            // defined here.
            CacheRegistry = new CacheRegistry(_bittorrentCache.CacheRegistryFilePath, selfNameSpace);
            CacheRegistry.LoadCacheDir(_bittorrentCache.DownloadsDirPath);
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TorrentHelper"/> class.
 /// </summary>
 /// <param name="bittorrentCache">The bittorrent cache.</param>
 /// <param name="hostIP">The host IP.</param>
 /// <param name="trackerPort">The tracker port.</param>
 /// <param name="gsserverPort">The gsserver port. It is used to register the torrent web server.</param>
 public TorrentHelper(BitTorrentCache bittorrentCache, IPAddress hostIP, 
     int trackerPort, int gsserverPort)
 {
     _bittorrentCache = bittorrentCache;
       _hostIP = hostIP;
       _trackerPort = trackerPort;
       _gsserverPort = gsserverPort;
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TorrentHelper"/> class.
 /// </summary>
 /// <param name="bittorrentCache">The bittorrent cache.</param>
 /// <param name="hostIP">The host IP.</param>
 /// <param name="trackerPort">The tracker port.</param>
 /// <param name="gsserverPort">The gsserver port. It is used to register the torrent web server.</param>
 public TorrentHelper(BitTorrentCache bittorrentCache, IPAddress hostIP,
                      int trackerPort, int gsserverPort)
 {
     _bittorrentCache = bittorrentCache;
     _hostIP          = hostIP;
     _trackerPort     = trackerPort;
     _gsserverPort    = gsserverPort;
 }
Пример #5
0
 public PieceLevelTorrentManager(BitTorrentManager manager, BitTorrentCache bittorrentCache,
     DictionaryServiceProxy dhtProxy, TorrentHelper torrentHelper, int pieceInfoServerPort)
 {
     _manager = manager;
       _dhtProxy = dhtProxy;
       _bittorrentCache = bittorrentCache;
       _torrentHelper = torrentHelper;
       _pieceInfoServerPort = pieceInfoServerPort;
       _pieceInfoServer = new HttpPieceInfoServer(_pieceInfoServerPort, this);
 }
 public PieceLevelTorrentManager(BitTorrentManager manager, BitTorrentCache bittorrentCache,
                                 DictionaryServiceProxy dhtProxy, TorrentHelper torrentHelper, int pieceInfoServerPort)
 {
     _manager             = manager;
     _dhtProxy            = dhtProxy;
     _bittorrentCache     = bittorrentCache;
     _torrentHelper       = torrentHelper;
     _pieceInfoServerPort = pieceInfoServerPort;
     _pieceInfoServer     = new HttpPieceInfoServer(_pieceInfoServerPort, this);
 }
Пример #7
0
 public TorrentDataService(BitTorrentCache bittorrentCache)
 {
     _bittorrentCache = bittorrentCache;
 }
Пример #8
0
 public TorrentDataService(BitTorrentCache bittorrentCache)
 {
     _bittorrentCache = bittorrentCache;
 }
Пример #9
0
        public static void ConfigureUnityContainer(IUnityContainer container)
        {
            #region Common
              var dhtTrackerListenerPort =
            Int32.Parse(ConfigurationManager.AppSettings["DhtTrackerListeningPort"]);
              var infoServerListeningPort = Int32.Parse(ConfigurationManager.AppSettings[
            "HttpPieceInfoServerListeningPort"]); // listeningPort
              #endregion

              #region TorrentSettings
              // Create the default settings which a torrent will have.
              // 4 Upload slots - a good ratio is one slot per 5kB of upload speed
              // 50 open connections - should never really need to be changed
              // Unlimited download speed - valid range from 0 -> int.Max
              // Unlimited upload speed - valid range from 0 -> int.Max
              TorrentSettings torrentDefaults = new TorrentSettings(4, 150, 0, 0);
              container.RegisterInstance<TorrentSettings>(torrentDefaults);
              #endregion

              #region ClientEngine
              // DefaultListenPort = 52138;
              var engineSettings = new EngineSettings();
              engineSettings.PreferEncryption = false;
              engineSettings.AllowedEncryption = EncryptionTypes.All;
              var clientEngine = new ClientEngine(engineSettings);
              container.RegisterInstance<ClientEngine>(clientEngine);
              #endregion

              #region DhtProxy
              var peerTtlSecs = 60 * 50;
              container.RegisterType<DictionaryServiceProxy>(
            new InjectionConstructor(typeof(DictionaryServiceBase),
              peerTtlSecs));
              #endregion

              #region DhtTracker
              // Singleton.
              container.RegisterType<DictionaryServiceTracker>(new ContainerControlledLifetimeManager(),
            new InjectionConstructor(
              typeof(DictionaryServiceProxy),
              string.Format("http://*:{0}/", dhtTrackerListenerPort))); // listeningPrefix
              #endregion

              #region TorrentHelper
              // Singleton.
              var cacheBaseDirPath =
            ConfigurationManager.AppSettings["BitTorrentManagerBaseDirPath"];
              IPAddress ip = NetUtil.GetLocalIPByInterface(
            ConfigurationManager.AppSettings["DhtTrackerIface"]);
              int gsserverPort = Int32.Parse(ConfigurationManager.AppSettings["GSServerPort"]);
              var bittorrentCache = new BitTorrentCache(cacheBaseDirPath);
              container.RegisterInstance<BitTorrentCache>(bittorrentCache);
              var torrentHelper = new TorrentHelper(
            bittorrentCache, ip, dhtTrackerListenerPort, gsserverPort);
              container.RegisterInstance<TorrentHelper>(torrentHelper);
              #endregion

              #region BitTorrentManager
              // Singleton.
              container.RegisterType<BitTorrentManager>(
            new ContainerControlledLifetimeManager(),
            new InjectionConstructor(
              typeof(BitTorrentCache),
              ConfigurationManager.AppSettings["BitTorrentManagerSelfNamespace"],
              typeof(DictionaryServiceProxy),
              typeof(DictionaryServiceTracker),
              typeof(ClientEngine),
              typeof(TorrentSettings),
              typeof(TorrentHelper),
              Boolean.Parse(ConfigurationManager.AppSettings[
            "BitTorrentManagerStartSeedingAtStartup"])
              ));
              #endregion

              #region IPieceInfoServer
              // Singleton.
              //container.RegisterType<IPieceInfoServer, HttpPieceInfoServer>(
              //    new ContainerControlledLifetimeManager(),
              //    new InjectionConstructor(
              //      infoServerListeningPort,
              //      typeof(PieceLevelTorrentManager)));
              #endregion

              #region PieceLevelTorrentManager
              container.RegisterType<PieceLevelTorrentManager>(
            new ContainerControlledLifetimeManager(),
            new InjectionConstructor(
              typeof(BitTorrentManager),
              typeof(BitTorrentCache),
              typeof(DictionaryServiceProxy),
              typeof(TorrentHelper),
              infoServerListeningPort));
              #endregion
        }