made pings more "fair"
This commit is contained in:
parent
e9ab5431e2
commit
17bf3bcbc4
7 changed files with 29196 additions and 29173 deletions
34274
javascript/classes.js
34274
javascript/classes.js
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
|
@ -35,7 +35,7 @@ public class RateLimiter {
|
||||||
locked = false;
|
locked = false;
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
long p = RateLimiter.this.period;
|
long p = RateLimiter.this.period / RateLimiter.this.limit;
|
||||||
int breaker = 0;
|
int breaker = 0;
|
||||||
while(millis - timer > p) {
|
while(millis - timer > p) {
|
||||||
timer += p;
|
timer += p;
|
||||||
|
|
|
@ -19,8 +19,10 @@ public interface ServerQuery {
|
||||||
public final boolean serverCracked;
|
public final boolean serverCracked;
|
||||||
public final RateLimit rateLimitStatus;
|
public final RateLimit rateLimitStatus;
|
||||||
public final boolean rateLimitIsTCP;
|
public final boolean rateLimitIsTCP;
|
||||||
public QueryResponse(JSONObject obj) {
|
public final long ping;
|
||||||
|
public QueryResponse(JSONObject obj, long ping) {
|
||||||
this.responseType = obj.getString("type").toLowerCase();
|
this.responseType = obj.getString("type").toLowerCase();
|
||||||
|
this.ping = ping;
|
||||||
if(this.responseType.equals("blocked") || this.responseType.equals("locked")) {
|
if(this.responseType.equals("blocked") || this.responseType.equals("locked")) {
|
||||||
this.responseData = null;
|
this.responseData = null;
|
||||||
this.serverVersion = "Unknown";
|
this.serverVersion = "Unknown";
|
||||||
|
@ -43,7 +45,8 @@ public interface ServerQuery {
|
||||||
this.rateLimitIsTCP = false;
|
this.rateLimitIsTCP = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public QueryResponse(boolean lockedNotBlocked) {
|
public QueryResponse(boolean lockedNotBlocked, long ping) {
|
||||||
|
this.ping = ping;
|
||||||
this.responseType = lockedNotBlocked ? "locked" : "blocked";
|
this.responseType = lockedNotBlocked ? "locked" : "blocked";
|
||||||
this.responseData = null;
|
this.responseData = null;
|
||||||
this.serverVersion = "Unknown";
|
this.serverVersion = "Unknown";
|
||||||
|
|
|
@ -2742,6 +2742,8 @@ public class EaglerAdapterImpl2 {
|
||||||
private boolean open;
|
private boolean open;
|
||||||
private boolean alive;
|
private boolean alive;
|
||||||
private String uriString;
|
private String uriString;
|
||||||
|
private long pingStart;
|
||||||
|
private long pingTimer;
|
||||||
|
|
||||||
private final WebSocket sock;
|
private final WebSocket sock;
|
||||||
|
|
||||||
|
@ -2749,6 +2751,8 @@ public class EaglerAdapterImpl2 {
|
||||||
type = type_;
|
type = type_;
|
||||||
uriString = uri;
|
uriString = uri;
|
||||||
alive = false;
|
alive = false;
|
||||||
|
pingStart = -1l;
|
||||||
|
pingTimer = -1l;
|
||||||
WebSocket s = null;
|
WebSocket s = null;
|
||||||
try {
|
try {
|
||||||
s = WebSocket.create(uri);
|
s = WebSocket.create(uri);
|
||||||
|
@ -2757,9 +2761,9 @@ public class EaglerAdapterImpl2 {
|
||||||
}catch(Throwable t) {
|
}catch(Throwable t) {
|
||||||
open = false;
|
open = false;
|
||||||
if(EaglerAdapterImpl2.blockedAddresses.contains(uriString)) {
|
if(EaglerAdapterImpl2.blockedAddresses.contains(uriString)) {
|
||||||
queryResponses.add(new QueryResponse(true));
|
queryResponses.add(new QueryResponse(true, -1l));
|
||||||
}else if(EaglerAdapterImpl2.rateLimitedAddresses.contains(uriString)) {
|
}else if(EaglerAdapterImpl2.rateLimitedAddresses.contains(uriString)) {
|
||||||
queryResponses.add(new QueryResponse(false));
|
queryResponses.add(new QueryResponse(false, -1l));
|
||||||
}
|
}
|
||||||
sock = null;
|
sock = null;
|
||||||
return;
|
return;
|
||||||
|
@ -2769,6 +2773,7 @@ public class EaglerAdapterImpl2 {
|
||||||
sock.onOpen(new EventListener<MessageEvent>() {
|
sock.onOpen(new EventListener<MessageEvent>() {
|
||||||
@Override
|
@Override
|
||||||
public void handleEvent(MessageEvent evt) {
|
public void handleEvent(MessageEvent evt) {
|
||||||
|
pingStart = System.currentTimeMillis();
|
||||||
sock.send("Accept: " + type);
|
sock.send("Accept: " + type);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -2778,9 +2783,9 @@ public class EaglerAdapterImpl2 {
|
||||||
open = false;
|
open = false;
|
||||||
if(!alive) {
|
if(!alive) {
|
||||||
if(EaglerAdapterImpl2.blockedAddresses.contains(uriString)) {
|
if(EaglerAdapterImpl2.blockedAddresses.contains(uriString)) {
|
||||||
queryResponses.add(new QueryResponse(true));
|
queryResponses.add(new QueryResponse(true, pingTimer));
|
||||||
}else if(EaglerAdapterImpl2.rateLimitedAddresses.contains(uriString)) {
|
}else if(EaglerAdapterImpl2.rateLimitedAddresses.contains(uriString)) {
|
||||||
queryResponses.add(new QueryResponse(false));
|
queryResponses.add(new QueryResponse(false, pingTimer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2789,21 +2794,24 @@ public class EaglerAdapterImpl2 {
|
||||||
@Override
|
@Override
|
||||||
public void handleEvent(MessageEvent evt) {
|
public void handleEvent(MessageEvent evt) {
|
||||||
alive = true;
|
alive = true;
|
||||||
|
if(pingTimer == -1) {
|
||||||
|
pingTimer = System.currentTimeMillis() - pingStart;
|
||||||
|
}
|
||||||
if(isString(evt.getData())) {
|
if(isString(evt.getData())) {
|
||||||
try {
|
try {
|
||||||
String str = evt.getDataAsString();
|
String str = evt.getDataAsString();
|
||||||
if(str.equalsIgnoreCase("BLOCKED")) {
|
if(str.equalsIgnoreCase("BLOCKED")) {
|
||||||
EaglerAdapterImpl2.rateLimitedAddresses.add(uriString);
|
EaglerAdapterImpl2.rateLimitedAddresses.add(uriString);
|
||||||
queryResponses.add(new QueryResponse(false));
|
queryResponses.add(new QueryResponse(false, pingTimer));
|
||||||
sock.close();
|
sock.close();
|
||||||
return;
|
return;
|
||||||
}else if(str.equalsIgnoreCase("LOCKED")) {
|
}else if(str.equalsIgnoreCase("LOCKED")) {
|
||||||
EaglerAdapterImpl2.blockedAddresses.add(uriString);
|
EaglerAdapterImpl2.blockedAddresses.add(uriString);
|
||||||
queryResponses.add(new QueryResponse(true));
|
queryResponses.add(new QueryResponse(true, pingTimer));
|
||||||
sock.close();
|
sock.close();
|
||||||
return;
|
return;
|
||||||
}else {
|
}else {
|
||||||
QueryResponse q = new QueryResponse(new JSONObject(str));
|
QueryResponse q = new QueryResponse(new JSONObject(str), pingTimer);
|
||||||
if(q.rateLimitStatus != null) {
|
if(q.rateLimitStatus != null) {
|
||||||
if(q.rateLimitStatus == RateLimit.BLOCKED) {
|
if(q.rateLimitStatus == RateLimit.BLOCKED) {
|
||||||
EaglerAdapterImpl2.rateLimitedAddresses.add(uriString);
|
EaglerAdapterImpl2.rateLimitedAddresses.add(uriString);
|
||||||
|
@ -2976,7 +2984,8 @@ public class EaglerAdapterImpl2 {
|
||||||
private String brand = "<no brand>";
|
private String brand = "<no brand>";
|
||||||
|
|
||||||
private long connectionOpenedAt;
|
private long connectionOpenedAt;
|
||||||
private int connectionPing = -1;
|
private long connectionPingStart = -1;
|
||||||
|
private long connectionPingTimer = -1;
|
||||||
|
|
||||||
private RateLimit rateLimitStatus = RateLimit.NONE;
|
private RateLimit rateLimitStatus = RateLimit.NONE;
|
||||||
|
|
||||||
|
@ -3003,6 +3012,7 @@ public class EaglerAdapterImpl2 {
|
||||||
@Override
|
@Override
|
||||||
public void handleEvent(MessageEvent evt) {
|
public void handleEvent(MessageEvent evt) {
|
||||||
try {
|
try {
|
||||||
|
connectionPingStart = System.currentTimeMillis();
|
||||||
nativeBinarySend(sock, convertToArrayBuffer(
|
nativeBinarySend(sock, convertToArrayBuffer(
|
||||||
IPacket.writePacket(new IPacket00Handshake(0x03, IntegratedServer.preferredRelayVersion, ""))
|
IPacket.writePacket(new IPacket00Handshake(0x03, IntegratedServer.preferredRelayVersion, ""))
|
||||||
));
|
));
|
||||||
|
@ -3046,7 +3056,9 @@ public class EaglerAdapterImpl2 {
|
||||||
if(pkt instanceof IPacket69Pong) {
|
if(pkt instanceof IPacket69Pong) {
|
||||||
IPacket69Pong ipkt = (IPacket69Pong)pkt;
|
IPacket69Pong ipkt = (IPacket69Pong)pkt;
|
||||||
versError = RelayQuery.VersionMismatch.COMPATIBLE;
|
versError = RelayQuery.VersionMismatch.COMPATIBLE;
|
||||||
connectionPing = (int)(System.currentTimeMillis() - connectionOpenedAt);
|
if(connectionPingTimer == -1) {
|
||||||
|
connectionPingTimer = System.currentTimeMillis() - connectionPingStart;
|
||||||
|
}
|
||||||
vers = ipkt.protcolVersion;
|
vers = ipkt.protcolVersion;
|
||||||
comment = ipkt.comment;
|
comment = ipkt.comment;
|
||||||
brand = ipkt.brand;
|
brand = ipkt.brand;
|
||||||
|
@ -3128,7 +3140,6 @@ public class EaglerAdapterImpl2 {
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
if(sock != null && open) {
|
if(sock != null && open) {
|
||||||
connectionPing = -1;
|
|
||||||
sock.close();
|
sock.close();
|
||||||
}
|
}
|
||||||
open = false;
|
open = false;
|
||||||
|
@ -3151,7 +3162,7 @@ public class EaglerAdapterImpl2 {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getPing() {
|
public long getPing() {
|
||||||
return connectionPing;
|
return connectionPingTimer < 1 ? 1 : connectionPingTimer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue