private bool Authenticate(ReplicationPacket p)
 {
     uint pwd = uint.Parse(p.passwordhash);
     bool auth = false;
     foreach (var w in _config.Where)
     {
         uint hash = Helper.MurMur.Hash(Helper.GetBytes(w.BranchName + "|" + w.Password));
         if (hash == pwd) auth = true;
     }
     if (auth == false)
         _log.Debug("Authentication failed for '" + p.branchname + "' hash = " + p.passwordhash);
     return auth;
 }
        private string CreatePackageForSend(ReplicationPacket packet, out int last)
        {
            int maxc = INTERNALLIMIT;
            WhatItem what = GetBranchConfig(packet.branchname).what;
            if (what.PackageItemLimit > 0)
                maxc = what.PackageItemLimit;
            string outFolder = _OutboxPath;
            int packageNumber = packet.lastrecord;
            int i = packet.lastrecord;
            string filename = outFolder + _S + packet.branchname + _S + packageNumber.ToString("0000000000") + ".mgdat";

            if (i < _docs.RecordCount())
            {
                StorageFile<Guid> package = new StorageFile<Guid>(filename, SF_FORMAT.JSON, true);
                while (maxc > 0)
                {
                    var meta = _docs.GetMeta(i);
                    if (meta == null)
                        break;
                    if (meta.isReplicated == false && MatchType(meta.typename, what))
                    {
                        if (meta.isDeleted == false || what.PropogateHQDeletes)
                        {
                            object obj = _docs.GetObject(i, out meta);
                            package.WriteObject(meta.key, obj);
                            maxc--;
                        }
                    }

                    i++;
                }
                package.Shutdown();
                packageNumber++;
                // compress the file
                using (FileStream read = File.OpenRead(filename))
                using (FileStream outp = File.Create(filename + ".gz"))
                    CompressForBackup(read, outp);

                // delete uncompressed file
                File.Delete(filename);
            }

            last = i;
            return filename + ".gz";
        }
Example #3
0
        private bool Authenticate(ReplicationPacket p)
        {
            uint pwd  = uint.Parse(p.passwordhash);
            bool auth = false;

            foreach (var w in _config.Where)
            {
                uint hash = Helper.MurMur.Hash(Helper.GetBytes(w.BranchName + "|" + w.Password));
                if (hash == pwd)
                {
                    auth = true;
                }
            }
            if (auth == false)
            {
                _log.Debug("Authentication failed for '" + p.branchname + "' hash = " + p.passwordhash);
            }
            return(auth);
        }
        private ReplicationPacket GetPackageForBranch(ReplicationPacket packet)
        {
            int last = _branchLastDocs[packet.branchname.ToLower()];

            // skip retry for the same package
            if (packet.lastrecord >= _branchLastDocs[packet.branchname.ToLower()])
            {
                string            fn = CreatePackageForSend(packet, out last);
                ReplicationPacket p  = new ReplicationPacket();
                p.filename   = Path.GetFileName(fn);
                p.data       = File.ReadAllBytes(fn);
                p.datahash   = Helper.MurMur.Hash((byte[])p.data);
                p.lastrecord = last;
                return(p);
            }
            else
            {
                return(null);
            }
        }
 private ReplicationPacket GetPackageForBranch(ReplicationPacket packet)
 {
     int last = _branchLastDocs[packet.branchname.ToLower()];
     // skip retry for the same package
     if (packet.lastrecord >= _branchLastDocs[packet.branchname.ToLower()])
     {
         string fn = CreatePackageForSend(packet, out last);
         ReplicationPacket p = new ReplicationPacket();
         p.filename = Path.GetFileName(fn);
         p.data = File.ReadAllBytes(fn);
         p.datahash = Helper.MurMur.Hash((byte[])p.data);
         p.lastrecord = last;
         return p;
     }
     else
         return null;
 }
 private bool PackageForHQ(ReplicationPacket p)
 {
     uint hash = Helper.MurMur.Hash((byte[])p.data);
     if (hash != p.datahash)
         return false;
     // save file to \replication\inbox\branchname
     Directory.CreateDirectory(_InboxPath + _S + p.branchname);
     string fn = _InboxPath + _S + p.branchname + _S + p.filename;
     _log.Debug("package recieved from : " + p.branchname);
     _log.Debug("package name : " + p.filename);
     _log.Debug("package size : " + (p.data as byte[]).Length.ToString("#,0"));
     File.WriteAllBytes(fn, (byte[])p.data);
     return true;
 }
 private ReplicationPacket createpacket()
 {
     ReplicationPacket p = new ReplicationPacket();
     p.branchname = _config.BranchName;
     p.passwordhash = Helper.MurMur.Hash(Helper.GetBytes(_config.BranchName + "|" + _config.Password)).ToString();
     return p;
 }