Exemplo n.º 1
0
        /// <summary>
        /// Write a connection response message
        /// </summary>
        public static void WriteConnectionResponse(IClient <byte, byte> client)
        {
            var response = new ConnectionResponse();

            response.Status           = Status.Ok;
            response.ClientIdentifier = ByteString.CopyFrom(client.Guid.ToByteArray());
            WriteMessage(client.Stream, response);
        }
Exemplo n.º 2
0
        static void WriteErrorConnectionResponse(Status status, string message, IStream <byte, byte> stream)
        {
            if (status == Status.Ok)
            {
                throw new ArgumentException("Error response must have a non-OK status code");
            }
            var response = new ConnectionResponse();

            response.Status  = status;
            response.Message = message;
            Utils.WriteMessage(stream, response);
        }
Exemplo n.º 3
0
        static void WriteErrorConnectionResponse(Status status, string message, IStream <byte, byte> stream)
        {
            if (status == Status.Ok)
            {
                throw new ArgumentException("Error response must have a non-OK status code");
            }
            var response = new ConnectionResponse();

            response.Status  = status;
            response.Message = message;
            Utils.WriteMessage(stream, response);
            Logger.WriteLine("ProtocolBuffers: client connection denied: " + status + " " + message, Logger.Severity.Error);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Write a connection response message
        /// </summary>
        public static void WriteConnectionResponse(
            IClient <byte, byte> client, Status errorStatus, string errorMessage)
        {
            if (errorStatus == Status.Ok)
            {
                throw new ArgumentException("Error response must have a non-OK status code");
            }
            var response = new ConnectionResponse();

            response.Status  = errorStatus;
            response.Message = errorMessage;
            WriteMessage(client.Stream, response);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Handle a client connection request
 /// </summary>
 public override void HandleClientRequestingConnection(object sender, ClientRequestingConnectionEventArgs <byte, byte> args)
 {
     base.HandleClientRequestingConnection(sender, args);
     if (args.Request.ShouldAllow)
     {
         var client   = args.Client;
         var response = new ConnectionResponse();
         response.Status           = Status.Ok;
         response.ClientIdentifier = ByteString.CopyFrom(client.Guid.ToByteArray());
         Utils.WriteMessage(client.Stream, response);
     }
     else if (args.Request.ShouldDeny)
     {
         args.Client.Stream.Close();
     }
 }