aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/HttpServer
diff options
context:
space:
mode:
authorUbitUmarov2018-11-03 11:43:47 +0000
committerUbitUmarov2018-11-03 11:43:47 +0000
commit5b5e53aa1d3e9eba7ec08d438464f4526d091887 (patch)
treeaf46935cd5f258a26bcc92d64fe1f0f0444546a3 /OpenSim/Framework/Servers/HttpServer
parentfix lsl http url pool service still not starting correctly (diff)
downloadopensim-SC-5b5e53aa1d3e9eba7ec08d438464f4526d091887.zip
opensim-SC-5b5e53aa1d3e9eba7ec08d438464f4526d091887.tar.gz
opensim-SC-5b5e53aa1d3e9eba7ec08d438464f4526d091887.tar.bz2
opensim-SC-5b5e53aa1d3e9eba7ec08d438464f4526d091887.tar.xz
we should only have one http poll service manager per instance
Diffstat (limited to 'OpenSim/Framework/Servers/HttpServer')
-rw-r--r--OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs114
-rw-r--r--OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs118
-rw-r--r--OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs23
3 files changed, 178 insertions, 77 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
index 4c9b19d..83cf904 100644
--- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
+++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
@@ -44,11 +44,11 @@ using log4net;
44using Nwc.XmlRpc; 44using Nwc.XmlRpc;
45using OpenMetaverse.StructuredData; 45using OpenMetaverse.StructuredData;
46using CoolHTTPListener = HttpServer.HttpListener; 46using CoolHTTPListener = HttpServer.HttpListener;
47using HttpListener = System.Net.HttpListener;
48using LogPrio = HttpServer.LogPrio; 47using LogPrio = HttpServer.LogPrio;
49using OpenSim.Framework.Monitoring; 48using OpenSim.Framework.Monitoring;
50using System.IO.Compression; 49using System.IO.Compression;
51using System.Security.Cryptography; 50using System.Security.Cryptography;
51using OpenSim.Framework.Servers;
52 52
53namespace OpenSim.Framework.Servers.HttpServer 53namespace OpenSim.Framework.Servers.HttpServer
54{ 54{
@@ -57,6 +57,8 @@ namespace OpenSim.Framework.Servers.HttpServer
57 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 57 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
58 private HttpServerLogWriter httpserverlog = new HttpServerLogWriter(); 58 private HttpServerLogWriter httpserverlog = new HttpServerLogWriter();
59 private static Encoding UTF8NoBOM = new System.Text.UTF8Encoding(false); 59 private static Encoding UTF8NoBOM = new System.Text.UTF8Encoding(false);
60 public static PollServiceRequestManager m_pollServiceManager;
61 private static object m_generalLock = new object();
60 62
61 /// <summary> 63 /// <summary>
62 /// This is a pending websocket request before it got an sucessful upgrade response. 64 /// This is a pending websocket request before it got an sucessful upgrade response.
@@ -119,7 +121,6 @@ namespace OpenSim.Framework.Servers.HttpServer
119 121
120 protected IPAddress m_listenIPAddress = IPAddress.Any; 122 protected IPAddress m_listenIPAddress = IPAddress.Any;
121 123
122 public PollServiceRequestManager PollServiceRequestManager { get; private set; }
123 124
124 public string Protocol 125 public string Protocol
125 { 126 {
@@ -249,46 +250,46 @@ namespace OpenSim.Framework.Servers.HttpServer
249 m_ssl = false; 250 m_ssl = false;
250 } 251 }
251 252
252 static bool MatchDNS (string hostname, string dns) 253 static bool MatchDNS(string hostname, string dns)
253 { 254 {
254 int indx = dns.IndexOf ('*'); 255 int indx = dns.IndexOf('*');
255 if (indx == -1) 256 if (indx == -1)
256 return (String.Compare(hostname, dns, true, CultureInfo.InvariantCulture) == 0); 257 return (String.Compare(hostname, dns, true, CultureInfo.InvariantCulture) == 0);
257 258
258 int dnslen = dns.Length; 259 int dnslen = dns.Length;
259 dnslen--; 260 dnslen--;
260 if(indx == dnslen) 261 if (indx == dnslen)
261 return true; // just * ? 262 return true; // just * ?
262 263
263 if(indx > dnslen - 2) 264 if (indx > dnslen - 2)
264 return false; // 2 short ? 265 return false; // 2 short ?
265 266
266 if (dns[indx + 1] != '.') 267 if (dns[indx + 1] != '.')
267 return false; 268 return false;
268 269
269 int indx2 = dns.IndexOf ('*', indx + 1); 270 int indx2 = dns.IndexOf('*', indx + 1);
270 if (indx2 != -1) 271 if (indx2 != -1)
271 return false; // there can only be one; 272 return false; // there can only be one;
272 273
273 string end = dns.Substring(indx + 1); 274 string end = dns.Substring(indx + 1);
274 int hostlen = hostname.Length; 275 int hostlen = hostname.Length;
275 int endlen = end.Length; 276 int endlen = end.Length;
276 int length = hostlen - endlen; 277 int length = hostlen - endlen;
277 if (length <= 0) 278 if (length <= 0)
278 return false; 279 return false;
279 280
280 if (String.Compare(hostname, length, end, 0, endlen, true, CultureInfo.InvariantCulture) != 0) 281 if (String.Compare(hostname, length, end, 0, endlen, true, CultureInfo.InvariantCulture) != 0)
281 return false; 282 return false;
282 283
283 if (indx == 0) 284 if (indx == 0)
284 { 285 {
285 indx2 = hostname.IndexOf ('.'); 286 indx2 = hostname.IndexOf('.');
286 return ((indx2 == -1) || (indx2 >= length)); 287 return ((indx2 == -1) || (indx2 >= length));
287 } 288 }
288 289
289 string start = dns.Substring (0, indx); 290 string start = dns.Substring(0, indx);
290 return (String.Compare (hostname, 0, start, 0, start.Length, true, CultureInfo.InvariantCulture) == 0); 291 return (String.Compare(hostname, 0, start, 0, start.Length, true, CultureInfo.InvariantCulture) == 0);
291 } 292 }
292 293
293 public bool CheckSSLCertHost(string hostname) 294 public bool CheckSSLCertHost(string hostname)
294 { 295 {
@@ -527,7 +528,6 @@ namespace OpenSim.Framework.Servers.HttpServer
527 public void OnRequest(object source, RequestEventArgs args) 528 public void OnRequest(object source, RequestEventArgs args)
528 { 529 {
529 RequestNumber++; 530 RequestNumber++;
530
531 try 531 try
532 { 532 {
533 IHttpClientContext context = (IHttpClientContext)source; 533 IHttpClientContext context = (IHttpClientContext)source;
@@ -576,7 +576,7 @@ namespace OpenSim.Framework.Servers.HttpServer
576 psEvArgs.Request(psreq.RequestID, keysvals); 576 psEvArgs.Request(psreq.RequestID, keysvals);
577 } 577 }
578 578
579 PollServiceRequestManager.Enqueue(psreq); 579 m_pollServiceManager.Enqueue(psreq);
580 } 580 }
581 else 581 else
582 { 582 {
@@ -616,16 +616,6 @@ namespace OpenSim.Framework.Servers.HttpServer
616 request.AcceptTypes[i] = string.Empty; 616 request.AcceptTypes[i] = string.Empty;
617 } 617 }
618 618
619 // public void ConvertIHttpClientContextToOSHttp(object stateinfo)
620 // {
621 // HttpServerContextObj objstate = (HttpServerContextObj)stateinfo;
622
623 // OSHttpRequest request = objstate.oreq;
624 // OSHttpResponse resp = objstate.oresp;
625
626 // HandleRequest(request,resp);
627 // }
628
629 /// <summary> 619 /// <summary>
630 /// This methods is the start of incoming HTTP request handling. 620 /// This methods is the start of incoming HTTP request handling.
631 /// </summary> 621 /// </summary>
@@ -2036,7 +2026,7 @@ namespace OpenSim.Framework.Servers.HttpServer
2036 2026
2037 public void Start() 2027 public void Start()
2038 { 2028 {
2039 Start(true,true); 2029 Start(true, true);
2040 } 2030 }
2041 2031
2042 /// <summary> 2032 /// <summary>
@@ -2085,11 +2075,14 @@ namespace OpenSim.Framework.Servers.HttpServer
2085 //m_httpListener.Start(); 2075 //m_httpListener.Start();
2086 m_httpListener2.Start(64); 2076 m_httpListener2.Start(64);
2087 2077
2088 // Long Poll Service Manager with 3 worker threads a 25 second timeout for no events 2078 lock(m_generalLock)
2089 if(runPool)
2090 { 2079 {
2091 PollServiceRequestManager = new PollServiceRequestManager(this, performPollResponsesAsync, 2, 25000); 2080 if (runPool)
2092 PollServiceRequestManager.Start(); 2081 {
2082 if(m_pollServiceManager == null)
2083 m_pollServiceManager = new PollServiceRequestManager(performPollResponsesAsync, 2, 25000);
2084 m_pollServiceManager.Start();
2085 }
2093 } 2086 }
2094 2087
2095 HTTPDRunning = true; 2088 HTTPDRunning = true;
@@ -2143,27 +2136,22 @@ namespace OpenSim.Framework.Servers.HttpServer
2143 if (source.ToString() == "HttpServer.HttpListener" && exception.ToString().StartsWith("Mono.Security.Protocol.Tls.TlsException")) 2136 if (source.ToString() == "HttpServer.HttpListener" && exception.ToString().StartsWith("Mono.Security.Protocol.Tls.TlsException"))
2144 return; 2137 return;
2145 m_log.ErrorFormat("[BASE HTTP SERVER]: {0} had an exception {1}", source.ToString(), exception.ToString()); 2138 m_log.ErrorFormat("[BASE HTTP SERVER]: {0} had an exception {1}", source.ToString(), exception.ToString());
2146 /*
2147 if (HTTPDRunning)// && NotSocketErrors > 5)
2148 {
2149 Stop();
2150 Thread.Sleep(200);
2151 StartHTTP();
2152 m_log.Warn("[HTTPSERVER]: Died. Trying to kick.....");
2153 }
2154 */
2155 } 2139 }
2156 2140
2157 public void Stop() 2141 public void Stop(bool stopPool = false)
2158 { 2142 {
2159 HTTPDRunning = false; 2143 HTTPDRunning = false;
2160 2144
2145
2161 StatsManager.DeregisterStat(m_requestsProcessedStat); 2146 StatsManager.DeregisterStat(m_requestsProcessedStat);
2162 2147
2163 try 2148 try
2164 { 2149 {
2165 if(PollServiceRequestManager != null) 2150 lock(m_generalLock)
2166 PollServiceRequestManager.Stop(); 2151 {
2152 if (stopPool && m_pollServiceManager != null)
2153 m_pollServiceManager.Stop();
2154 }
2167 2155
2168 m_httpListener2.ExceptionThrown -= httpServerException; 2156 m_httpListener2.ExceptionThrown -= httpServerException;
2169 //m_httpListener2.DisconnectHandler = null; 2157 //m_httpListener2.DisconnectHandler = null;
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs
index 04eb8de..beeef70 100644
--- a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs
+++ b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs
@@ -79,12 +79,12 @@ namespace OpenSim.Framework.Servers.HttpServer
79 contextHash = HttpContext.contextID; 79 contextHash = HttpContext.contextID;
80 } 80 }
81 81
82 internal void DoHTTPGruntWork(BaseHttpServer server, Hashtable responsedata) 82 internal void DoHTTPGruntWork(Hashtable responsedata)
83 { 83 {
84 OSHttpResponse response 84 OSHttpResponse response
85 = new OSHttpResponse(new HttpResponse(HttpContext, Request), HttpContext); 85 = new OSHttpResponse(new HttpResponse(HttpContext, Request), HttpContext);
86 86
87 byte[] buffer = server.DoHTTPGruntWork(responsedata, response); 87 byte[] buffer = srvDoHTTPGruntWork(responsedata, response);
88 88
89 if(Request.Body.CanRead) 89 if(Request.Body.CanRead)
90 Request.Body.Dispose(); 90 Request.Body.Dispose();
@@ -114,7 +114,119 @@ namespace OpenSim.Framework.Servers.HttpServer
114 PollServiceArgs.RequestsHandled++; 114 PollServiceArgs.RequestsHandled++;
115 } 115 }
116 116
117 internal void DoHTTPstop(BaseHttpServer server) 117 internal byte[] srvDoHTTPGruntWork(Hashtable responsedata, OSHttpResponse response)
118 {
119 int responsecode;
120 string responseString = String.Empty;
121 byte[] responseData = null;
122 string contentType;
123
124 if (responsedata == null)
125 {
126 responsecode = 500;
127 responseString = "No response could be obtained";
128 contentType = "text/plain";
129 responsedata = new Hashtable();
130 }
131 else
132 {
133 try
134 {
135 //m_log.Info("[BASE HTTP SERVER]: Doing HTTP Grunt work with response");
136 responsecode = (int)responsedata["int_response_code"];
137 if (responsedata["bin_response_data"] != null)
138 responseData = (byte[])responsedata["bin_response_data"];
139 else
140 responseString = (string)responsedata["str_response_string"];
141 contentType = (string)responsedata["content_type"];
142 if (responseString == null)
143 responseString = String.Empty;
144 }
145 catch
146 {
147 responsecode = 500;
148 responseString = "No response could be obtained";
149 contentType = "text/plain";
150 responsedata = new Hashtable();
151 }
152 }
153
154 if (responsedata.ContainsKey("error_status_text"))
155 {
156 response.StatusDescription = (string)responsedata["error_status_text"];
157 }
158 if (responsedata.ContainsKey("http_protocol_version"))
159 {
160 response.ProtocolVersion = (string)responsedata["http_protocol_version"];
161 }
162
163 if (responsedata.ContainsKey("keepalive"))
164 {
165 bool keepalive = (bool)responsedata["keepalive"];
166 response.KeepAlive = keepalive;
167 }
168
169 // Cross-Origin Resource Sharing with simple requests
170 if (responsedata.ContainsKey("access_control_allow_origin"))
171 response.AddHeader("Access-Control-Allow-Origin", (string)responsedata["access_control_allow_origin"]);
172
173 //Even though only one other part of the entire code uses HTTPHandlers, we shouldn't expect this
174 //and should check for NullReferenceExceptions
175
176 if (string.IsNullOrEmpty(contentType))
177 {
178 contentType = "text/html";
179 }
180
181 // The client ignores anything but 200 here for web login, so ensure that this is 200 for that
182
183 response.StatusCode = responsecode;
184
185 if (responsecode == (int)OSHttpStatusCode.RedirectMovedPermanently)
186 {
187 response.RedirectLocation = (string)responsedata["str_redirect_location"];
188 response.StatusCode = responsecode;
189 }
190
191 response.AddHeader("Content-Type", contentType);
192 if (responsedata.ContainsKey("headers"))
193 {
194 Hashtable headerdata = (Hashtable)responsedata["headers"];
195
196 foreach (string header in headerdata.Keys)
197 response.AddHeader(header, headerdata[header].ToString());
198 }
199
200 byte[] buffer;
201
202 if (responseData != null)
203 {
204 buffer = responseData;
205 }
206 else
207 {
208 if (!(contentType.Contains("image")
209 || contentType.Contains("x-shockwave-flash")
210 || contentType.Contains("application/x-oar")
211 || contentType.Contains("application/vnd.ll.mesh")))
212 {
213 // Text
214 buffer = Encoding.UTF8.GetBytes(responseString);
215 }
216 else
217 {
218 // Binary!
219 buffer = Convert.FromBase64String(responseString);
220 }
221
222 response.SendChunked = false;
223 response.ContentLength64 = buffer.Length;
224 response.ContentEncoding = Encoding.UTF8;
225 }
226
227 return buffer;
228 }
229 internal void DoHTTPstop()
118 { 230 {
119 OSHttpResponse response 231 OSHttpResponse response
120 = new OSHttpResponse(new HttpResponse(HttpContext, Request), HttpContext); 232 = new OSHttpResponse(new HttpResponse(HttpContext, Request), HttpContext);
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
index ec16d7c..b9ac155 100644
--- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
+++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
@@ -41,8 +41,6 @@ namespace OpenSim.Framework.Servers.HttpServer
41 { 41 {
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43 43
44 private readonly BaseHttpServer m_server;
45
46 private Dictionary<int, Queue<PollServiceHttpRequest>> m_bycontext; 44 private Dictionary<int, Queue<PollServiceHttpRequest>> m_bycontext;
47 private BlockingCollection<PollServiceHttpRequest> m_requests = new BlockingCollection<PollServiceHttpRequest>(); 45 private BlockingCollection<PollServiceHttpRequest> m_requests = new BlockingCollection<PollServiceHttpRequest>();
48 private ConcurrentQueue<PollServiceHttpRequest> m_retryRequests = new ConcurrentQueue<PollServiceHttpRequest>(); 46 private ConcurrentQueue<PollServiceHttpRequest> m_retryRequests = new ConcurrentQueue<PollServiceHttpRequest>();
@@ -56,9 +54,8 @@ namespace OpenSim.Framework.Servers.HttpServer
56 private SmartThreadPool m_threadPool; 54 private SmartThreadPool m_threadPool;
57 55
58 public PollServiceRequestManager( 56 public PollServiceRequestManager(
59 BaseHttpServer pSrv, bool performResponsesAsync, uint pWorkerThreadCount, int pTimeout) 57 bool performResponsesAsync, uint pWorkerThreadCount, int pTimeout)
60 { 58 {
61 m_server = pSrv;
62 m_WorkerThreadCount = pWorkerThreadCount; 59 m_WorkerThreadCount = pWorkerThreadCount;
63 m_workerThreads = new Thread[m_WorkerThreadCount]; 60 m_workerThreads = new Thread[m_WorkerThreadCount];
64 61
@@ -77,6 +74,8 @@ namespace OpenSim.Framework.Servers.HttpServer
77 74
78 public void Start() 75 public void Start()
79 { 76 {
77 if(m_running)
78 return;
80 m_running = true; 79 m_running = true;
81 m_threadPool.Start(); 80 m_threadPool.Start();
82 //startup worker threads 81 //startup worker threads
@@ -85,7 +84,7 @@ namespace OpenSim.Framework.Servers.HttpServer
85 m_workerThreads[i] 84 m_workerThreads[i]
86 = WorkManager.StartThread( 85 = WorkManager.StartThread(
87 PoolWorkerJob, 86 PoolWorkerJob,
88 string.Format("PollServiceWorkerThread {0}:{1}", i, m_server.Port), 87 string.Format("PollServiceWorkerThread {0}", i),
89 ThreadPriority.Normal, 88 ThreadPriority.Normal,
90 true, 89 true,
91 false, 90 false,
@@ -95,7 +94,7 @@ namespace OpenSim.Framework.Servers.HttpServer
95 94
96 m_retrysThread = WorkManager.StartThread( 95 m_retrysThread = WorkManager.StartThread(
97 this.CheckRetries, 96 this.CheckRetries,
98 string.Format("PollServiceWatcherThread:{0}", m_server.Port), 97 string.Format("PollServiceWatcherThread"),
99 ThreadPriority.Normal, 98 ThreadPriority.Normal,
100 true, 99 true,
101 true, 100 true,
@@ -183,6 +182,9 @@ namespace OpenSim.Framework.Servers.HttpServer
183 182
184 public void Stop() 183 public void Stop()
185 { 184 {
185 if(!m_running)
186 return;
187
186 m_running = false; 188 m_running = false;
187 189
188 Thread.Sleep(100); // let the world move 190 Thread.Sleep(100); // let the world move
@@ -202,7 +204,7 @@ namespace OpenSim.Framework.Servers.HttpServer
202 try 204 try
203 { 205 {
204 while(m_retryRequests.TryDequeue(out req)) 206 while(m_retryRequests.TryDequeue(out req))
205 req.DoHTTPstop(m_server); 207 req.DoHTTPstop();
206 } 208 }
207 catch 209 catch
208 { 210 {
@@ -211,7 +213,7 @@ namespace OpenSim.Framework.Servers.HttpServer
211 try 213 try
212 { 214 {
213 while(m_requests.TryTake(out req, 0)) 215 while(m_requests.TryTake(out req, 0))
214 req.DoHTTPstop(m_server); 216 req.DoHTTPstop();
215 } 217 }
216 catch 218 catch
217 { 219 {
@@ -266,7 +268,7 @@ namespace OpenSim.Framework.Servers.HttpServer
266 try 268 try
267 { 269 {
268 Hashtable responsedata = nreq.PollServiceArgs.GetEvents(nreq.RequestID, nreq.PollServiceArgs.Id); 270 Hashtable responsedata = nreq.PollServiceArgs.GetEvents(nreq.RequestID, nreq.PollServiceArgs.Id);
269 nreq.DoHTTPGruntWork(m_server, responsedata); 271 nreq.DoHTTPGruntWork(responsedata);
270 } 272 }
271 catch (ObjectDisposedException) { } 273 catch (ObjectDisposedException) { }
272 finally 274 finally
@@ -286,8 +288,7 @@ namespace OpenSim.Framework.Servers.HttpServer
286 { 288 {
287 try 289 try
288 { 290 {
289 nreq.DoHTTPGruntWork(m_server, 291 nreq.DoHTTPGruntWork(nreq.PollServiceArgs.NoEvents(nreq.RequestID, nreq.PollServiceArgs.Id));
290 nreq.PollServiceArgs.NoEvents(nreq.RequestID, nreq.PollServiceArgs.Id));
291 } 292 }
292 catch (ObjectDisposedException) {} 293 catch (ObjectDisposedException) {}
293 finally 294 finally