Esempio n. 1
0
        private void OnBeaconReady(object sender, NetMQBeaconEventArgs e)
        {
            // we got another beacon
            // let's check if we already know about the beacon
            var message = m_beacon.Receive();
            int port;

            int.TryParse(message.String, out port);

            NodeKey node = new NodeKey(message.PeerHost, port);

            // check if node already exist
            if (!m_nodes.ContainsKey(node))
            {
                // we have a new node, let's add it and connect to subscriber
                m_nodes.Add(node, DateTime.Now);
                m_publisher.Connect(node.Address);
                m_shim.SendMoreFrame(AddedNodeCommand).SendFrame(node.Address);
            }
            else
            {
                //Console.WriteLine("Node {0} is not a new beacon.", node);
                m_nodes[node] = DateTime.Now;
            }
        }
Esempio n. 2
0
        private void OnBeaconReady(object sender, NetMQBeaconEventArgs e)
        {
            var readyTime = DateTimeOffset.Now;

            var message = _beacon.Receive();

            int.TryParse(message.String, out var port);

            var peer = new PeerInfo(message.PeerHost, port);

            if (!_info.ContainsKey(peer))
            {
                _info.Add(peer, readyTime);
                _publisher.Connect(peer.Address);
                _shim.SendMoreFrame("A").SendFrame(peer.Address);

                _logger?.LogInformation($"{_id}: Added new peer from '{{PeerAddress}}'", peer.Address);
                _hub?.Clients.All.SendAsync("ReceiveMessage", "success", $"Adding new peer from '{peer.Address}'");
            }
            else
            {
                _logger?.LogDebug($"{_id}: Updating keep-alive for peer '{{PeerAddress}}'", peer.Address);
                _info[peer] = readyTime;
            }
        }
Esempio n. 3
0
        private void OnBeaconReady(object sender, NetMQBeaconEventArgs e)
        {
            // we got another beacon
            // let's check if we already know about the beacon
            string nodeName;
            int    port = Convert.ToInt32(m_beacon.ReceiveString(out nodeName));

            // remove the port from the peer name
            nodeName = nodeName.Replace(":" + m_broadcastPort, "");

            NodeKey node = new NodeKey(nodeName, port);

            // check if node already exist
            if (!m_nodes.ContainsKey(node))
            {
                // we have a new node, let's add it and connect to subscriber
                m_nodes.Add(node, DateTime.Now);
                m_publisher.Connect(node.Address);
                m_shim.SendMoreFrame(AddedNodeCommand).SendFrame(node.Address);
            }
            else
            {
                //Console.WriteLine("Node {0} is not a new beacon.", node);
                m_nodes[node] = DateTime.Now;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Remove a peer from our data structures
        /// </summary>
        /// <param name="peer"></param>
        private void RemovePeer(ZyrePeer peer)
        {
            // Tell the calling application the peer has gone
            _outbox.SendMoreFrame("EXIT").SendMoreFrame(peer.Uuid.ToByteArray()).SendFrame(peer.Name);
            _loggerDelegate?.Invoke($"EXIT name={peer.Name} endpoint={peer.Endpoint}");

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

            _peers.Remove(peer.Uuid);
            peer.Destroy();
        }
Esempio n. 5
0
        private void OnBeaconReady(object sender, NetMQBeaconEventArgs e)
        {
            // we got another beacon
            // let's check if we already know about the beacon
            var message = _beacon.Receive();
            var port    = int.Parse(message.String);
            var node    = new NodeKey(message.PeerHost, port);

            // check if node already exist
            if (!_nodes.ContainsKey(node))
            {
                // we have a new node, let's add it and connect to subscriber
                _nodes.Add(node, DateTime.UtcNow);
                _publisher.Connect(node.Address);
                _shim.SendMoreFrame(TaskSchedulerBusCommands.AddedNode.ToString()).SendFrame(node.Address);
            }
            else
            {
                _nodes[node] = DateTime.UtcNow; //heartbeat
            }
        }
Esempio n. 6
0
 public void SendMoreFrame(byte[] frame)
 {
     m_messagesPipe.SendMoreFrame(frame);
 }