You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openmeetings.apache.org by so...@apache.org on 2021/01/13 17:45:59 UTC
[openmeetings] branch master updated: [OPENMEETINGS-2551] NetTest
client count can be limited
This is an automated email from the ASF dual-hosted git repository.
solomax pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openmeetings.git
The following commit(s) were added to refs/heads/master by this push:
new cbdfd2f [OPENMEETINGS-2551] NetTest client count can be limited
new 57d9531 Merge branch 'master' of github.com:apache/openmeetings
cbdfd2f is described below
commit cbdfd2f9731a8fe3daa9b4adf5da4a063fde161d
Author: Maxim Solodovnik <so...@gmail.com>
AuthorDate: Thu Jan 14 00:45:29 2021 +0700
[OPENMEETINGS-2551] NetTest client count can be limited
---
.../main/webapp/WEB-INF/classes/cxf-servlet.xml | 3 ++
.../webapp/WEB-INF/classes/openmeetings.properties | 3 ++
.../openmeetings/webservice/NetTestWebService.java | 50 +++++++++++++++++++---
3 files changed, 50 insertions(+), 6 deletions(-)
diff --git a/openmeetings-web/src/main/webapp/WEB-INF/classes/cxf-servlet.xml b/openmeetings-web/src/main/webapp/WEB-INF/classes/cxf-servlet.xml
index 38d3d60..6ba3b7d 100644
--- a/openmeetings-web/src/main/webapp/WEB-INF/classes/cxf-servlet.xml
+++ b/openmeetings-web/src/main/webapp/WEB-INF/classes/cxf-servlet.xml
@@ -23,6 +23,7 @@
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:jaxws="http://cxf.apache.org/jaxws"
+ xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
@@ -35,6 +36,8 @@
<context:annotation-config />
<context:component-scan base-package="org.apache.openmeetings.webservice" />
+ <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
+ p:location="classpath:openmeetings.properties" />
<!-- (writeXsiType=false) -->
<jaxrs:server id="server" address="/">
diff --git a/openmeetings-web/src/main/webapp/WEB-INF/classes/openmeetings.properties b/openmeetings-web/src/main/webapp/WEB-INF/classes/openmeetings.properties
index d1cd572..3dc2989 100644
--- a/openmeetings-web/src/main/webapp/WEB-INF/classes/openmeetings.properties
+++ b/openmeetings-web/src/main/webapp/WEB-INF/classes/openmeetings.properties
@@ -49,6 +49,9 @@ kurento.kuid=df992960-e7b0-11ea-9acd-337fb30dd93d
## this list can be space and/or comma separated
kurento.ignored.kuids=
+################## NetTest ##################
+nettest.max.clients=50
+
################## SIP ##################
### Should be updated with real values for Asterisk ###
sip.hostname=
diff --git a/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/NetTestWebService.java b/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/NetTestWebService.java
index 709cb95..0af9d02 100644
--- a/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/NetTestWebService.java
+++ b/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/NetTestWebService.java
@@ -22,7 +22,9 @@ package org.apache.openmeetings.webservice;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.annotation.PostConstruct;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
@@ -32,10 +34,12 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.Response.Status;
import org.apache.openmeetings.webservice.util.RateLimited;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@Service("netTestWebService")
@@ -53,6 +57,15 @@ public class NetTestWebService {
private static final int PING_PACKET_SIZE = 64;
private static final int JITTER_PACKET_SIZE = 1024;
private static final int MAX_UPLOAD_SIZE = 16 * 1024 * 1024;
+ private AtomicInteger clientCount = new AtomicInteger();
+
+ @Value("${nettest.max.clients}")
+ private int maxClients = 100;
+
+ @PostConstruct
+ private void report() {
+ log.debug("MaxClients: {}", maxClients);
+ }
@RateLimited
@GET
@@ -60,8 +73,15 @@ public class NetTestWebService {
@Path("/")
public Response get(@QueryParam("type") String type, @QueryParam("size") int inSize) {
final int size;
- TestType testType = getTypeByString(type);
+ final TestType testType = getTypeByString(type);
log.debug("Network test:: get, {}, {}", testType, inSize);
+ if (TestType.UNKNOWN == testType) {
+ return Response.status(Status.BAD_REQUEST).build();
+ }
+ if (clientCount.intValue() > maxClients) {
+ log.error("Download: Max client count reached");
+ return Response.status(Status.TOO_MANY_REQUESTS).build();
+ }
// choose data to send
switch (testType) {
@@ -72,6 +92,7 @@ public class NetTestWebService {
size = JITTER_PACKET_SIZE;
break;
default:
+ clientCount.incrementAndGet();
size = inSize;
break;
}
@@ -88,6 +109,14 @@ public class NetTestWebService {
public int available() throws IOException {
return size - pos;
}
+
+ @Override
+ public void close() throws IOException {
+ if (TestType.DOWNLOAD_SPEED == testType) {
+ clientCount.decrementAndGet();
+ }
+ super.close();
+ }
});
response.header("Cache-Control", "no-cache, no-store, no-transform");
response.header("Pragma", "no-cache");
@@ -102,13 +131,22 @@ public class NetTestWebService {
if (size > MAX_UPLOAD_SIZE) {
return;
}
+ if (clientCount.intValue() > maxClients) {
+ log.error("Upload: Max client count reached");
+ return;
+ }
+ clientCount.incrementAndGet();
byte[] b = new byte[1024];
- int totalCount = 0
- , count;
- while ((count = stream.read(b)) > -1) {
- totalCount += count;
+ int totalCount = 0;
+ int count;
+ try {
+ while ((count = stream.read(b)) > -1) {
+ totalCount += count;
+ }
+ log.debug("Total bytes read {}", totalCount);
+ } finally {
+ clientCount.decrementAndGet();
}
- log.debug("Total bytes read {}", totalCount);
}
public static TestType getTypeByString(String typeString) {