//(Stream request, string path, string param, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        public byte[] HandleGetUserFriendList2(Stream requestStream, string path, string param, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            Util.SlowTimeReporter slowCheck = new Util.SlowTimeReporter("[FRIEND]: GetUserFriendList2 took", TimeSpan.FromMilliseconds(1000));
            try
            {
                // Check IP Endpoint Access
                if (!TrustManager.Instance.IsTrustedPeer(httpRequest.RemoteIPEndPoint))
                {
                    httpResponse.StatusCode = 401;
                    return(new byte[0]);
                }

                // Request/response succeeded.
                FriendsListRequest request = ProtoBuf.Serializer.Deserialize <FriendsListRequest>(requestStream);
                UUID friendlistowner       = request.ToUUID();

                // Now perform the actual friends lookup.
                List <FriendListItem> returndata = m_userDataBaseService.GetUserFriendList(friendlistowner);

                // Generate and send the response.
                if (returndata == null)
                {
                    returndata = new List <FriendListItem>();
                }

                httpResponse.StatusCode = 200;
                return(FriendsListResponse.ToBytes(returndata));
            }
            finally
            {
                slowCheck.Complete();
            }
        }
Пример #2
0
        /// <summary>
        /// Returns a list of FriendsListItems that describe the friends and permissions in the friend
        /// relationship for UUID friendslistowner. For faster lookup, we index by friend's UUID.
        /// </summary>
        /// <param name="friendlistowner">The agent that we're retreiving the friends Data for.</param>
        private GetUserFriendListResult GetUserFriendList2(UUID friendlistowner, out Dictionary <UUID, FriendListItem> results)
        {
            Util.SlowTimeReporter slowCheck = new Util.SlowTimeReporter("[FRIEND]: GetUserFriendList2 for " + friendlistowner.ToString() + " took", TimeSpan.FromMilliseconds(1000));
            try
            {
                Dictionary <UUID, FriendListItem> EMPTY_RESULTS = new Dictionary <UUID, FriendListItem>();
                string         uri = m_cfg.UserServerURL + "/get_user_friend_list2/";
                HttpWebRequest friendListRequest = (HttpWebRequest)WebRequest.Create(uri);
                friendListRequest.Method      = "POST";
                friendListRequest.ContentType = "application/octet-stream";
                friendListRequest.Timeout     = FriendsListRequest.TIMEOUT;

                // Default results are empty
                results = EMPTY_RESULTS;

//                m_log.WarnFormat("[FRIEND]: Msg/GetUserFriendList2({0}) using URI '{1}'", friendlistowner, uri);
                FriendsListRequest request = FriendsListRequest.FromUUID(friendlistowner);
                try
                {
                    // send the Post
                    Stream os = friendListRequest.GetRequestStream();
                    ProtoBuf.Serializer.Serialize(os, request);
                    os.Flush();
                    os.Close();
                }
                catch (Exception e)
                {
                    m_log.InfoFormat("[FRIEND]: GetUserFriendList2 call failed {0}", e);
                    return(GetUserFriendListResult.ERROR);
                }

                // Let's wait for the response
                try
                {
                    HttpWebResponse webResponse = (HttpWebResponse)friendListRequest.GetResponse();
                    if (webResponse == null)
                    {
                        m_log.Error("[FRIEND]: Null reply on GetUserFriendList2 put");
                        return(GetUserFriendListResult.ERROR);
                    }
                    //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.WarnFormat("[FRIEND]: NotFound on reply of GetUserFriendList2");
                        return(GetUserFriendListResult.NOTIMPLEMENTED);
                    }
                    if (webResponse.StatusCode != HttpStatusCode.OK)
                    {
                        m_log.ErrorFormat("[FRIEND]: Error on reply of GetUserFriendList2 {0}", friendlistowner);
                        return(GetUserFriendListResult.ERROR);
                    }

                    // We have a reply.
                    FriendsListResponse response = ProtoBuf.Serializer.Deserialize <FriendsListResponse>(webResponse.GetResponseStream());
                    if (response == null)
                    {
                        m_log.ErrorFormat("[FRIEND]: Could not deserialize reply of GetUserFriendList2");
                        return(GetUserFriendListResult.ERROR);
                    }

                    // Request/response succeeded.
                    results = response.ToDict();
                    // m_log.InfoFormat("[FRIEND]: Returning {0} friends for {1}", results.Count, friendlistowner);
                    return(GetUserFriendListResult.OK);
                }
                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("[FRIEND]: NotFound exception on reply of GetUserFriendList2");
                            return(GetUserFriendListResult.NOTIMPLEMENTED);
                        }
                    }
                    m_log.ErrorFormat("[FRIEND]: exception on reply of GetUserFriendList2 for {0}", request.FriendListOwner);
                }
                return(GetUserFriendListResult.ERROR);
            }
            finally
            {
                slowCheck.Complete();
            }
        }
