예제 #1
0
 public ShareBuilder(IShareHasher hasher, ILoggingService loggingService)
 {
     this.hasher         = hasher;
     this.loggingService = loggingService;
     this.queue          = new BlockingCollection <QueueItem>();
     this.cancellation   = new CancellationTokenSource();
 }
예제 #2
0
파일: Core.cs 프로젝트: tabrath/meshwork
        public static bool Init(ISettings settings)
        {
            if (loaded == true)
            {
                throw new Exception("Please only call this method once.");
            }

            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            Core.Settings = settings;

            string pidFilePath = Path.Combine(Core.Settings.DataPath, "meshwork.pid");

            if (File.Exists(pidFilePath))
            {
                int processId = -1;
                Int32.TryParse(File.ReadAllText(pidFilePath), out processId);
                try
                {
                    Process.GetProcessById(processId);
                    Console.Error.WriteLine("Meshwork is already running (PID {0})!", processId);
                    return(false);
                }
                catch (ArgumentException)
                {
                    File.Delete(pidFilePath);
                }
            }
            File.WriteAllText(pidFilePath, Process.GetCurrentProcess().Id.ToString());

            if (settings.KeyEncrypted)
            {
                PasswordPrompt(null, EventArgs.Empty);
                if (!settings.KeyUnlocked)
                {
                    // Quit!
                    return(false);
                }
            }

            rsaProvider = new RSACryptoServiceProvider();
            rsaProvider.ImportParameters(settings.EncryptionParameters);
            nodeID = Common.SHA512Str(rsaProvider.ToXmlString(false));

            fileSystem = Container.GetExportedValue <IFileSystemProvider>();

            shareBuilder = Container.GetExportedValue <IShareBuilder>();
            shareBuilder.FinishedIndexing += ShareBuilder_FinishedIndexing;

            shareWatcher        = Container.GetExportedValue <IShareWatcher>();
            shareHasher         = Container.GetExportedValue <IShareHasher>();
            transportManager    = Container.GetExportedValue <ITransportManager>();
            fileTransferManager = Container.GetExportedValue <IFileTransferManager>();
            fileSearchManager   = Container.GetExportedValue <IFileSearchManager>();
            destinationManager  = Container.GetExportedValue <IDestinationManager>();

            // XXX: Use reflection to load these:
            destinationManager.RegisterSource(new TCPIPv4DestinationSource());
            destinationManager.RegisterSource(new TCPIPv6DestinationSource());

            MonoTorrent.Client.Tracker.TrackerFactory.Register("meshwork", typeof(MeshworkTracker));

            ITransportListener tcpListener = new TcpTransportListener(Core.Settings.TcpListenPort);

            transportListeners.Add(tcpListener);

            loaded = true;

            if (FinishedLoading != null)
            {
                FinishedLoading(null, EventArgs.Empty);
            }

            return(true);
        }