public void SetPeerStatus(IPEndPoint peer, string status) { if (PeerStatuses.ContainsKey(peer)) { PeerStatuses[peer].ConnectionState = status; } }
/// <summary> /// Remove this station from the group! /// </summary> /// <param name="peer"> /// The address of the station to remove. /// </param> public void RemovePeer(IPEndPoint peer, Boolean disconnect) { Contract.Requires(peer != null); Contract.Ensures(!Peers.ContainsKey(peer)); if (Peers.Remove(peer)) { if (IsManager && disconnect) { // only the manager should send disconnect messages if (Logger != null) { Logger.Log("Sending disconnect command to station " + peer, Level.Info); } Communicator.Send(new DisconnectStationCommand(new IPEndPoint(Manager.Address, Manager.Port), peer), peer); AnnounceRemovePeer(peer); } PeerStatuses.Remove(peer); if (Logger != null) { Logger.Log("Station " + peer + " removed from peer list.", Level.Info); } if (!EnoughStations) { UI.NotEnoughPeers(); } UI.RefreshPeers(); } else if (peer.Equals(Address)) { // we are the peer being disconnected if (Logger != null) { Logger.Log("This station has been disconnected by the manager.", Level.Info); } UI.StationRemoved(); } else { if (Logger != null) { Logger.Log("Attempt to remove nonexistent peer " + peer, Level.Error); } } }
/// <summary> /// Add this station to the group! /// </summary> /// <param name="peer"> /// The address of the station to add. /// </param> /// <param name="peerPublicAsymmetricKey"> /// The public AsymmetricKey of the station to add. /// </param> public void AddPeer(IPEndPoint peer, AsymmetricKey peerPublicAsymmetricKey) { Contract.Requires(peer != null); Contract.Requires(!Peers.ContainsKey(peer)); Contract.Ensures(Peers.ContainsKey(peer)); Peers.Add(peer, peerPublicAsymmetricKey); if (PeerStatuses.ContainsKey(peer)) { PeerStatuses[peer].ConnectionState = "Connected"; } else { PeerStatuses.Add(peer, new StationStatus(peer, Communicator.GetIdentifyingStringForStation(peer), "Connected")); } if (EnoughStations) { UI.EnoughPeers(); } if (Logger != null) { Logger.Log("Peer added: " + peer, Level.Info); } }