Пример #1
0
        /// <summary>
        /// Initializes a new instance of <see cref="Node"/> using the given parameters.
        /// </summary>
        /// <param name="bc">The blockchain (database) manager</param>
        /// <param name="cs">Client settings</param>
        /// <param name="socket">Socket to use</param>
        internal Node(IBlockchain bc, IClientSettings cs, Socket socket)
        {
            settings   = cs;
            NodeStatus = new NodeStatus();
            var repMan = new ReplyManager(NodeStatus, bc, cs);

            sendReceiveSAEA = cs.SendReceivePool.Pop();
            sendReceiveSAEA.AcceptSocket = socket;
            sendReceiveSAEA.UserToken    = new MessageManager(cs, repMan, NodeStatus);
            sendReceiveSAEA.Completed   += new EventHandler <SocketAsyncEventArgs>(IO_Completed);

            sendSAEA = cs.SendReceivePool.Pop();
            sendSAEA.AcceptSocket = socket;
            sendSAEA.UserToken    = new MessageManager(cs, repMan, NodeStatus);
            sendSAEA.Completed   += new EventHandler <SocketAsyncEventArgs>(IO_Completed);
        }
Пример #2
0
        private void PingTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            // Every 1 minute (~66 sec) the LastSeen is checked but only if 2 minutes has passed a Ping will be sent
            // this will make sure the connection to the other node is still alive while avoiding unnecessary Pings
            var msgMan = (MessageManager)sendSAEA.UserToken;

            if (DateTime.Now.Subtract(msgMan.NodeStatus.LastSeen) >= TimeSpan.FromMinutes(2))
            {
                if (NodeStatus.HasTooManyUnansweredPings)
                {
                    NodeStatus.SignalDisconnect();
                }
                else
                {
                    Message ping = msgMan.GetPingMsg();
                    Send(ping);
                }
            }
        }