public TorrentService(TorrentServiceOptions options, ILoggerFactory logger) { this.Options = options; this.Address = Options.TorProxy.Address; this.SocksPort = Options.TorProxy.SocksPort; this.ControlPort = Options.TorProxy.ControlPort; this.Logger = logger.CreateLogger(this.GetType().FullName); this.TorrentEngineSettings = new EngineSettings( defaultSavePath: Options.Client.Path, globalMaxConnections: Options.Client.MaxConnections, globalHalfOpenConnections: Options.Client.HalfOpenConnections, globalMaxDownloadSpeed: Options.Client.MaxDownloadSpeed, globalMaxUploadSpeed: Options.Client.MaxUploadSpeed, allowedEncryption: Options.Client.AllowedEncryption); this.TorrentSettings = new TorrentSettings( Options.Client.UploadSlots, Options.Client.MaxConnections, Options.Client.MaxDownloadSpeed, Options.Client.MaxUploadSpeed, Options.Client.InitialSeedingEnabled); if (!Directory.Exists(Options.Client.Path)) { Directory.CreateDirectory(Options.Client.Path); } if (!Directory.Exists(Path.Combine(Options.Client.Path, "Torrents"))) { Directory.CreateDirectory(Path.Combine(Options.Client.Path, "Torrents")); } this.TorrentClient = new ClientEngine(this.TorrentEngineSettings); this.TorrentClient.ChangeListenEndpoint(new IPEndPoint(IPAddress.Any, Options.Client.ListenPort)); try { this.FastResume = BEncodedValue.Decode <BEncodedDictionary>(File.ReadAllBytes(Path.Combine(Options.Client.Path, "fastresume.data"))); } catch { this.FastResume = new BEncodedDictionary(); } }
public TorrentService(ILogger <TorrentService> log, ITorrentClient torrentClient, TorrentServiceOptions options, IMessageBroker broker) { _log = log; _torrentClient = torrentClient; _downloadTorrentPath = options.DownloadTorrentPath; _broker = broker; _broker.DeclareExchange(BrokerExchange); }