Ejemplo n.º 1
0
        private void ProcessRequest(object state)
        {
            Console.WriteLine("Получен запрос");
            SntpMessageEventArgs args = (SntpMessageEventArgs)state;

            if (args.RequestMessage != null)
            {
                switch (args.RequestMessage.Mode)
                {
                case Mode.Client:
                    args.ResponseMessage                     = args.RequestMessage;
                    args.ResponseMessage.Mode                = Mode.Server;
                    args.ResponseMessage.ReceiveDateTime     = DateTime.Now;
                    args.ResponseMessage.TransmitDateTime    = DateTime.Now;
                    args.ResponseMessage.Stratum             = Stratum.Secondary;
                    args.ResponseMessage.ReferenceIdentifier = ReferenceIdentifier.LOCL;
                    this.SendReply(args);

                    break;

                case Mode.Broadcast:
                case Mode.Reserved:
                case Mode.ReservedNTPControl:
                case Mode.ReservedPrivate:
                case Mode.Server:
                case Mode.SymmetricActive:
                case Mode.SymmetricPassive:
                    break;

                default:
                    logger.Info("UNKNOWN message mode received and ignored");
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        private void SendReply(SntpMessageEventArgs args)
        {
            try {
                args.Channel.SendTo(args.ResponseMessage.ToArray(), args.Channel.RemoteEndpoint);

                logger.Debug("PACKET with channel id " +
                             args.Channel.ChannelId.ToString() +
                             " successfully sent to client endpoint " +
                             args.Channel.RemoteEndpoint.ToString());

                logger.Debug(args.ResponseMessage.ToString());

                OnSntpMessageSent(this, args);
            }
            catch (Exception ex) {
                logger.Error(ex, "Error Message");
            }
        }
Ejemplo n.º 3
0
        private void OnClientConnect(object sender, ClientConnectedEventArgs args)
        {
            SocketBuffer channelBuffer = args.ChannelBuffer;

            if (channelBuffer != null &&
                args.Channel.IsConnected &&
                channelBuffer.BytesTransferred >= Constants.SNTP_MIN_MESSAGE_SIZE &&
                channelBuffer.BytesTransferred <= Constants.SNTP_MAX_MESSAGE_SIZE)
            {
                logger.Debug("PACKET request with channel id " +
                             args.Channel.ChannelId.ToString() +
                             " was received from " +
                             args.Channel.RemoteEndpoint.ToString() +
                             " and queued for processing...");

                SntpMessageEventArgs messageArgs = new SntpMessageEventArgs(args.Channel, args.ChannelBuffer);
                OnSntpMessageReceived(this, messageArgs);

                ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessRequest), messageArgs);
            }
        }