Esempio n. 1
0
            public PRSMessage ParseMessage(PRSMessage Request)//Parses through message and formulates a response to be sent back
            {
                //error checking0. SUCCESS
                //1.SERVICE_IN_USE
                //2.SERVICE_NOT_FOUND
                //3.ALL_PORTS_BUSY
                //4.INVALID_ARG
                //5.UNDEFINED_ERROR
                switch (Request.msgType)
                {
                case PRSMessage.MsgType.CLOSE_PORT:        //Closes the requested port 3 errors 2,4,5
                    return(PRSMessage.MakeRESPONSE(0, 0)); //Returns a success

                case PRSMessage.MsgType.KEEP_ALIVE:        //keeps service alive 3 errors 2,4,5
                    return(PRSMessage.MakeRESPONSE(0, 0)); //Returns a success

                case PRSMessage.MsgType.LOOKUP_PORT:       //takes a service name and gives a port error 2,4,5
                    return(PRSMessage.MakeRESPONSE(0, 0)); //Returns a success

                case PRSMessage.MsgType.REQUEST_PORT:      //Gives service lowest port 2,3,4,5
                    return(PRSMessage.MakeRESPONSE(0, 0)); //Returns a success

                case PRSMessage.MsgType.STOP:              //Server gets stopped by the Handler this sends response
                    return(PRSMessage.MakeRESPONSE(0, 0)); //Returns a success

                default:
                    return(PRSMessage.MakeRESPONSE(0, 0));   //Returns a success;
                }
            }
Esempio n. 2
0
            private PRSMessage portdead(PRSMessage Request)
            {
                ManagedPort p = find_port(Request.port);

                p.reserved = false;
                Console.WriteLine("Marked port dead:" + p.port);
                return(PRSMessage.MakeRESPONSE(PRSMessage.Status.SUCCESS, Request.port));
            }
Esempio n. 3
0
            private PRSMessage lookup_port(PRSMessage Request)
            {
                ManagedPort p = find_service(Request.serviceName);//find the service in the list

                if (p == null)
                {
                    return(PRSMessage.MakeRESPONSE(PRSMessage.Status.SERVICE_NOT_FOUND, Request.port)); //if the service isnt in the list return not found
                }
                return(PRSMessage.MakeRESPONSE(PRSMessage.Status.SUCCESS, (ushort)p.port));             //if it is return success with port number
            }
Esempio n. 4
0
            public PRSMessage ParseMessageType(PRSMessage Request)//Parses through message and formulates a response to be sent back
            {
                //error checking
                //0. SUCCESS
                //1.SERVICE_IN_USE
                //2.SERVICE_NOT_FOUND
                //3.ALL_PORTS_BUSY
                //4.INVALID_ARG
                //5.UNDEFINED_ERROR
                try
                {
                    switch (Request.msgType)//checks the type
                    {
                    case PRSMessage.MsgType.PORT_DEAD:
                        return(portdead(Request));

                    case PRSMessage.MsgType.CLOSE_PORT:    //Closes the requested port 3 errors 2,4,5
                                                           //if service in msg is not at either the correct port or name
                                                           //throw out Response service not found
                        return(close_port(Request));

                    case PRSMessage.MsgType.KEEP_ALIVE:    //keeps service alive 3 errors 2,4,5
                                                           //if port or service is incorrect return invalid
                        return(keep_alive(Request));

                    case PRSMessage.MsgType.LOOKUP_PORT:    //takes a service name and gives a port error 2,4,5
                                                            //if not well formulated throw invalid
                                                            //if service name not correct return not found
                        return(lookup_port(Request));

                    case PRSMessage.MsgType.REQUEST_PORT:    //Gives service lowest port 1,3,4,5
                        return(request_port(Request));

                    case PRSMessage.MsgType.STOP:                                          //Server gets stopped by the Handler this sends response
                                                                                           //only checks message type
                        Console.WriteLine("Stop Has been recieved");
                        return(PRSMessage.MakeSTOP());                                     //Stop doesn't impact the port reservations so it just uses its method

                    default:                                                               //if not a correct message code
                        return(PRSMessage.MakeRESPONSE(PRSMessage.Status.INVALID_ARG, 0)); //Returns an invalid arg
                    }
                }
                catch (Exception e)
                {
                    return(PRSMessage.MakeRESPONSE(PRSMessage.Status.UNDEFINED_ERROR, 0));//if this happened the service broke
                }
            }
Esempio n. 5
0
            private PRSMessage keep_alive(PRSMessage Request)
            {
                //check if the service and port are both valid and match
                ManagedPort n = find_service(Request.serviceName);//checks if the service is valid

                if (n == null)
                {
                    return(PRSMessage.MakeRESPONSE(PRSMessage.Status.SERVICE_NOT_FOUND, Request.port));
                }
                ManagedPort p = find_port(Request.port);//Checks if the port is valid

                if (p == null || p != n)
                {
                    return(PRSMessage.MakeRESPONSE(PRSMessage.Status.INVALID_ARG, Request.port));
                }
                p.lastAlive = DateTime.Now;
                return(PRSMessage.MakeRESPONSE(PRSMessage.Status.SUCCESS, Request.port));
            }
Esempio n. 6
0
            private PRSMessage close_port(PRSMessage Request)
            {
                //check if port and name are accurate
                ManagedPort n = find_service(Request.serviceName);//checks if the service is valid

                if (n == null)
                {
                    return(PRSMessage.MakeRESPONSE(PRSMessage.Status.SERVICE_NOT_FOUND, Request.port));
                }
                ManagedPort p = find_port(Request.port);//Checks if the port is valid

                if (p == null || p != n)
                {
                    return(PRSMessage.MakeRESPONSE(PRSMessage.Status.INVALID_ARG, Request.port));
                }
                //Actually close port
                p.serviceName = null;
                p.reserved    = false;
                return(PRSMessage.MakeRESPONSE(PRSMessage.Status.SUCCESS, Request.port));
            }
Esempio n. 7
0
            private PRSMessage request_port(PRSMessage Request)
            {
                //check if service in use
                ManagedPort sn = find_service(Request.serviceName);                                  //if the service is in the list

                if (sn != null)                                                                      //check to see if it was found in the list
                {
                    return(PRSMessage.MakeRESPONSE(PRSMessage.Status.SERVICE_IN_USE, Request.port)); //if it was its already in use
                }
                foreach (ManagedPort p in Ports)                                                     //for each port in the list
                {
                    if (!p.reserved && p.serviceName == null)                                        //check if its reserved
                    {
                        p.reserved    = true;                                                        //reserve it
                        p.serviceName = Request.serviceName;                                         //set the service name
                        p.lastAlive   = DateTime.Now;                                                //update the time
                        return(PRSMessage.MakeRESPONSE(PRSMessage.Status.SUCCESS, (ushort)p.port));  //return success with port number
                    }
                }
                return(PRSMessage.MakeRESPONSE(PRSMessage.Status.ALL_PORTS_BUSY, Request.port));
            }