Пример #3
0
        /// <summary>
        /// Returns a list of FriendsListItems that describe the friends and permissions in the friend
        /// relationship for UUID friendslistowner.
        /// </summary>
        /// <param name="friendlistowner">The agent that we're retreiving the friends Data for.</param>
        private GetUserFriendListResult GetUserFriendList2(UUID friendlistowner, out List<FriendListItem> results)
        {
            Util.SlowTimeReporter slowCheck = new Util.SlowTimeReporter("[FRIEND]: GetUserFriendList2 for "+friendlistowner.ToString()+" took");
            try
            {
                List<FriendListItem> EMPTY_RESULTS = new List<FriendListItem>();
                string uri = m_commsManager.NetworkServersInfo.UserURL + "/get_user_friend_list2/";
                HttpWebRequest friendListRequest = (HttpWebRequest)WebRequest.Create(uri);
                friendListRequest.Method = "POST";
                friendListRequest.ContentType = "application/octet-stream";
                friendListRequest.Timeout = FriendsListRequest.TIMEOUT;

                // Default results are empty
                results = EMPTY_RESULTS;

//                m_log.WarnFormat("[FRIEND]: Msg/GetUserFriendList2({0}) using URI '{1}'", friendlistowner, uri);
                FriendsListRequest request = FriendsListRequest.FromUUID(friendlistowner);
                try
                {
                    // send the Post
                    Stream os = friendListRequest.GetRequestStream();
                    ProtoBuf.Serializer.Serialize(os, request);

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

//                    m_log.InfoFormat("[FRIEND]: Posted GetUserFriendList2 request remotely {0}", uri);
                }
                catch (Exception e)
                {
                    m_log.WarnFormat("[FRIEND]: GetUserFriendList2 call failed {0}", e);
                    return GetUserFriendListResult.ERROR;
                }

                // Let's wait for the response
                try
                {
                    HttpWebResponse webResponse = (HttpWebResponse)friendListRequest.GetResponse();
                    if (webResponse == null)
                    {
                        m_log.Error("[FRIEND]: Null reply on GetUserFriendList2 put");
                        return GetUserFriendListResult.ERROR;
                    }
                    //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.WarnFormat("[FRIEND]: NotFound on reply of GetUserFriendList2");
                        return GetUserFriendListResult.NOTIMPLEMENTED;
                    }
                    if (webResponse.StatusCode != HttpStatusCode.OK)
                    {
                        m_log.ErrorFormat("[FRIEND]: Error on reply of GetUserFriendList2 {0}", friendlistowner);
                        return GetUserFriendListResult.ERROR;
                    }

                    // Request/response succeeded.
                    results = FriendsListResponse.DeserializeFromStream(webResponse.GetResponseStream());
                    // m_log.InfoFormat("[FRIEND]: Returning {0} friends for {1}", results.Count, friendlistowner);
                    return GetUserFriendListResult.OK;
                }
                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("[FRIEND]: NotFound exception on reply of GetUserFriendList2");
                            return GetUserFriendListResult.NOTIMPLEMENTED;
                        }
                    }
                    m_log.ErrorFormat("[FRIEND]: exception on reply of GetUserFriendList2 for {0}", request.FriendListOwner);
                }
                return GetUserFriendListResult.ERROR;
            }
            finally
            {
                slowCheck.Complete();
            }
        }
Пример #4
0
        //(Stream request, string path, string param, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        public byte[] HandleGetUserFriendList2(Stream requestStream, string path, string param, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            Util.SlowTimeReporter slowCheck = new Util.SlowTimeReporter("[FRIEND]: GetUserFriendList2 took", TimeSpan.FromMilliseconds(1000));
            try
            {
                // Check IP Endpoint Access
                if (!TrustManager.Instance.IsTrustedPeer(httpRequest.RemoteIPEndPoint))
                {
                    httpResponse.StatusCode = 401;
                    return new byte[0];
                }

                // Request/response succeeded.
                FriendsListRequest request = ProtoBuf.Serializer.Deserialize<FriendsListRequest>(requestStream);
                UUID friendlistowner = request.ToUUID();

                // Now perform the actual friends lookup.
                List<FriendListItem> returndata = m_userDataBaseService.GetUserFriendList(friendlistowner);

                // Generate and send the response.
                if (returndata == null)
                    returndata = new List<FriendListItem>();

                httpResponse.StatusCode = 200;
                return FriendsListResponse.ToBytes(returndata);
            }
            finally
            {
                slowCheck.Complete();
            }
        }