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)); }
private void UpdateNetworkStatusCallback(object state) { lock (_updateNetworkStatusLock) { if (_updateNetworkStatusRunning) { return; } _updateNetworkStatusRunning = true; _updateNetworkStatusTriggered = false; } try { BitChatNetworkStatus oldStatus = _networkStatus; //find network wide connected peer ep list List <PeerInfo> uniqueConnectedPeerList = new List <PeerInfo>(); List <Peer> onlinePeers = new List <Peer>(); List <Peer> offlinePeers = new List <Peer>(); lock (_peers) { foreach (Peer currentPeer in _peers) { if (currentPeer.IsOnline) { onlinePeers.Add(currentPeer); } else { offlinePeers.Add(currentPeer); } } } foreach (Peer onlinePeer in onlinePeers) { onlinePeer.UpdateUniqueConnectedPeerList(uniqueConnectedPeerList); } //find self connected & disconnected peer list List <PeerInfo> connectedPeerList; List <PeerInfo> disconnectedPeerList; connectedPeerList = _network.GetConnectedPeerList(); //update self connected list UpdateUniquePeerList(uniqueConnectedPeerList, connectedPeerList); //remove self from unique connected peer list PeerInfo selfPeerInfo = _network.GetSelfPeerInfo(); uniqueConnectedPeerList.Remove(selfPeerInfo); //update connected peer's network status foreach (Peer onlinePeer in onlinePeers) { onlinePeer.UpdateNetworkStatus(uniqueConnectedPeerList); } foreach (Peer offlinePeer in offlinePeers) { offlinePeer.SetNoNetworkStatus(); } //find disconnected list disconnectedPeerList = GetMissingPeerList(connectedPeerList, uniqueConnectedPeerList); //update disconnected peer's network status List <PeerInfo> dummyUniqueConnectedPeerList = new List <PeerInfo>(1); dummyUniqueConnectedPeerList.Add(selfPeerInfo); foreach (PeerInfo peerInfo in disconnectedPeerList) { //search all offline peers for comparison foreach (Peer offlinePeer in offlinePeers) { if (offlinePeer.PeerCertificate.IssuedTo.EmailAddress.Address.Equals(peerInfo.PeerEmail)) { offlinePeer.UpdateNetworkStatus(dummyUniqueConnectedPeerList); break; } } } BitChatNetworkStatus networkStatus; if (disconnectedPeerList.Count > 0) { networkStatus = BitChatNetworkStatus.PartialNetwork; _network.MakeConnection(disconnectedPeerList); } else { networkStatus = BitChatNetworkStatus.FullNetwork; } lock (_connectedPeerList) { _connectedPeerList.Clear(); _connectedPeerList.AddRange(connectedPeerList); _disconnectedPeerList = disconnectedPeerList; _networkStatus = networkStatus; } if (_network.Type == BitChatNetworkType.PrivateChat) { if (connectedPeerList.Count > 0) { _manager.PauseLocalAnnouncement(_network.NetworkID); StopTracking(); } else { _manager.ResumeLocalAnnouncement(_network.NetworkID); StartTracking(); } } else { if (connectedPeerList.Count > 0) { _manager.PauseLocalAnnouncement(_network.NetworkID); } else { _manager.ResumeLocalAnnouncement(_network.NetworkID); } } if (oldStatus != networkStatus) { _selfPeer.RaiseEventNetworkStatusUpdated(); } } catch { } finally { lock (_updateNetworkStatusLock) { if (_updateNetworkStatusTriggered) { _updateNetworkStatusTimer.Change(NETWORK_STATUS_TIMER_INTERVAL, Timeout.Infinite); } else { _updateNetworkStatusTriggered = false; if (_networkStatus == BitChatNetworkStatus.PartialNetwork) { _reCheckNetworkStatusTimer.Change(NETWORK_STATUS_RECHECK_TIMER_INTERVAL, Timeout.Infinite); } } _updateNetworkStatusRunning = false; } } }