Beispiel #1
0
        /// <summary>
        /// Construct new ZrePeer object
        /// </summary>
        /// <param name="container">The dictionary of peers</param>
        /// <param name="guid">The identity for this peer</param>
        /// <returns></returns>
        public static ZrePeer NewPeer(Dictionary <Guid, ZrePeer> container, Guid guid)
        {
            var peer = new ZrePeer(guid);

            container[guid] = peer; // overwrite any existing entry for same uuid
            return(peer);
        }
Beispiel #2
0
        /// <summary>
        /// We do this once a second:
        /// - if peer has gone quiet, send TCP ping and emit EVASIVE event
        /// - if peer has disappeared, expire it
        /// </summary>
        /// <param name="peer">the peer to ping</param>
        public void PingPeer(ZrePeer peer)
        {
            if (ZrePeer.CurrentTimeMilliseconds() >= peer.ExpiredAt)
            {
                RemovePeer(peer);
            }
            else if (ZrePeer.CurrentTimeMilliseconds() >= peer.EvasiveAt)
            {
                // If peer is being evasive, force a TCP ping.
                // ZeroMQTODO: do this only once for a peer in this state;
                // it would be nicer to use a proper state machine
                // for peer management.
                ZreMsg.SendPing(_outbox, 0);

                // Inform the calling application this peer is being evasive
                _outbox.SendMoreFrame("EVASIVE");
                _outbox.SendMoreFrame(peer.Uuid.ToByteArray());
                _outbox.SendFrame(peer.Name);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Have peer leave group
        /// </summary>
        /// <param name="peer"></param>
        /// <param name="groupName"></param>
        /// <returns></returns>
        public ZreGroup LeavePeerGroup(ZrePeer peer, string groupName)
        {
            var group = RequirePeerGroup(groupName);
            group.Leave(peer);

            // Now tell the caller about the peer left group
            _outbox.SendMoreFrame("LEAVE").SendMoreFrame(peer.Uuid.ToString()).SendMoreFrame(peer.Name).SendFrame(_name);
            return group;
        }
Beispiel #4
0
        /// <summary>
        /// Join peer to group
        /// </summary>
        /// <param name="peer">The peer that is joining thie group</param>
        /// <param name="groupName">The name of the group to join</param>
        /// <returns>the group joined</returns>
        public ZreGroup JoinPeerGroup(ZrePeer peer, string groupName)
        {
            var group = RequirePeerGroup(groupName);
            group.Join(peer);

            // Now tell the caller about the peer joined group
            _outbox.SendMoreFrame("JOIN").SendMoreFrame(peer.Uuid.ToString()).SendMoreFrame(peer.Name).SendFrame(_name);
            return group;
        }
Beispiel #5
0
        /// <summary>
        /// Remove a peer from our data structures
        /// </summary>
        /// <param name="peer"></param>
        public void RemovePeer(ZrePeer peer)
        {
            // Tell the calling application the peer has gone
            _outbox.SendMoreFrame("EXIT").SendMoreFrame(peer.Uuid.ToString()).SendFrame(peer.Name);

            // Remove peer from any groups we've got it in
            foreach (var peerGroup in _peerGroups.Values)
            {
                DeletePeer(peerGroup, peer);
            }

            // To destroy peer, we remove from peers hash table
            _peers.Remove(peer.Uuid);
        }
Beispiel #6
0
 /// <summary>
 /// Remove peer from group, if it's a member
 /// </summary>
 /// <param name="group"></param>
 /// <param name="peer"></param>
 public void DeletePeer(ZreGroup group, ZrePeer peer)
 {
     group.Leave(peer);
 }
Beispiel #7
0
 /// <summary>
 /// Delete peer for a given endpoint
 /// </summary>
 /// <param name="peer"></param>
 /// <param name="endpoint"></param>
 public void PurgePeer(ZrePeer peer, string endpoint)
 {
     if (peer.Endpoint == endpoint)
     {
         peer.Disconnect();
     }
 }
Beispiel #8
0
 /// <summary>
 /// Send message to one peer
 /// </summary>
 /// <param name="peer">The peer to get msg</param>
 /// <param name="msg">the message to send</param>
 public void SendMessageToPeer(ZrePeer peer, ZreMsg msg)
 {
     peer.Send(msg);
 }
Beispiel #9
0
 /// <summary>
 /// Remove peer from group
 /// </summary>
 /// <param name="peer"></param>
 public void Leave(ZrePeer peer)
 {
     m_peers.Remove(peer.Uuid);
     peer.IncrementStatus();
 }
Beispiel #10
0
 /// <summary>
 /// Add peer to group
 /// Ignore duplicate joins
 /// </summary>
 /// <param name="peer"></param>
 public void Join(ZrePeer peer)
 {
     m_peers[peer.Uuid] = peer;
     peer.IncrementStatus();
 }
Beispiel #11
0
 /// <summary>
 /// Construct new ZrePeer object
 /// </summary>
 /// <param name="container">The dictionary of peers</param>
 /// <param name="guid">The identity for this peer</param>
 /// <returns></returns>
 public static ZrePeer NewPeer(Dictionary<Guid, ZrePeer> container, Guid guid)
 {
     var peer = new ZrePeer(guid);
     container[guid] = peer; // overwrite any existing entry for same uuid
     return peer;
 }
Beispiel #12
0
 /// <summary>
 /// Remove peer from group
 /// </summary>
 /// <param name="peer"></param>
 public void Leave(ZrePeer peer)
 {
     m_peers.Remove(peer.Uuid);
     peer.IncrementStatus();
 }
Beispiel #13
0
 /// <summary>
 /// Add peer to group
 /// Ignore duplicate joins
 /// </summary>
 /// <param name="peer"></param>
 public void Join(ZrePeer peer)
 {
     m_peers[peer.Uuid] = peer;
     peer.IncrementStatus();
 }