Esempio n. 1
0
        void INetworkListener.OnFileError(string sender, string recipient, string filename)
        {
            CCBLogConfig.GetLogger().Debug("Tagging file completed with error: {0}\n", filename);
            try
            {
                CCBP2PFile infile = GetInFile(filename);

                if ((null != infile) && infile.CheckNode(sender, recipient))
                {
                    infile.OnError();
                    m_signal.Set();
                }
                lock (m_outbox)
                {
                    foreach (CCBP2PFile outfile in m_outbox.Values)
                    {
                        if ((0 == string.Compare(outfile.LocalName, filename)) && outfile.CheckNode(sender, recipient))
                        {
                            outfile.OnError();
                            m_signal.Set();
                        }
                    }
                }
            }
            catch (IOException ioex)
            {
                CCBLogConfig.GetLogger().Error("IO Exception OnFileError {0}: {1}", filename, ioex.Message);
            }
            catch (Exception ex)
            {
                CCBLogConfig.GetLogger().Error("Exception OnFileError {0}: {1}", filename, ex.Message);
            }
        }
Esempio n. 2
0
        //After having written the file, we mark it as finalized, which will make the file worker thread
        //calculate and check the hash.
        void INetworkListener.OnFileComplete(string filename, byte[] hash)
        {
            CCBLogConfig.GetLogger().Debug("Completing file: {0}\n", filename);
            try
            {
                CCBP2PFile infile = GetInFile(filename);

                if (null == infile)
                {
                    CCBLogConfig.GetLogger().Debug("No file data for {0}, ignoring file completion event.", filename);
                }
                else
                {
                    infile.OnFinalized(hash);
                    m_signal.Set();
                }
            }
            catch (IOException ioex)
            {
                CCBLogConfig.GetLogger().Error("IO Exception OnFileData {0}: {1}", filename, ioex.Message);
            }
            catch (Exception ex)
            {
                CCBLogConfig.GetLogger().Error("Exception OnFileData {0}: {1}", filename, ex.Message);
            }
        }
Esempio n. 3
0
        //We write the data directly on the networker thread. The reason is that if the write is fast, it's ok;
        //if it's slow, the file worker thread would back up while the chunks came in, leaving significant parts
        //of the file in memory. With only 2 threads, it's better to write the data out immediately. If the file
        //transfer system needs to scale up, this should be changed and more file worker threads should be added.
        void INetworkListener.OnFileData(string filename, long offset, byte[] data)
        {
            CCBLogConfig.GetLogger().Debug(string.Format("Receiving {0} bytes of {1}\n", data.Length, filename));
            try
            {
                CCBP2PFile infile = GetInFile(filename);

                if (null == infile)
                {
                    CCBLogConfig.GetLogger().Error("No file data for {0}, ignoring file data.", filename);
                }
                else
                {
                    infile.WriteData(offset, data);
                }
            }
            catch (IOException ioex)
            {
                CCBLogConfig.GetLogger().Error("IO Exception OnFileData {0}: {1}", filename, ioex.Message);
            }
            catch (Exception ex)
            {
                CCBLogConfig.GetLogger().Error("Exception OnFileData {0}: {1}", filename, ex.Message);
            }
        }
Esempio n. 4
0
        public void PrepareInFile(string sender, string recipient, string remoteFile, string localFile)
        {
            CCBP2PFile newFile = new CCBP2PFile(localFile, remoteFile, sender, recipient);

            lock (m_inbox)
            {
                m_inbox[remoteFile] = newFile;
            }
            MaybeStart();
        }
Esempio n. 5
0
        public void MarkDataSent(string filename, CCBP2PFileDataEnvelope data)
        {
            lock (m_outbox)
            {
                CCBP2PFile fileToSend = m_outbox[filename];

                if (null != fileToSend)
                {
                    fileToSend.MarkDataSent(data);
                }
            }
        }
Esempio n. 6
0
        public int RetrieveDataToSend(string filename, ref CCBP2PFileDataEnvelope data)
        {
            lock (m_outbox)
            {
                CCBP2PFile fileToSend = m_outbox[filename];

                if (null != fileToSend)
                {
                    return(fileToSend.RetrieveDataToSend(ref data));
                }
            }
            return(0);
        }
Esempio n. 7
0
        public TStatusUpdate GetFileStatus(string filename, out long cbXfer, out long cbMax)
        {
            cbXfer = 0;
            cbMax  = 0;
            lock (m_outbox)
            {
                if (m_outbox.Keys.Contains(filename))
                {
                    CCBP2PFile outfile = m_outbox[filename];

                    cbMax  = outfile.FileSize;
                    cbXfer = outfile.BytesSent;
                    return(TStatusUpdate.tsuFileWork);
                }
            }
            return(TStatusUpdate.tsuNone);
        }
Esempio n. 8
0
        private long LoadNext()
        {
            CCBP2PFile nextFileToLoad = GetNextFileToLoad();

            if (CCBSettings.m_simSlowIO)
            {
                Thread.Sleep(991);
            }
            if (null != nextFileToLoad)
            {
                //Do not load while file has data yet to be sent.
                if (!nextFileToLoad.HasDataToSend())
                {
                    return(nextFileToLoad.LoadNextBlob());
                }
            }
            return(0);
        }
Esempio n. 9
0
        public bool IsSent(string filename, ref byte[] hash, ref string recipient)
        {
            CCBP2PFile file = null;

            lock (m_outbox)
            {
                if (m_outbox.ContainsKey(filename))
                {
                    file = m_outbox[filename];
                }
            }
            if (null != file)
            {
                if (file.IsSent())
                {
                    hash = new byte[file.Hash.Length];
                    file.Hash.CopyTo(hash, 0);
                    recipient = file.Recipient;
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 10
0
        public string HasErrorFile(ref string sender, ref string recipient)
        {
            lock (m_outbox)
            {
                foreach (string filename in m_outbox.Keys)
                {
                    CCBP2PFile outfile = m_outbox[filename];

                    if (outfile.Error)
                    {
                        sender    = outfile.Sender;
                        recipient = outfile.Recipient;
                        //Remove object first, so we don't go in a tizzy when
                        //getting the notification back.
                        m_outbox.Remove(filename);
                        return(outfile.LocalName);
                    }
                }
            }
            lock (m_inbox)
            {
                foreach (string filename in m_inbox.Keys)
                {
                    CCBP2PFile infile = m_inbox[filename];

                    if (infile.Error)
                    {
                        sender    = infile.Sender;
                        recipient = infile.Recipient;
                        m_inbox.Remove(filename);
                        return(infile.RemoteName);
                    }
                }
            }
            return(null);
        }