GetHashCode() public method

public GetHashCode ( ) : int
return int
コード例 #1
0
 public ClientTransport(IPEndPoint ip, int minRpc, int maxRpc, float packetDropRate)
 {
     _random = new Random(ip.GetHashCode());
     _minRpc = minRpc;
     _maxRpc = maxRpc;
     _packetDropRate = packetDropRate;
 }
コード例 #2
0
ファイル: ConnectorI.cs プロジェクト: bholl/zeroc-ice
        //
        // Only for use by EndpointI.
        //
        internal ConnectorI(Instance instance, string host, IPEndPoint addr, int timeout, string connectionId)
        {
            _instance = instance;
            _host = host;
            _logger = instance.communicator().getLogger();
            _addr = addr;
            _timeout = timeout;
            _connectionId = connectionId;

            _hashCode = _addr.GetHashCode();
            _hashCode = 5 * _hashCode + _timeout;
            _hashCode = 5 * _hashCode + _connectionId.GetHashCode();
        }
コード例 #3
0
ファイル: TcpConnector.cs プロジェクト: bholl/zeroc-ice
        //
        // Only for use by TcpEndpoint
        //
        internal TcpConnector(Instance instance, IPEndPoint addr, int timeout, string connectionId)
        {
            _instance = instance;
            _traceLevels = instance.traceLevels();
            _logger = instance.initializationData().logger;
            _addr = addr;
            _timeout = timeout;
            _connectionId = connectionId;

            _hashCode = _addr.GetHashCode();
            _hashCode = 5 * _hashCode + _timeout;
            _hashCode = 5 * _hashCode + _connectionId.GetHashCode();
        }
コード例 #4
0
 public Server GetAServer(IStrategyCallerType type, IPEndPoint localIPEndPoint)
 {
     var configs = _controller.GetCurrentConfiguration().configs;
     int index;
     if (type == IStrategyCallerType.TCP)
     {
         index = _random.Next();
     }
     else
     {
         index = localIPEndPoint.GetHashCode();
     }
     return configs[index % configs.Count];
 }
コード例 #5
0
ファイル: UdpConnector.cs プロジェクト: bholl/zeroc-ice
        //
        // Only for use by TcpEndpoint
        //
        internal UdpConnector(Instance instance, IPEndPoint addr, string mcastInterface, int mcastTtl,
                              byte protocolMajor, byte protocolMinor, byte encodingMajor, byte encodingMinor,
                              string connectionId)
        {
            instance_ = instance;
            _addr = addr;
            _mcastInterface = mcastInterface;
            _mcastTtl = mcastTtl;
            _protocolMajor = protocolMajor;
            _protocolMinor = protocolMinor;
            _encodingMajor = encodingMajor;
            _encodingMinor = encodingMinor;
            _connectionId = connectionId;

            _hashCode = _addr.GetHashCode();
            _hashCode = 5 * _hashCode + _mcastInterface.GetHashCode();
            _hashCode = 5 * _hashCode + _mcastTtl.GetHashCode();
            _hashCode = 5 * _hashCode + _connectionId.GetHashCode();
        }
