Пример #1
0
        /// <summary>
        /// Generates a <see cref="IContact"/> for a node.
        /// </summary>
        /// <returns></returns>
        public static IContact GetContact()
        {
            if (_contact != null)
            {
                return(_contact);
            }

            Config config = Config.ReadConfig();
            string nodeId = config.Kademlia.NodeId;

            if (!string.IsNullOrEmpty(nodeId))
            {
                return(new Contact(Transport.GetServiceBaseUrl(), nodeId));
            }

            string   publicIp         = EnvironmentHelper.GetPublicIp();
            string   localIp          = EnvironmentHelper.GetLocalIp();
            string   machineName      = EnvironmentHelper.GetFqdn();
            FileInfo assemblyFileInfo = AssemblyHelper.GetEntryAssemblyFileInfo();
            string   directory        = assemblyFileInfo.DirectoryName;
            string   applicationId    = AppSettings.InstanceMode == InstanceMode.Single ?
                                        AssemblyHelper.GetEntryAssemblyId() :
                                        EncryptionProvider.GetString(GetRandomKey());

            string uniqueAttributes = string.Format("{0}#{1}#{2}#{3}#{4}", publicIp, localIp, machineName, directory, applicationId);

            nodeId = EncryptionProvider.Hash(uniqueAttributes);

            return(_contact = new Contact(Transport.GetServiceBaseUrl(), nodeId));
        }
Пример #2
0
 /// <summary>
 /// Computes the unique key of the <see cref="Type"/>.
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public static string Key(this Type type)
 {
     return(EncryptionProvider.Hash(type.AssemblyQualifiedName()));
 }