Example #1
0
        private string DoAgent2Put(Stream request, string path, string param, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            if (!Util.CheckHttpAuthorization(_gridSendKey, httpRequest.Headers))
            {
                m_log.WarnFormat("[REST COMMS]: /agent2/ communication from untrusted peer {0}", httpRequest.RemoteIPEndPoint.Address.ToString());
                httpResponse.StatusCode = 401;
                return("Untrusted");
            }

            UUID   agentId;
            ulong  regionHandle;
            string action; //unused

            if (!GetParams(path, out agentId, out regionHandle, out action))
            {
                m_log.InfoFormat("[REST COMMS]: Invalid parameters for agent message {0}", path);
                httpResponse.StatusCode = 400;
                return("Invalid Parameters");
            }

            ulong           createdOn = Util.GetLongTickCount();
            AgentPutMessage message   = ProtoBuf.Serializer.Deserialize <AgentPutMessage>(request);

            if (message == null)
            {
                httpResponse.StatusCode = 400;
                return("Invalid Request");
            }

            //CAU2 is the meaning of PUT
            var agentData = message.ToAgentData();

            agentData.AgentDataCreatedOn = createdOn; //used to calculate interpolation values
            ChildAgentUpdate2Response status = m_localBackend.SendChildAgentUpdate2(m_localBackend.GetRegion(regionHandle), agentData);
            bool result = (status == ChildAgentUpdate2Response.Ok);

            switch (status)
            {
            case ChildAgentUpdate2Response.Ok:
                httpResponse.StatusCode = 200;
                break;

            case ChildAgentUpdate2Response.AccessDenied:
                httpResponse.StatusCode = 403;
                break;

            default:
                httpResponse.StatusCode = 500;
                break;
            }
            return(result.ToString());
        }
Example #2
0
        public AgentUpdate2Ret DoChildAgentUpdateCall2(SimpleRegionInfo regInfo, AgentData data)
        {
            ulong  regionHandle = GetRegionHandle(regInfo.RegionHandle);
            string uri          = "http://" + regInfo.ExternalHostName + ":" + regInfo.HttpPort + "/agent2/" + data.AgentID + "/" + regionHandle + "/";

            HttpWebRequest agentPutRequest = (HttpWebRequest)WebRequest.Create(uri);

            agentPutRequest.Method      = "PUT";
            agentPutRequest.ContentType = "application/octet-stream";
            agentPutRequest.Timeout     = AGENT_UPDATE_TIMEOUT;

            agentPutRequest.Headers["authorization"] = GenerateAuthorization();

            AgentPutMessage message = AgentPutMessage.FromAgentData(data);

            try
            {
                // send the Post
                Stream os = agentPutRequest.GetRequestStream();
                ProtoBuf.Serializer.Serialize(os, message);

                os.Flush();
                os.Close();

                m_log.InfoFormat("[REST COMMS]: PUT DoChildAgentUpdateCall2 request to remote sim {0}", uri);
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[REST COMMS]: DoChildAgentUpdateCall2 call failed {0}", e);
                return(AgentUpdate2Ret.Error);
            }

            // Let's wait for the response
            //m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall");
            try
            {
                HttpWebResponse webResponse = (HttpWebResponse)agentPutRequest.GetResponse();
                if (webResponse == null)
                {
                    m_log.Error("[REST COMMS]: Null reply on DoChildAgentUpdateCall2 put");
                    return(AgentUpdate2Ret.Error);
                }

                StreamReader sr    = new StreamReader(webResponse.GetResponseStream());
                string       reply = sr.ReadToEnd().Trim();
                sr.Close();

                //this will happen during the initial rollout and tells us we need to fall back to the
                //old method
                if (webResponse.StatusCode == HttpStatusCode.NotFound)
                {
                    m_log.InfoFormat("[REST COMMS]: NotFound on reply of DoChildAgentUpdateCall2");
                    return(AgentUpdate2Ret.NotFound);
                }
                else if (webResponse.StatusCode == HttpStatusCode.OK)
                {
                    return(AgentUpdate2Ret.Ok);
                }
                else
                {
                    m_log.ErrorFormat("[REST COMMS]: Error on reply of DoChildAgentUpdateCall2 {0}", reply);
                    return(AgentUpdate2Ret.Error);
                }
            }
            catch (WebException ex)
            {
                HttpWebResponse webResponse = ex.Response as HttpWebResponse;
                if (webResponse != null)
                {
                    //this will happen during the initial rollout and tells us we need to fall back to the
                    //old method
                    if (webResponse.StatusCode == HttpStatusCode.NotFound)
                    {
                        m_log.InfoFormat("[REST COMMS]: NotFound on reply of DoChildAgentUpdateCall2");
                        return(AgentUpdate2Ret.NotFound);
                    }
                    if (webResponse.StatusCode == HttpStatusCode.Forbidden)
                    {
                        m_log.InfoFormat("[REST COMMS]: Forbidden returned on reply of DoChildAgentUpdateCall2");
                        return(AgentUpdate2Ret.AccessDenied);
                    }
                }

                m_log.ErrorFormat("[REST COMMS]: exception on reply of DoChildAgentUpdateCall2 {0} Sz {1}", ex, agentPutRequest.ContentLength);
            }

            return(AgentUpdate2Ret.Error);
        }