コード例 #6
0
        public MFTestResults NetTest5_IPEndPointBasic()
        {
            /// <summary>
            /// 1. Creates 30 Random IPs between 0.0.0.0 and 255.255.255.127
            /// 2. Verifies that they can be constructed as IPEndPoints with both ctors
            /// 3. Verifies that their data, ToString and GetHashCode funcs return normally
            /// 4. Clones one with Create and verifies the above funcs again
            /// </summary>
            ///
            bool testResult = true;
            try
            {
                Random random = new Random();
                for (int i = 0; i <= 30; i++)
                {
                    int[] IPInts = { random.Next(256), random.Next(256), 
                        random.Next(256), random.Next(128) };
                    int portInt = random.Next(65535) + 1;
                    long addressLong = (long)(
                        IPInts[0]
                        + IPInts[1] * 256
                        + IPInts[2] * 256 * 256
                        + IPInts[3] * 256 * 256 * 256);
                    Log.Comment("Random IP " + IPInts[0] + "." + IPInts[1]
                        + "." + IPInts[2] + "." + IPInts[3] + ":" + portInt);
                    IPAddress address = new IPAddress(addressLong);

                    Log.Comment("EndPoint1 created with IPAddress and int");
                    IPEndPoint endPoint1 = new IPEndPoint(address,portInt);
                    Log.Comment("EndPoint2 created with long and int"); 
                    IPEndPoint endPoint2 = new IPEndPoint(addressLong, portInt);
                    if (endPoint1 == null)
                        throw new Exception("EndPoint1 is null");
                    if (endPoint2 == null)
                        throw new Exception("EndPoint2 is null");

                    Type typeOfEndPoint = endPoint1.GetType();
                    if (typeOfEndPoint != Type.GetType("System.Net.IPEndPoint"))
                        throw new Exception("EndPoint1 Type is incorrect");
                    typeOfEndPoint = endPoint2.GetType();
                    if (typeOfEndPoint != Type.GetType("System.Net.IPEndPoint"))
                        throw new Exception("EndPoint2 Type is incorrect");

                    if (endPoint1.ToString() != endPoint2.ToString())
                        throw new Exception("ToString returns differently for same data");

                    if (!endPoint1.Equals(endPoint2))
                    {
                        throw new Exception("Equals returns false for same data");
                    }


                    int hashCode1 = endPoint1.GetHashCode();
                    int hashCode2 = endPoint2.GetHashCode();


                    if (hashCode1 != hashCode2)
                        throw new Exception("GetHasCode returns differently for same data");

                    if (endPoint1.Address.ToString() != endPoint2.Address.ToString()
                        || endPoint1.Address.ToString() != address.ToString()
                        || endPoint2.Address.ToString() != address.ToString())
                        throw new Exception("Address returns wrong data");

                    if (endPoint1.Port != endPoint2.Port
                        || endPoint1.Port != portInt
                        || endPoint2.Port != portInt)
                        throw new Exception("Port returns wrong data");
                    
                    Log.Comment("Cloning Enpoint1 into EndPoint2");
                    endPoint2 = (IPEndPoint)endPoint2.Create(endPoint1.Serialize());
                    typeOfEndPoint = endPoint2.GetType();
                    if (typeOfEndPoint != Type.GetType("System.Net.IPEndPoint"))
                        throw new Exception("EndPoint2 Type is incorrect after clone");

                    if (endPoint1.ToString() != endPoint2.ToString())
                        throw new Exception("ToString returns differently for cloned data");


                    //21295	GetHashCode returns differently for cloned data
                    if (endPoint1.GetHashCode() != endPoint2.GetHashCode())
                        throw new Exception("GetHashCode returns differently for cloned data");

                    if (endPoint1.Address.ToString() != endPoint2.Address.ToString()
                        || endPoint1.Address.ToString() != address.ToString()
                        || endPoint2.Address.ToString() != address.ToString())
                        throw new Exception("Address returns wrong data after clone");

                    if (endPoint1.Port != endPoint2.Port
                        || endPoint1.Port != portInt
                        || endPoint2.Port != portInt)
                        throw new Exception("Port returns wrong data after clone");

                    Log.Comment("Recreating EndPoint2 with new data");
                    int portInt2 = portInt % 2 + 1;
                    long addressLong2 = (long)(
                        (IPInts[0] % 2 + 1)
                        + (IPInts[1] % 2 + 1 )* 256
                        + (IPInts[2] % 2 + 1 )* 256 * 256
                        + (IPInts[3] % 2 + 1 )* 256 * 256 * 256);
                    endPoint2 = new IPEndPoint(addressLong2, portInt2);

                    if (endPoint1.GetHashCode() == endPoint2.GetHashCode())
                        throw new Exception("GetHashCode returns same for " 
                            + endPoint1.ToString()
                            + " as " + endPoint2.ToString());

                    if (endPoint1.Address == endPoint2.Address
                        || endPoint2.Address == address)
                        throw new Exception("Address returns wrong data after change");

                    if (endPoint1.Port == endPoint2.Port
                        || endPoint2.Port == portInt)
                        throw new Exception("Port returns wrong data after change");
                }
            }
            catch (Exception e)
            {
                Log.Comment("Caught exception: " + e.Message);
                testResult = false;
            }
            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
コード例 #7
0
ファイル: Session.cs プロジェクト: kuchikios/Atheus
        /// <summary>
        /// Atheusネットワークへ参加します
        /// </summary>
        /// <param name="server">ホスト情報</param>
        public Session( IPEndPoint server )
            : this()
        {
            TcpClient tcp = new TcpClient( );
            tcp.ExclusiveAddressUse = true;
            tcp.NoDelay = true;

            Socket = tcp.Client;

            IPEndPoint = server;

            HashCode = IPEndPoint.GetHashCode( ) ^ Thread.GetHashCode( );

            Buffer = new byte[ Socket.ReceiveBufferSize ];
            Bufferd = new List<byte>( Buffer.Length );
        }
コード例 #8
0
ファイル: Server.cs プロジェクト: cphillips83/Raft.NET
 public Server(int volume, IPEndPoint id, Log log, ITransport transport)
 {
     //_config = config;
     Volume = volume;
     _id = id;
     _random = new Random((int)DateTime.UtcNow.Ticks ^ _id.GetHashCode());
     //_dataDir = dataDir;
     _currentState = new StoppedState(this);
     _transport = transport;
     _persistedStore = log;
 }
コード例 #9
0
ファイル: NetBase.cs プロジェクト: kindex/labyrinth2
        /// <summary>
        /// Stop any udp hole punching in progress towards ep
        /// </summary>
        public void CeaseHolePunching(IPEndPoint ep)
        {
            int hc = ep.GetHashCode();
            if (m_holePunches != null)
            {
                bool wasRemoved = false;
                do
                {
                    for (int i = 0; i < m_holePunches.Count; i++)
                    {
                        if (m_holePunches[i].GetHashCode() == hc)
                        {
                            m_holePunches.RemoveAt(i);
                            wasRemoved = true;
                            break;
                        }
                    }
                } while (m_holePunches.Count > 0 && wasRemoved);

                if (m_holePunches.Count == 0)
                    m_holePunches = null;
            }
        }
コード例 #10
0
ファイル: SipMessageWriter.cs プロジェクト: five-x/siprevo
		public void Write(IPEndPoint endpoint, Transports transport)
		{
			if (transport != Transports.Ws && transport != Transports.Wss)
				Write(endpoint);
			else
			{
				Write(C.i);
				Write((UInt32)endpoint.GetHashCode());
				Write(C._invalid);
			}
		}
コード例 #11
0
ファイル: NetServer.cs プロジェクト: TerenceWallace/bloodbox
		private NetConnection FindConnection(IPEndPoint endpoint)
		{
			NetConnection retval;
			if (m_connectionsLookUpTable.TryGetValue(endpoint.GetHashCode(), out retval))
				return retval;
			return null;

			/*
			for (int i = 0; i < Connections.Length; i++)
			{
				if (Connections[i] != null && Connections[i].Status != NetConnectionStatus.Disconnected && Connections[i].RemoteEndpoint.Equals(endpoint))
					return Connections[i];
			}
			return null;
			*/
		}
コード例 #12
0
ファイル: NetServer.cs プロジェクト: TerenceWallace/bloodbox
		internal NetConnection AddConnection(IPEndPoint remoteEndpoint, int remoteClockOffset)
		{
			// find empty slot
			for (int i = 0; i < Connections.Length; i++)
			{
				if (Connections[i] == null)
				{
					NetConnection conn = new NetConnection(this, remoteEndpoint);

					conn.RemoteClockOffset = remoteClockOffset;
					Log.Verbose("Initializing remote clock offset to " + remoteClockOffset + " ms");

					conn.m_firstSentHandshake = NetTime.Now;
					conn.m_lastSentHandshake = conn.m_firstSentHandshake;

					int hash = remoteEndpoint.GetHashCode();
					NetConnection existingConn;
					if (m_connectionsLookUpTable.TryGetValue(hash, out existingConn))
					{
						if (existingConn.Status != NetConnectionStatus.Disconnected)
							throw new NetException("Ack thphth; Connections lookup hash value taken!");

						// disconnected; just remove it
						RemoveConnection(existingConn);
					}

					Connections[i] = conn;

					m_connectionsLookUpTable[hash] = conn;

					conn.SetStatus(NetConnectionStatus.Connecting, "Connecting from " + remoteEndpoint);
					return conn;
				}
			}

			Log.Warning("Failed to add new connection!");
			return null;
		}
コード例 #13
0
ファイル: MyEndPoint.cs プロジェクト: Peng-Zhiyuan/mylib
 public override int GetHashCode()
 {
     return(mIPEndPoint.GetHashCode());
 }
コード例 #14
0
ファイル: NetBase.cs プロジェクト: JeffM2501/HackSharp
        /// <summary>
        /// Stop any udp hole punching in progress towards ep
        /// </summary>
        public void CeaseHolePunching(IPEndPoint ep)
        {
            if (ep == null)
                return;

            int hc = ep.GetHashCode();
            if (m_holePunches != null)
            {
                for (int i = 0; i < m_holePunches.Count; )
                {
                    if (m_holePunches[i] != null && m_holePunches[i].GetHashCode() == hc)
                    {
                        LogVerbose("Ceasing hole punching to " + m_holePunches[i]);
                        m_holePunches.RemoveAt(i);
                    }
                    else
                        i++;
                }
                if (m_holePunches.Count < 1)
                    m_holePunches = null;
            }
        }