Ejemplo n.º 1
0
        public T CalculateResponsible(Guid guid)
        {
            byte[] guidBytes       = guid.ToByteArray();
            uint   uniformHashCode = JenkinsHash.ComputeHash(guidBytes);

            return(CalculateResponsible(uniformHashCode));
        }
Ejemplo n.º 2
0
 public override void Write(BinaryWriter bw)
 {
     bw.Write(JenkinsHash.getHash32(this.Class));
     bw.Write(JenkinsHash.getHash32(this.RowName));
     bw.Write(0);
     bw.Write(this.Factor);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a subscriptionId that is unique per grainId, grainType, namespace combination.
        /// </summary>
        private Guid MakeSubscriptionGuid(GrainType grainType, InternalChannelId channelId)
        {
            // next 2 shorts inc guid are from namespace hash
            var namespaceHash     = JenkinsHash.ComputeHash(channelId.GetNamespace());
            var namespaceHashByes = BitConverter.GetBytes(namespaceHash);
            var s1 = BitConverter.ToInt16(namespaceHashByes, 0);
            var s2 = BitConverter.ToInt16(namespaceHashByes, 2);

            // Tailing 8 bytes of the guid are from the hash of the channelId Guid and a hash of the provider name.
            // get channelId guid hash code
            var channelIdGuidHash = JenkinsHash.ComputeHash(channelId.ChannelId.Key.Span);
            // get provider name hash code
            var providerHash = JenkinsHash.ComputeHash(channelId.ProviderName);

            // build guid tailing 8 bytes from grainIdHash and the hash of the provider name.
            var tail = new List <byte>();

            tail.AddRange(BitConverter.GetBytes(channelIdGuidHash));
            tail.AddRange(BitConverter.GetBytes(providerHash));

            // make guid.
            // - First int is grain type
            // - Two shorts from namespace hash
            // - 8 byte tail from channelId Guid and provider name hash.
            var id     = new Guid((int)JenkinsHash.ComputeHash(grainType.ToString()), s1, s2, tail.ToArray());
            var result = MarkSubscriptionGuid(id, isImplicitSubscription: true);

            return(result);
        }
Ejemplo n.º 4
0
        private Guid GenerateDeterministicGuid(QueueId queueId)
        {
            // provider name hash code
            JenkinsHash jenkinsHash          = JenkinsHash.Factory.GetHashGenerator();
            int         providerNameGuidHash = (int)jenkinsHash.ComputeHash(providerName);

            // get queueId hash code
            uint queueIdHash = queueId.GetUniformHashCode();

            byte[] queIdHashByes = BitConverter.GetBytes(queueIdHash);
            short  s1            = BitConverter.ToInt16(queIdHashByes, 0);
            short  s2            = BitConverter.ToInt16(queIdHashByes, 2);

            // build guid tailing 8 bytes from providerNameGuidHash and queIdHashByes.
            var tail = new List <byte>();

            tail.AddRange(BitConverter.GetBytes(providerNameGuidHash));
            tail.AddRange(queIdHashByes);

            // make guid.
            // - First int is provider name hash
            // - Two shorts from queue Id hash
            // - 8 byte tail from provider name hash and queue Id hash.
            return(new Guid(providerNameGuidHash, s1, s2, tail.ToArray()));
        }
Ejemplo n.º 5
0
        public VLTTypeResolver()
        {
            this._typeTable = new Dictionary <uint, Type>();
            this._typeTable.Add(JenkinsHash.getHash32("EA::Reflection::Double"), typeof(EADouble));
            this._typeTable.Add(JenkinsHash.getHash32("EA::Reflection::Float"), typeof(EAFloat));
            this._typeTable.Add(JenkinsHash.getHash32("EA::Reflection::UInt8"), typeof(EAUInt8));
            this._typeTable.Add(JenkinsHash.getHash32("EA::Reflection::UInt16"), typeof(EAUInt16));
            this._typeTable.Add(JenkinsHash.getHash32("EA::Reflection::UInt32"), typeof(EAUInt32));
            this._typeTable.Add(JenkinsHash.getHash32("EA::Reflection::UInt64"), typeof(EAUInt64));
            this._typeTable.Add(JenkinsHash.getHash32("EA::Reflection::Int8"), typeof(EAInt8));
            this._typeTable.Add(JenkinsHash.getHash32("EA::Reflection::Int16"), typeof(EAInt16));
            this._typeTable.Add(JenkinsHash.getHash32("EA::Reflection::Int32"), typeof(EAInt32));
            this._typeTable.Add(JenkinsHash.getHash32("EA::Reflection::Int64"), typeof(EAInt64));
            this._typeTable.Add(JenkinsHash.getHash32("EA::Reflection::Bool"), typeof(EABool));
            this._typeTable.Add(JenkinsHash.getHash32("EA::Reflection::Text"), typeof(EAText));

            this._typeTable.Add(JenkinsHash.getHash32("Attrib::Types::Matrix"), typeof(AttribMatrix));
            this._typeTable.Add(JenkinsHash.getHash32("Attrib::Types::Vector2"), typeof(AttribVector2));
            this._typeTable.Add(JenkinsHash.getHash32("Attrib::Types::Vector3"), typeof(AttribVector3));
            this._typeTable.Add(JenkinsHash.getHash32("Attrib::Types::Vector4"), typeof(AttribVector4));
            this._typeTable.Add(JenkinsHash.getHash32("Attrib::RefSpec"), typeof(AttribRefSpec));
            this._typeTable.Add(JenkinsHash.getHash32("Attrib::Blob"), typeof(AttribBlob));

#if CARBON
            this._typeTable.Add(JenkinsHash.getHash32("Attrib::StringKey"), typeof(AttribStringKeyCarbon));
#else
            this._typeTable.Add(JenkinsHash.getHash32("Attrib::StringKey"), typeof(AttribStringKey));
#endif

            this._typeTable.Add(JenkinsHash.getHash32("AxlePair"), typeof(AxlePair));
            this._typeTable.Add(JenkinsHash.getHash32("CarBodyMotion"), typeof(CarBodyMotion));
            this._typeTable.Add(JenkinsHash.getHash32("GCollectionKey"), typeof(GCollectionKey));
            this._typeTable.Add(JenkinsHash.getHash32("JunkmanMod"), typeof(JunkmanMod));
            this._typeTable.Add(JenkinsHash.getHash32("UpgradeSpecs"), typeof(UpgradeSpecs));
        }
Ejemplo n.º 6
0
 private VltTypeMap()
 {
     _typeDictionary =
         new Dictionary <uint, Type>
     {
         { JenkinsHash.getHash32("EA::Reflection::Int8"), typeof(EaInt8) },
         { JenkinsHash.getHash32("EA::Reflection::Int16"), typeof(EaInt16) },
         { JenkinsHash.getHash32("EA::Reflection::Int32"), typeof(EaInt32) },
         { JenkinsHash.getHash32("EA::Reflection::Int64"), typeof(EaInt64) },
         { JenkinsHash.getHash32("EA::Reflection::UInt8"), typeof(EaUInt8) },
         { JenkinsHash.getHash32("EA::Reflection::UInt16"), typeof(EaUInt16) },
         { JenkinsHash.getHash32("EA::Reflection::UInt32"), typeof(EaUInt32) },
         { JenkinsHash.getHash32("EA::Reflection::UInt64"), typeof(EaUInt64) },
         { JenkinsHash.getHash32("EA::Reflection::Bool"), typeof(EaBoolean) },
         { JenkinsHash.getHash32("EA::Reflection::Float"), typeof(EaFloat) },
         { JenkinsHash.getHash32("EA::Reflection::Double"), typeof(EaDouble) },
         { JenkinsHash.getHash32("EA::Reflection::Text"), typeof(EaText) },
         { JenkinsHash.getHash32("Attrib::RefSpec"), typeof(RefSpec) },
         { JenkinsHash.getHash32("Attrib::StringKey"), typeof(StringKey) },
         { JenkinsHash.getHash32("Attrib::Types::Matrix"), typeof(Matrix) },
         { JenkinsHash.getHash32("Attrib::Types::Vector2"), typeof(Vector2) },
         { JenkinsHash.getHash32("Attrib::Types::Vector3"), typeof(Vector3) },
         { JenkinsHash.getHash32("Attrib::Types::Vector4"), typeof(Vector4) },
         { JenkinsHash.getHash32("Attrib::Blob"), typeof(Blob) },
         { JenkinsHash.getHash32("GCollectionKey"), typeof(CollectionKey) },
         { JenkinsHash.getHash32("AirSupport"), typeof(AirSupport) },
         { JenkinsHash.getHash32("AxlePair"), typeof(AxlePair) },
     };
 }
Ejemplo n.º 7
0
 public QueueProperties(string @namespace, uint partitionId = 0)
 {
     Namespace   = @namespace;
     PartitionId = partitionId;
     QueueName   = $"{@namespace}_{partitionId.ToString()}";
     Hash        = JenkinsHash.ComputeHash(@namespace);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Create a subscriptionId that is unique per grainId, grainType, namespace combination.
        /// </summary>
        private Guid MakeSubscriptionGuid(GrainType grainType, InternalStreamId streamId)
        {
            // next 2 shorts inc guid are from namespace hash
            uint namespaceHash = JenkinsHash.ComputeHash(streamId.GetNamespace());

            byte[] namespaceHashByes = BitConverter.GetBytes(namespaceHash);
            short  s1 = BitConverter.ToInt16(namespaceHashByes, 0);
            short  s2 = BitConverter.ToInt16(namespaceHashByes, 2);

            // Tailing 8 bytes of the guid are from the hash of the streamId Guid and a hash of the provider name.
            // get streamId guid hash code
            uint streamIdGuidHash = JenkinsHash.ComputeHash(streamId.StreamId.Key.Span);
            // get provider name hash code
            uint providerHash = JenkinsHash.ComputeHash(streamId.ProviderName);

            // build guid tailing 8 bytes from grainIdHash and the hash of the provider name.
            var tail = new List <byte>();

            tail.AddRange(BitConverter.GetBytes(streamIdGuidHash));
            tail.AddRange(BitConverter.GetBytes(providerHash));

            // make guid.
            // - First int is grain type
            // - Two shorts from namespace hash
            // - 8 byte tail from streamId Guid and provider name hash.
            var id     = new Guid((int)JenkinsHash.ComputeHash(grainType.ToString()), s1, s2, tail.ToArray());
            var result = SubscriptionMarker.MarkAsImplictSubscriptionId(id);

            return(result);
        }
Ejemplo n.º 9
0
        private List <uint> GetUniformHashCodesImpl(int numHashes)
        {
            Span <byte> bytes = stackalloc byte[16 + sizeof(int) + sizeof(int) + sizeof(int)]; // ip + port + generation + extraBit

            // Endpoint IP Address
            var address = Endpoint.Address;

            if (address.AddressFamily == AddressFamily.InterNetwork) // IPv4
            {
#pragma warning disable CS0618                                       // Type or member is obsolete
                BinaryPrimitives.WriteInt32LittleEndian(bytes.Slice(12), (int)address.Address);
#pragma warning restore CS0618
                bytes.Slice(0, 12).Clear();
            }
            else // IPv6
            {
                address.GetAddressBytes().CopyTo(bytes);
            }
            var offset = 16;
            // Port
            BinaryPrimitives.WriteInt32LittleEndian(bytes.Slice(offset), Endpoint.Port);
            offset += sizeof(int);
            // Generation
            BinaryPrimitives.WriteInt32LittleEndian(bytes.Slice(offset), Generation);
            offset += sizeof(int);

            var hashes = new List <uint>(numHashes);
            for (int extraBit = 0; extraBit < numHashes; extraBit++)
            {
                BinaryPrimitives.WriteInt32LittleEndian(bytes.Slice(offset), extraBit);
                hashes.Add(JenkinsHash.ComputeHash(bytes));
            }
            return(hashes);
        }
Ejemplo n.º 10
0
 public uint GetUniformHashCode()
 {
     if (uniformHashCache == 0)
     {
         JenkinsHash jenkinsHash   = JenkinsHash.Factory.GetHashGenerator();
         byte[]      guidBytes     = Guid.ToByteArray();
         byte[]      providerBytes = Encoding.UTF8.GetBytes(ProviderName);
         byte[]      allBytes;
         if (Namespace == null)
         {
             allBytes = new byte[guidBytes.Length + providerBytes.Length];
             Array.Copy(guidBytes, allBytes, guidBytes.Length);
             Array.Copy(providerBytes, 0, allBytes, guidBytes.Length, providerBytes.Length);
         }
         else
         {
             byte[] namespaceBytes = Encoding.UTF8.GetBytes(Namespace);
             allBytes = new byte[guidBytes.Length + providerBytes.Length + namespaceBytes.Length];
             Array.Copy(guidBytes, allBytes, guidBytes.Length);
             Array.Copy(providerBytes, 0, allBytes, guidBytes.Length, providerBytes.Length);
             Array.Copy(namespaceBytes, 0, allBytes, guidBytes.Length + providerBytes.Length, namespaceBytes.Length);
         }
         uniformHashCache = jenkinsHash.ComputeHash(allBytes);
     }
     return(uniformHashCache);
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Create a subscriptionId that is unique per grainId, grainType, namespace combination.
        /// </summary>
        /// <param name="grainIdTypeCode"></param>
        /// <param name="streamId"></param>
        /// <returns></returns>
        private Guid MakeSubscriptionGuid(int grainIdTypeCode, StreamId streamId)
        {
            // next 2 shorts ing guid are from namespace hash
            uint namespaceHash = JenkinsHash.ComputeHash(streamId.Namespace);

            byte[] namespaceHashByes = BitConverter.GetBytes(namespaceHash);
            short  s1 = BitConverter.ToInt16(namespaceHashByes, 0);
            short  s2 = BitConverter.ToInt16(namespaceHashByes, 2);

            // Tailing 8 bytes of the guid are from the hash of the streamId Guid and a hash of the provider name.
            // get streamId guid hash code
            uint streamIdGuidHash = JenkinsHash.ComputeHash(streamId.Guid.ToByteArray());
            // get provider name hash code
            uint providerHash = JenkinsHash.ComputeHash(streamId.ProviderName);

            // build guid tailing 8 bytes from grainIdHash and the hash of the provider name.
            var tail = new List <byte>();

            tail.AddRange(BitConverter.GetBytes(streamIdGuidHash));
            tail.AddRange(BitConverter.GetBytes(providerHash));

            // make guid.
            // - First int is grain type
            // - Two shorts from namespace hash
            // - 8 byte tail from streamId Guid and provider name hash.
            return(SubscriptionMarker.MarkAsImplictSubscriptionId(new Guid(grainIdTypeCode, s1, s2, tail.ToArray())));
        }
Ejemplo n.º 12
0
        public T GetNode(string key)
        {
            var hash  = JenkinsHash.ComputeHash(Encoding.UTF8.GetBytes(key));
            int index = (int)(hash % _nodes.Length);

            return(_nodes[index]);
        }
Ejemplo n.º 13
0
 internal uint GetUniformHashCode()
 {
     // Disabling this ReSharper warning; hashCache is a logically read-only variable, so accessing them in GetHashCode is safe.
     // ReSharper disable NonReadonlyFieldInGetHashCode
     if (uniformHashCache == 0)
     {
         JenkinsHash jenkinsHash = JenkinsHash.Factory.GetHashGenerator();
         uint        n;
         if (HasKeyExt && KeyExt != null)
         {
             var writer = new BinaryTokenStreamWriter();
             writer.Write(this);
             byte[] bytes = writer.ToByteArray();
             writer.ReleaseBuffers();
             n = jenkinsHash.ComputeHash(bytes);
         }
         else
         {
             n = jenkinsHash.ComputeHash(TypeCodeData, N0, N1);
         }
         // Unchecked is required because the Jenkins hash is an unsigned 32-bit integer,
         // which we need to convert to a signed 32-bit integer.
         uniformHashCache = n;
     }
     return(uniformHashCache);
     // ReSharper restore NonReadonlyFieldInGetHashCode
 }
Ejemplo n.º 14
0
        public T CalculateResponsible(Guid guid)
        {
            JenkinsHash jenkinsHash = JenkinsHash.Factory.GetHashGenerator();

            byte[] guidBytes       = guid.ToByteArray();
            uint   uniformHashCode = jenkinsHash.ComputeHash(guidBytes);

            return(CalculateResponsible(uniformHashCode));
        }
Ejemplo n.º 15
0
        private uint GetUniformHashCode(JenkinsHash jenkinsHash, int extraBit)
        {
            var writer = new BinaryTokenStreamWriter();

            writer.Write(this);
            writer.Write(extraBit);
            byte[] bytes = writer.ToByteArray();
            return(jenkinsHash.ComputeHash(bytes));
        }
Ejemplo n.º 16
0
        public static void AddHash(string value)
        {
            var hash = JenkinsHash.getHash32(value);

            if (!Hashes.ContainsKey(hash))
            {
                Hashes[hash] = value;
            }
        }
Ejemplo n.º 17
0
        private void Validate(string file)
        {
            var   j    = new JenkinsHash();
            ulong hash = j.ComputeHash(file);

            if (TargetHashes.Contains(hash))
            {
                ResultStrings.Enqueue(file);
            }
        }
Ejemplo n.º 18
0
        private void CheckFieldName(string name)
        {
            int computedHash = JenkinsHash.GetHashCode(name);
            int hash         = this.reader.ReadInt32();

            if (computedHash != hash)
            {
                throw new InvalidOperationException("The field hash is not what was expected...");
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Performs the Jenkins hash on an input byte array
        /// </summary>
        public static byte[] JenkinsHash(byte[] input)
        {
            using (JenkinsHash jHash = new JenkinsHash())
            {
                byte[] hash = jHash.ComputeHash(input);
                Array.Reverse(hash);

                return(hash);
            }
        }
Ejemplo n.º 20
0
 private void Validate(IEnumerable <string> files)
 {
     Parallel.ForEach(files, x =>
     {
         ulong hash = new JenkinsHash().ComputeHash(x);
         if (Array.IndexOf(TargetHashes, hash, HashesLookup[hash & 0xFF], BucketSize) > -1)
         {
             ResultStrings.Enqueue(x);
             FileNames.Add(x);                     // add new files as we go
         }
     });
 }
Ejemplo n.º 21
0
        public static void AddAuto(string value)
        {
            uint key = JenkinsHash.getHash32(value);

            if (!_autoTable.ContainsKey(key))
            {
                _autoTable.Add(key, value);
                if (_loadTable.ContainsKey(key))
                {
                    _loadTable.Remove(key);
                }
            }
        }
Ejemplo n.º 22
0
        public static void addHashFromVLTDB(string A_0)
        {
            uint hash = JenkinsHash.getHash32(A_0);

            if (!HashTracker.hashesFromVLTFile.ContainsKey(hash))
            {
                HashTracker.hashesFromVLTFile[hash] = A_0;
                if (HashTracker.hashesFromTextFile.ContainsKey(hash))
                {
                    HashTracker.hashesFromTextFile.Remove(hash);
                }
            }
        }
Ejemplo n.º 23
0
        private void Validate(ref ConcurrentBag <string> files)
        {
            Parallel.ForEach(files, x =>
            {
                var j      = new JenkinsHash();
                ulong hash = j.ComputeHash(x);
                if (Array.IndexOf(TargetHashes, hash, HashesLookup[hash & 0xFF], BucketSize) > -1)
                {
                    ResultStrings.Enqueue(x);
                }
            });

            files = new ConcurrentBag <string>();
        }
Ejemplo n.º 24
0
        private void Validate(ref ConcurrentBag <string> files)
        {
            Parallel.ForEach(files, x =>
            {
                var j      = new JenkinsHash();
                ulong hash = j.ComputeHash(x);
                if (TargetHashes.Contains(hash))
                {
                    ResultStrings.Enqueue(x);
                }
            });

            files = new ConcurrentBag <string>();
        }
Ejemplo n.º 25
0
        private void Validate(IEnumerable <string> files)
        {
            Parallel.ForEach(files, x =>
            {
                ulong hash = new JenkinsHash().ComputeHash(x);
                if (TargetHashes.Contains(hash))
                {
                    ResultStrings.Enqueue(x);
                    FileNames.Add(x); // add new files as we go
                }

                x = null;
            });
        }
Ejemplo n.º 26
0
 public QueueProperties(
     string @namespace,
     uint partitionId          = 0,
     bool isExternal           = false,
     Type externalContractType = null
     )
 {
     Namespace            = @namespace;
     PartitionId          = partitionId;
     QueueName            = $"{@namespace}_{partitionId.ToString()}";
     Hash                 = JenkinsHash.ComputeHash(@namespace);
     IsExternal           = isExternal;
     ExternalContractType = externalContractType;
 }
Ejemplo n.º 27
0
        /// <summary>
        /// Open the Jenkins hash dialog.
        /// </summary>
        private async void DoJenkinsHashCommand()
        {
            var strToHash = await _dialogCoordinator.ShowInputAsync(this, "Jenkins Hash", "What would you like to hash?");

            if (string.IsNullOrWhiteSpace(strToHash))
            {
                return;
            }

            var hash32 = JenkinsHash.GetHash32(strToHash);
            var hash64 = JenkinsHash.GetHash64(strToHash);
            await _dialogCoordinator.ShowMessageAsync(this, "Hash Result",
                                                      $"The 32-bit Jenkins hash of \"{strToHash}\" is 0x{hash32:X8}.\nThe 64-bit Jenkins hash is 0x{hash64:X16}.");
        }
Ejemplo n.º 28
0
        public override int GetHashCode()
        {
            JenkinsHash hash = new JenkinsHash();

            hash.Mixin(VectorHelper.GetX(p0).GetHashCode());
            hash.Mixin(VectorHelper.GetY(p0).GetHashCode());
            hash.Mixin(VectorHelper.GetX(p1).GetHashCode());
            hash.Mixin(VectorHelper.GetY(p1).GetHashCode());
            hash.Mixin(VectorHelper.GetX(p2).GetHashCode());
            hash.Mixin(VectorHelper.GetY(p2).GetHashCode());
            hash.Mixin(VectorHelper.GetX(p3).GetHashCode());
            hash.Mixin(VectorHelper.GetY(p3).GetHashCode());
            return(hash.GetValue());
        }
Ejemplo n.º 29
0
        public void ID_HashCorrectness()
        {
            // This tests that our optimized Jenkins hash computes the same value as the reference implementation
            int testCount = 1000;

            for (int i = 0; i < testCount; i++)
            {
                byte[] byteData = new byte[24];
                random.NextBytes(byteData);
                ulong u1            = BitConverter.ToUInt64(byteData, 0);
                ulong u2            = BitConverter.ToUInt64(byteData, 8);
                ulong u3            = BitConverter.ToUInt64(byteData, 16);
                var   referenceHash = JenkinsHash.ComputeHash(byteData);
                var   optimizedHash = JenkinsHash.ComputeHash(u1, u2, u3);
                Assert.Equal(referenceHash, optimizedHash);   //  "Optimized hash value doesn't match the reference value for inputs {0}, {1}, {2}", u1, u2, u3
            }
        }
Ejemplo n.º 30
0
        private void Validate(string mask, byte[] maskoffsets)
        {
            char[] maskdata = mask.ToCharArray();

            // sanity check the results
            var j = new JenkinsHash();

            while (ResultQueue.Count > 0)
            {
                string s = StringGenerator.Generate(maskdata, ResultQueue.Dequeue(), maskoffsets, IsMirrored);
                ulong  h = j.ComputeHash(s);
                if (TargetHashes.Contains(h))
                {
                    ResultStrings.Add(s);
                }
            }
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Performs the Jenkins hash on an input byte array
        /// </summary>
        public static byte[] JenkinsHash( byte[] input )
        {
            using ( JenkinsHash jHash = new JenkinsHash() )
            {
                byte[] hash = jHash.ComputeHash( input );
                Array.Reverse( hash );

                return hash;
            }
        }