public bool DoHelloNeighbourCall(GridRegion region, RegionInfo thisRegion) { string uri = region.ServerURI + "region/" + thisRegion.RegionID + "/"; // m_log.Debug(" >>> DoHelloNeighbourCall <<< " + uri); WebRequest helloNeighbourRequest; try { helloNeighbourRequest = WebRequest.Create(uri); } catch (Exception e) { m_log.Warn(string.Format( "[NEIGHBOUR SERVICES CONNECTOR]: Unable to parse uri {0} to send HelloNeighbour from {1} to {2}. Exception {3} ", uri, thisRegion.RegionName, region.RegionName, e.Message), e); return false; } helloNeighbourRequest.Method = "POST"; helloNeighbourRequest.ContentType = "application/json"; helloNeighbourRequest.Timeout = 10000; // Fill it in OSDMap args = null; try { args = thisRegion.PackRegionInfoData(); } catch (Exception e) { m_log.Warn(string.Format( "[NEIGHBOUR SERVICES CONNECTOR]: PackRegionInfoData failed for HelloNeighbour from {0} to {1}. Exception {2} ", thisRegion.RegionName, region.RegionName, e.Message), e); return false; } // Add the regionhandle of the destination region args["destination_handle"] = OSD.FromString(region.RegionHandle.ToString()); string strBuffer = ""; byte[] buffer = new byte[1]; try { strBuffer = OSDParser.SerializeJsonString(args); buffer = Util.UTF8NoBomEncoding.GetBytes(strBuffer); } catch (Exception e) { m_log.Warn(string.Format( "[NEIGHBOUR SERVICES CONNECTOR]: Exception thrown on serialization of HelloNeighbour from {0} to {1}. Exception {2} ", thisRegion.RegionName, region.RegionName, e.Message), e); return false; } Stream os = null; try { // send the Post helloNeighbourRequest.ContentLength = buffer.Length; //Count bytes to send os = helloNeighbourRequest.GetRequestStream(); os.Write(buffer, 0, strBuffer.Length); //Send it //m_log.InfoFormat("[REST COMMS]: Posted HelloNeighbour request to remote sim {0}", uri); } catch (Exception e) { // m_log.WarnFormat( // "[NEIGHBOUR SERVICE CONNCTOR]: Unable to send HelloNeighbour from {0} to {1}. Exception {2}{3}", // thisRegion.RegionName, region.RegionName, e.Message, e.StackTrace); return false; } finally { if (os != null) os.Dispose(); } // Let's wait for the response //m_log.Info("[REST COMMS]: Waiting for a reply after DoHelloNeighbourCall"); try { using (WebResponse webResponse = helloNeighbourRequest.GetResponse()) { if (webResponse == null) { m_log.DebugFormat( "[NEIGHBOUR SERVICES CONNECTOR]: Null reply on DoHelloNeighbourCall post from {0} to {1}", thisRegion.RegionName, region.RegionName); } using (Stream s = webResponse.GetResponseStream()) { using (StreamReader sr = new StreamReader(s)) { //reply = sr.ReadToEnd().Trim(); sr.ReadToEnd().Trim(); //m_log.InfoFormat("[REST COMMS]: DoHelloNeighbourCall reply was {0} ", reply); } } } } catch (Exception e) { m_log.Warn(string.Format( "[NEIGHBOUR SERVICES CONNECTOR]: Exception on reply of DoHelloNeighbourCall from {0} back to {1}. Exception {2} ", region.RegionName, thisRegion.RegionName, e.Message), e); return false; } return true; }
protected void InformNeighborOfChatMessage(OSChatMessage message, ChatSourceType type, GridRegion region, RegionInfo thisRegion) { string uri = MakeUri(region, "/region/" + thisRegion.RegionID + "/"); //m_log.Debug(" >>> DoHelloNeighbourCall <<< " + uri); // Fill it in Dictionary<string, object> args = new Dictionary<string, object>(); try { args = Util.OSDToDictionary(thisRegion.PackRegionInfoData()); } catch (Exception e) { m_log.Debug("[REST COMMS]: PackRegionInfoData failed with exception: " + e.Message); return; } args["MESSAGE"] = WebUtils.BuildQueryString(message.ToKVP()); args["TYPE"] = (int)type; args["METHOD"] = "inform_neighbors_of_chat_message"; string queryString = WebUtils.BuildQueryString(args); SynchronousRestFormsRequester.MakeRequest("POST", uri, queryString); }
private Dictionary<string, object> PackRegionInfo(RegionInfo thisRegion, UUID uUID) { if (m_KnownNeighborsPass.ContainsKey(uUID)) { List<NeighborPassword> passes = m_KnownNeighborsPass[uUID]; lock (passes) { foreach (NeighborPassword p in passes) { if (thisRegion.RegionID == p.RegionID) { thisRegion.Password = p.Password; break; } } } } return Util.OSDToDictionary(thisRegion.PackRegionInfoData()); }
public bool DoHelloNeighbourCall(GridRegion region, RegionInfo thisRegion) { string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/region/" + thisRegion.RegionID + "/"; //m_log.Debug(" >>> DoHelloNeighbourCall <<< " + uri); WebRequest HelloNeighbourRequest = WebRequest.Create(uri); HelloNeighbourRequest.Method = "POST"; HelloNeighbourRequest.ContentType = "application/json"; HelloNeighbourRequest.Timeout = 10000; // Fill it in OSDMap args = null; try { args = thisRegion.PackRegionInfoData(); } catch (Exception e) { m_log.Debug("[REST COMMS]: PackRegionInfoData failed with exception: " + e.Message); return false; } // Add the regionhandle of the destination region args["destination_handle"] = OSD.FromString(region.RegionHandle.ToString()); string strBuffer = ""; byte[] buffer = new byte[1]; try { strBuffer = OSDParser.SerializeJsonString(args); UTF8Encoding str = new UTF8Encoding(); buffer = str.GetBytes(strBuffer); } catch (Exception e) { m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of HelloNeighbour: {0}", e.Message); return false; } Stream os = null; try { // send the Post HelloNeighbourRequest.ContentLength = buffer.Length; //Count bytes to send os = HelloNeighbourRequest.GetRequestStream(); os.Write(buffer, 0, strBuffer.Length); //Send it //m_log.InfoFormat("[REST COMMS]: Posted HelloNeighbour request to remote sim {0}", uri); } catch (Exception ex) { m_log.InfoFormat("[REST COMMS]: Unable to send HelloNeighbour to {0}: {1}", region.RegionName, ex.Message); return false; } finally { if (os != null) os.Close(); } // Let's wait for the response //m_log.Info("[REST COMMS]: Waiting for a reply after DoHelloNeighbourCall"); StreamReader sr = null; try { WebResponse webResponse = HelloNeighbourRequest.GetResponse(); if (webResponse == null) { m_log.Info("[REST COMMS]: Null reply on DoHelloNeighbourCall post"); } sr = new StreamReader(webResponse.GetResponseStream()); //reply = sr.ReadToEnd().Trim(); sr.ReadToEnd().Trim(); //m_log.InfoFormat("[REST COMMS]: DoHelloNeighbourCall reply was {0} ", reply); } catch (Exception ex) { m_log.InfoFormat("[REST COMMS]: exception on reply of DoHelloNeighbourCall {0}", ex.Message); return false; } finally { if (sr != null) sr.Close(); } return true; }