public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) { return(false); } if (ReferenceEquals(this, obj)) { return(true); } PeerInfo objPeerInfo = obj as PeerInfo; return(_peerEmail.Equals(objPeerInfo._peerEmail)); }
public bool Equals(PeerInfo obj) { if (ReferenceEquals(null, obj)) { return(false); } if (ReferenceEquals(this, obj)) { return(true); } if (!_peerEP.Equals(obj._peerEP)) { return(false); } if (!_networkID.Equals(obj._networkID)) { return(false); } return(true); }
private void listener_ReceivedPacket(DiscoveryPacket packet, IPAddress remotePeerIP) { if (packet.IsResponse) { #region response process lock (_queryPacketCache) { int i = _queryPacketCache.IndexOf(packet); if (i < 0) { return; } DiscoveryPacket queryPacket = _queryPacketCache[i]; if (queryPacket.IsExpired()) { return; } } BinaryNumber foundNetworkID = null; lock (_announceNetworkIDs) { foreach (BinaryNumber networkID in _announceNetworkIDs) { if (packet.IsResponseValid(networkID, remotePeerIP)) { foundNetworkID = networkID; break; } } } if (foundNetworkID != null) { IPEndPoint peerEP = new IPEndPoint(remotePeerIP, packet.ServicePort); PeerInfo peerInfo = new PeerInfo(peerEP, foundNetworkID); bool peerInCache; lock (_peerInfoCache) { if (_peerInfoCache.Contains(peerInfo)) { PeerInfo existingPeerInfo = _peerInfoCache[_peerInfoCache.IndexOf(peerInfo)]; if (existingPeerInfo.IsExpired()) { peerInCache = false; _peerInfoCache.Remove(existingPeerInfo); } else { peerInCache = true; } } else { peerInCache = false; } } if (!peerInCache) { lock (_peerInfoCache) { _peerInfoCache.Add(peerInfo); } PeerDiscovered(this, peerEP, foundNetworkID); } } #endregion } else { #region query process BinaryNumber foundNetworkID = null; lock (_trackedNetworkIDs) { foreach (BinaryNumber networkID in _trackedNetworkIDs) { if (packet.IsThisNetwork(networkID)) { foundNetworkID = networkID; break; } } } if (foundNetworkID != null) { SendResponse(packet, foundNetworkID, remotePeerIP); } #endregion } }