Ejemplo n.º 1
0
 public void clean()
 {
     while (true)
     {
         if (DBTransferManager.getManager(null) != null)
         {
             doCleanup();
         }
         const int MIN = 60, SEC = 1000;
         System.Threading.Thread.Sleep(2 * MIN * SEC);
     }
 }
Ejemplo n.º 2
0
 public static DBTransferManager getManager(DBServer srv)
 {
     if (instance == null)
     {
         if (srv == null)
         {
             return(null);
         }
         else
         {
             instance = new DBTransferManager(srv);
         }
     }
     return(instance);
 }
Ejemplo n.º 3
0
 private void doCleanup()
 {
     lock (activeLocks)
     {
         List <String> dropKey = new List <String>();
         foreach (String key in activeLocks.Keys)
         {
             Lock l = activeLocks[key];
             if (l.isWriteLock)
             {
                 if (l.lockCreation.AddMinutes(W_TIMEOUT).CompareTo(new DateTime()) < 0)
                 {
                     if (DBTransferManager.getManager(null).abortDownload(key))
                     {
                         dropKey.Add(key);
                         //activeLocks.Remove(key);
                     }
                     else
                     {
                         l.lockCreation = l.lockCreation.AddMinutes(W_TIMEOUT);
                     }
                 }
             }
             else
             {
                 if (l.lockCreation.AddMinutes(R_TIMEOUT).CompareTo(new DateTime()) < 0)
                 {
                     dropKey.Add(key);
                     //((ILocks)(this)).releaseReadLock(key);
                     //activeLocks.Remove(key);
                 }
             }
         } //forEach
         ILocks ilock = (ILocks)this;
         foreach (string s in dropKey)
         {
             Lock l = activeLocks[s];
             if (l.isWriteLock)
             {
                 ilock.releaseWriteLock(s);
             }
             else
             {
                 ilock.releaseReadLock(s);
             }
         }
     } //lock
 }
Ejemplo n.º 4
0
        private string doUpload(string line)
        {
            if (!isLoggedIn())
            {
                return(MESSAGES.ERR);
            }
            long   filesize, timestamp;
            string md5, oldmd5;

            try
            {
                line = fetchLong(line, out timestamp, ' ');
                line = fetchString(line, out md5, ' ');
                line = fetchLong(line, out filesize, ' ');
            }
            catch (Exception)
            {
                return(MESSAGES.ERR);
            }
            try
            {
                line = fetchString(line, out oldmd5, ' ');
            }
            catch (ArgumentException)
            {
                Console.WriteLine("no old hash");
                oldmd5 = null;
            }

            String[] tokens = line.Split(path_sep);
            if (tokens.Length != 2)
            {
                return(MESSAGES.ERR);
            }
            String containerName = tokens[0];
            String path          = tokens[1];

            //String lengthStr = tokens[2];
            // no longer need to reject files of zero size
            if (filesize > DBServer.MAX_FILE_SIZE)
            {
                return(MESSAGES.E_BADFILESIZE);
            }

            /*
             * if (md5.Length != MD5LENGTH)
             * {
             *  Console.WriteLine("md5length fail, this is nyi");
             *  //return MESSAGES.ERR;
             * }*/
            if (timestamp < 0)
            {
                return("ERR_TIMESTAMP_TOO_OLD");
            }
            DateTimeOffset fileStamp = new DateTimeOffset(new DateTime(timestamp, DateTimeKind.Utc));

            //new DateTimeOffset()

            /*
             * if (fileStamp.CompareTo(new DateTimeOffset().AddMinutes(5)) > 0)
             * {
             *  return "ERR_TIMESTAMP_IN_FUTURE";
             * }*/

            Services.UPLOAD_INFO f = new Services.UPLOAD_INFO();
            f.username = this.loggedInUsername;

            //f.path = containerName + ":" + path;
            f.path     = line;
            f.sz       = filesize;
            f.utcTime  = fileStamp;
            f.curHash  = md5;
            f.prevHash = oldmd5;
            f.absPath  = makeAbsPath(f.username, f.path);
            try
            {
                DBTransferManager mgr = DBTransferManager.getManager(srv);
                string            key = mgr.getDownloadKey(f);
                if (srv.getLocks().acquireWriteLock(f.absPath))
                {
                    Console.WriteLine("Acquired global write lock");
                    return(MESSAGES.OK + " " + key);
                }
                else
                {
                    mgr.revokeKey(key);
                    Console.WriteLine("Global write lock was denied");
                    return(MESSAGES.E_LOCK);
                }
            }
            catch (Exception e)
            {
                //details not settled yet
                if (e is DBLikeExceptions.UnauthorizedAccessException)
                {
                    return(MESSAGES.E_NOACCESS);
                }
                if (e is DBLikeExceptions.CloudContainerNotFoundException)
                {
                    return(MESSAGES.E_NOFOLDER);
                }
                if (e is DBLikeExceptions.HashConflictException)
                {
                    return(MESSAGES.E_CONFLICT);
                }
                Console.WriteLine(e);
                return(MESSAGES.ERR);
            }
        }