pull/1/head
Ivan Olexyn 5 years ago
parent 8cdfed0d96
commit 2aa1eb7339

@ -1,18 +1,35 @@
### About
The goal of this project is to bypass the limitations caused by ISPs blocking incoming connections.
It is estimated to require two servlets - one on the webhost (`mispbridge`), and one on the localhost (`mispclient`).
To do so have an adapter or reverse-proxy `reverse`.
It sends `Rides` to a forward-proxy servlet `forward`.
This servlet waits for a request, and fills the `Ride` with the request.
`reverse` can then forward the request to the `app`.
Upon recieving a reply with data from `app`, `reverse` will forward this data to `forward`,
which in turn will finally forward it to `user`.
<br>
### Overview
![](overview.png)
#### What works:
* Forwarding GET requests (including HTTPS).
#### What does not work:
* Handling 301 (Moved Permanently).
* Forwarding PUT requests - if needed, the logic might be quickly added to `doPut` in `forward`.
* The `forward.war` has issues - meanwhile run `forward` embedded with Jetty.
<br>
### Run / Deploy
### Demo
### Demo<a name="demo"></a>
[![IMAGE ALT TEXT](http://img.youtube.com/vi/WcSvzeu6nKo/0.jpg)](https://youtu.be/WcSvzeu6nKo "misp Demo")
<br>
### Run / Deploy
#### How to Run / Debug
* `com.olexyn.misp.embedded.RunAll.main()`
@ -23,8 +40,3 @@ It is estimated to require two servlets - one on the webhost (`mispbridge`), and
* Build (e.g. with `build-install-all.sh`)
* Put the generated `forward-0.1.war` in a servlet container (e.g. Jetty).
* Launch the `reverse-0.1.jar` on your host.
<br>
### TODO
* See [TODO.md](TODO.md).

@ -1,17 +0,0 @@
#### TODO
* Use real `app`
* Replace `AppMock` with *guacamole*
* Does *guac* take *json*?
* Adjust `UserMock` to query *guac*.
* Adjust `MockClient` to forward *guac*-query.
* Copy & adapt the `mispmock` code to `mispclient` and `mispbridge`
* Test with Tomcat
<br>
<br>
#### DO MAYBE
*
*

@ -0,0 +1,5 @@
#### About
* Uses `com.olexyn.min.http.server.MinJettyServer` to host the servlets.
* Where to adjust the parameters:
* for `forward` -> `EmbeddedR`
* for `reverse` -> `RunAll`

@ -5,7 +5,7 @@ import com.olexyn.misp.forward.Forward;
import com.olexyn.misp.mirror.Mirror;
public class Embedded implements Runnable {
public class EmbeddedR implements Runnable {
@Override

@ -6,14 +6,16 @@ public class RunAll {
public static void main(String... args) throws InterruptedException {
Thread serverT = new Thread(new Embedded());
serverT.start();
Thread embeddedT = new Thread(new EmbeddedR());
embeddedT.start();
Thread.sleep(2000);
Reverse reverse = new Reverse();
reverse.FORWARD_URL = "http://localhost:8090/forward";
reverse.APP_URL = "http://localhost:8090/app";
reverse.APP_URL = "https://olexyn.com/wp/";
Thread reverseT = new Thread(reverse);
reverseT.start();

@ -1,2 +1,9 @@
#### About
The `forward` servlet.
#### Deploy
* Run `install-locally.sh`
* Find the `forward-0.1.war` in `./target`
* copy it to `tomcat/webapps`.
* Assuming tomcat runs at `http://localhost:9090`
* Then the servlet will be at `http://localhost:9090/mirror-0.1/mirror`

@ -87,7 +87,6 @@
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>

@ -16,44 +16,34 @@ import java.util.Map;
public class Forward extends HttpServlet {
protected static final String MISP_CLIENT_URL = "http://localhost:9090/mispclient/core";
private static final long WAIT_FOR_USER_REQUEST = 500;
public final Map<Long, Ride> available = new HashMap<>();
public final Map<Long, Ride> booked = new HashMap<>();
public final Map<Long, Ride> loaded = new HashMap<>();
private final Map<Long, Ride> available = new HashMap<>();
private final Map<Long, Ride> booked = new HashMap<>();
private final Map<Long, Ride> loaded = new HashMap<>();
// #######
//
// #######
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
public void doGet(HttpServletRequest request, HttpServletResponse response) {
Thread handleGetRequestThread = new Thread(() -> {
try {
handleGetRequest(request, response);
} catch (IOException | InterruptedException e) {e.printStackTrace(); }
});
Thread handleGetRequestThread = new Thread(() -> { handleGetRequest(request, response); });
handleGetRequestThread.setName("handleGetRequestThread");
handleGetRequestThread.start();
try {handleGetRequestThread.join(); } catch (InterruptedException ignored) { }
}
/**
* handle GET (Link)
* remove Ride from AvailableRides
* add Ride to ReservedRides
* send OK (Ride) to mispclient
* send OK (Ride) to public
* Handle GET (Request).
* Remove next Ride from `available`.
* Put the Ride to `booked`.
* Wait for Ride to appear in `loaded`. This happens due to POST (Ride)(Request)(Data) from `reverse`.
* Finally send OK (Data) to `user`.
*/
protected void handleGetRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, InterruptedException {
final Ride ride;
protected void handleGetRequest(HttpServletRequest request, HttpServletResponse response) {
try {
final Ride ride;
final ServletInputStream in = request.getInputStream();
final String parsedRequest = new String(in.readAllBytes());
@ -72,6 +62,7 @@ public class Forward extends HttpServlet {
available.notify();
}
synchronized (booked) {
// ride exists only locally, thus safe
booked.put(ride.getID(), ride);
@ -81,30 +72,21 @@ public class Forward extends HttpServlet {
booked.notify();
}
synchronized (loaded) {
boolean realcondition = !loaded.containsKey(ride.getID());
boolean relaxedcondition = loaded.size() == 0;
synchronized (loaded) {
while (loaded.size() == 0) {
while (!loaded.containsKey(ride.getID())) {
loaded.notify();
if (loaded.size() > 0) {
break;
}
if (loaded.size() > 0) { break; }
loaded.wait();
}
// CARE this is tricky
// what if ride exists in another map, e.g. "available'
// in that case illegal access is possible
// be carefull to removing ride from all other references, when adding it to "loaded".
Ride badbad__ride = loaded.entrySet().iterator().next().getValue();
ride.setData(loaded.remove(badbad__ride.getID()).getData());
//ride.setData(loaded.remove(ride.getID()).getData());
ride.setData(loaded.remove(ride.getID()).getData());
}
response.setStatus(200);
@ -112,55 +94,11 @@ public class Forward extends HttpServlet {
writer.write(ride.getData());
writer.flush();
writer.close();
}
/**
* handle GET (Ride)(Data)
* if Ride in ForwardedRequest
* remove Ride from ForwardedRequest
* add Ride to NewData
* send OK (Ride)(Data)
* remove Ride from NewData
* add Ride to ForwardedData
* send OK (EOL)
* remove Ride from ForwardedData
* add Ride to EOL
*/
protected void handlePostRideRequestData(HttpServletRequest request, HttpServletResponse response, String payload) {
final String _payload = payload;
final Ride ride = new Ride(_payload);
synchronized (booked) {
booked.remove(ride.getID());
}
synchronized (loaded) {
loaded.put(ride.getID(), ride);
loaded.notify();
}
}
protected void handlePostAvailable(HttpServletRequest request, HttpServletResponse response) {
JSONObject obj = new JSONObject();
obj.put("available", available.size());
response.setStatus(200);
try {
PrintWriter writer = response.getWriter();
writer.write(obj.toString());
writer.flush();
writer.close();
} catch (Exception ignored) {}
}
// #######
//
// #######
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
@ -181,7 +119,7 @@ public class Forward extends HttpServlet {
boolean hasData = obj.has("data") && obj.getString("data") != null;
if (obj.has("id") && !hasData) {
Thread handlePostRideT = new Thread(() -> { handlePostRide(request, response); });
Thread handlePostRideT = new Thread(() -> { handlePostRide(request, response, payload); });
handlePostRideT.setName("handlePostRideT");
handlePostRideT.start();
try {handlePostRideT.join(); } catch (InterruptedException ignored) { }
@ -195,17 +133,54 @@ public class Forward extends HttpServlet {
}
}
/**
* handle POST (Ride)
* add Ride to AvailableRides
* Handle POST (Ride)(Request)(Data)
* Move the Ride from `booked` to `loaded`, so it can be picked up by OK (Data) of GET (Request).
*/
protected void handlePostRide(HttpServletRequest request, HttpServletResponse response) {
protected void handlePostRideRequestData(HttpServletRequest request, HttpServletResponse response, String payload) {
final Ride ride = new Ride(payload);
synchronized (booked) {
booked.remove(ride.getID());
}
synchronized (loaded) {
loaded.put(ride.getID(), ride);
loaded.notify();
}
}
/**
* Handle POST (Available).
* Send current # of available Rides to `reverse`.
*/
protected void handlePostAvailable(HttpServletRequest request, HttpServletResponse response) {
JSONObject obj = new JSONObject().put("available", available.size());
response.setStatus(200);
try {
String jsonPayload = IOUtils.toString(request.getReader());
PrintWriter writer = response.getWriter();
writer.write(obj.toString());
writer.flush();
writer.close();
} catch (Exception ignored) {}
}
final Ride ride = new Ride(jsonPayload);
/**
* Handle POST (Ride).
* Add Ride to `available`.
* Wait till a GET (Request) arrives from `user`.
* Return OK (Ride)(Request) to `reverse`.
*/
protected void handlePostRide(HttpServletRequest request, HttpServletResponse response, String payload) {
try {
final Ride ride = new Ride(payload);
synchronized (available) {
available.put(ride.getID(), ride);
@ -214,16 +189,13 @@ public class Forward extends HttpServlet {
// ID is final/threadsafe
while (!(booked.containsKey(ride.getID()))) {
Thread.sleep(500);
Thread.sleep(WAIT_FOR_USER_REQUEST);
}
synchronized (booked) {
//booked.notify();
//booked.wait();
ride.setRequest(booked.get(ride.getID()).getRequest());
}
response.setStatus(200);
PrintWriter writer = response.getWriter();
writer.write(ride.json());
@ -231,6 +203,5 @@ public class Forward extends HttpServlet {
writer.close();
} catch (Exception ignored) {}
}
}

@ -16,7 +16,7 @@
<servlet-mapping>
<servlet-name>misp-fwd</servlet-name>
<url-pattern>/core</url-pattern>
<url-pattern>/forward</url-pattern>
</servlet-mapping>
</web-app>

@ -3,7 +3,6 @@ package com.olexyn.misp.helper;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Objects;
public class Ride {
@ -14,70 +13,24 @@ public class Ride {
private String data;
public Ride() {
id = count++;
}
public Ride(String jsonString) {
JSONObject obj = new JSONObject();
try {
obj = new JSONObject(jsonString);
}catch (JSONException e){
int br = 0;
}
public Ride(String jsonString) { this(new JSONObject(jsonString)); }
public Ride(JSONObject obj) {
long _id;
try {
_id = obj.getLong("id");
}catch (JSONException e){
_id = count++;
}
try { _id = obj.getLong("id"); } catch (JSONException e) { _id = count++; }
id = _id;
try{
request = obj.getString("request");
} catch (JSONException e){
request = null;
}
try{
data = obj.getString("data");
}catch (JSONException e){
data = null;
}
try { request = obj.getString("request"); } catch (JSONException e) { request = null; }
try { data = obj.getString("data"); } catch (JSONException e) { data = null; }
}
public Ride(JSONObject obj){
long _id;
try {
_id = obj.getLong("id");
}catch (JSONException e){
_id = count++;
}
id = _id;
try{
request = obj.getString("request");
} catch (JSONException e){
request = null;
}
try{
data = obj.getString("data");
}catch (JSONException e){
data = null;
}
}
public void setRequest(String request) {
this.request = request;
}
@ -86,9 +39,6 @@ public class Ride {
this.data = data;
}
public String getRequest() {
return this.request;
}
@ -102,36 +52,13 @@ public class Ride {
}
private String brace(String foo) {
return "\"" + foo + "\"";
}
private String unbrace(String foo) { return foo.replace("\"", ""); }
public String json() {
JSONObject obj = new JSONObject();
obj.put("id", id);
obj.put("request", request);
obj.put("data",data);
obj.put("data", data);
return obj.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Ride ride = (Ride) o;
return Objects.equals(id, ride.id) && Objects.equals(request, ride.request) && Objects.equals(data, ride.data);
}
@Override
public int hashCode() {
return Objects.hash(id, request, data);
}
}

@ -1,5 +1,9 @@
#### About
The `mirror` servlet. Prints the list of request it received.
* `./src` the code.
* `./war/wrapper` supplements needed for `.war`.
* `./war/<name>.war` copy this to `tomcat/webapps`.
#### Deploy
* Run `install-locally.sh`
* Find the `mirror-0.1.war` in `./target`
* copy it to `tomcat/webapps`.
* Assuming tomcat runs at `http://localhost:9090`
* Then the servlet will be at `http://localhost:9090/mirror-0.1/mirror`

@ -53,7 +53,6 @@
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>

@ -17,7 +17,7 @@
<servlet-mapping>
<servlet-name>misp-mirror</servlet-name>
<url-pattern>/core</url-pattern>
<url-pattern>/mirror</url-pattern>
</servlet-mapping>
</web-app>

@ -4,8 +4,8 @@
<element>
<id>UMLClass</id>
<coordinates>
<x>1250</x>
<y>410</y>
<x>1210</x>
<y>260</y>
<w>90</w>
<h>70</h>
</coordinates>
@ -17,8 +17,8 @@ lt=-</panel_attributes>
<element>
<id>UMLClass</id>
<coordinates>
<x>1250</x>
<y>750</y>
<x>1210</x>
<y>600</y>
<w>90</w>
<h>30</h>
</coordinates>
@ -29,8 +29,8 @@ bg=#90CAF9</panel_attributes>
<element>
<id>UMLClass</id>
<coordinates>
<x>1020</x>
<y>750</y>
<x>980</x>
<y>600</y>
<w>100</w>
<h>30</h>
</coordinates>
@ -42,8 +42,8 @@ layer=-1</panel_attributes>
<element>
<id>Relation</id>
<coordinates>
<x>770</x>
<y>820</y>
<x>730</x>
<y>670</y>
<w>280</w>
<h>50</h>
</coordinates>
@ -55,8 +55,8 @@ Generated by Loop</panel_attributes>
<element>
<id>Relation</id>
<coordinates>
<x>1100</x>
<y>860</y>
<x>1060</x>
<y>710</y>
<w>200</w>
<h>40</h>
</coordinates>
@ -68,8 +68,8 @@ fg=#1E88E5</panel_attributes>
<element>
<id>UMLClass</id>
<coordinates>
<x>690</x>
<y>750</y>
<x>650</x>
<y>600</y>
<w>100</w>
<h>30</h>
</coordinates>
@ -81,8 +81,8 @@ layer=-1</panel_attributes>
<element>
<id>Relation</id>
<coordinates>
<x>770</x>
<y>970</y>
<x>730</x>
<y>820</y>
<w>280</w>
<h>50</h>
</coordinates>
@ -94,8 +94,8 @@ POST (Ride)(Request)
<element>
<id>Relation</id>
<coordinates>
<x>1100</x>
<y>990</y>
<x>1060</x>
<y>840</y>
<w>200</w>
<h>40</h>
</coordinates>
@ -107,8 +107,8 @@ fg=#1E88E5</panel_attributes>
<element>
<id>Relation</id>
<coordinates>
<x>770</x>
<y>1030</y>
<x>730</x>
<y>880</y>
<w>280</w>
<h>40</h>
</coordinates>
@ -119,8 +119,8 @@ OK (Ride)</panel_attributes>
<element>
<id>UMLClass</id>
<coordinates>
<x>490</x>
<y>750</y>
<x>450</x>
<y>600</y>
<w>80</w>
<h>30</h>
</coordinates>
@ -131,8 +131,8 @@ bg=#90CAF9</panel_attributes>
<element>
<id>Relation</id>
<coordinates>
<x>530</x>
<y>900</y>
<x>490</x>
<y>750</y>
<w>190</w>
<h>40</h>
</coordinates>
@ -144,8 +144,8 @@ fg=#1E88E5</panel_attributes>
<element>
<id>Relation</id>
<coordinates>
<x>530</x>
<y>950</y>
<x>490</x>
<y>800</y>
<w>190</w>
<h>40</h>
</coordinates>
@ -157,8 +157,8 @@ fg=#1E88E5</panel_attributes>
<element>
<id>Relation</id>
<coordinates>
<x>770</x>
<y>880</y>
<x>730</x>
<y>730</y>
<w>280</w>
<h>40</h>
</coordinates>
@ -169,8 +169,8 @@ OK (Ride)(Request)</panel_attributes>
<element>
<id>UMLClass</id>
<coordinates>
<x>490</x>
<y>410</y>
<x>450</x>
<y>260</y>
<w>300</w>
<h>70</h>
</coordinates>
@ -182,8 +182,8 @@ lt=-</panel_attributes>
<element>
<id>UMLClass</id>
<coordinates>
<x>460</x>
<y>810</y>
<x>420</x>
<y>660</y>
<w>910</w>
<h>280</h>
</coordinates>
@ -195,8 +195,8 @@ layer=-10</panel_attributes>
<element>
<id>UMLClass</id>
<coordinates>
<x>1030</x>
<y>840</y>
<x>990</x>
<y>690</y>
<w>80</w>
<h>40</h>
</coordinates>
@ -209,8 +209,8 @@ transparency=0</panel_attributes>
<element>
<id>UMLClass</id>
<coordinates>
<x>700</x>
<y>840</y>
<x>660</x>
<y>690</y>
<w>80</w>
<h>210</h>
</coordinates>
@ -223,8 +223,8 @@ transparency=0</panel_attributes>
<element>
<id>UMLClass</id>
<coordinates>
<x>1030</x>
<y>880</y>
<x>990</x>
<y>730</y>
<w>80</w>
<h>110</h>
</coordinates>
@ -238,8 +238,8 @@ layer=1</panel_attributes>
<element>
<id>UMLClass</id>
<coordinates>
<x>1030</x>
<y>990</y>
<x>990</x>
<y>840</y>
<w>80</w>
<h>60</h>
</coordinates>
@ -252,8 +252,8 @@ transparency=0</panel_attributes>
<element>
<id>Relation</id>
<coordinates>
<x>1280</x>
<y>770</y>
<x>1240</x>
<y>620</y>
<w>30</w>
<h>320</h>
</coordinates>
@ -264,8 +264,8 @@ fg=#1E88E5</panel_attributes>
<element>
<id>Relation</id>
<coordinates>
<x>520</x>
<y>770</y>
<x>480</x>
<y>620</y>
<w>30</w>
<h>320</h>
</coordinates>
@ -276,8 +276,8 @@ fg=#1E88E5</panel_attributes>
<element>
<id>UMLClass</id>
<coordinates>
<x>1280</x>
<y>880</y>
<x>1240</x>
<y>730</y>
<w>20</w>
<h>130</h>
</coordinates>
@ -290,8 +290,8 @@ layer=4</panel_attributes>
<element>
<id>UMLClass</id>
<coordinates>
<x>520</x>
<y>920</y>
<x>480</x>
<y>770</y>
<w>20</w>
<h>50</h>
</coordinates>
@ -304,8 +304,8 @@ layer=4</panel_attributes>
<element>
<id>Relation</id>
<coordinates>
<x>1060</x>
<y>770</y>
<x>1020</x>
<y>620</y>
<w>30</w>
<h>320</h>
</coordinates>
@ -317,8 +317,8 @@ layer=-4</panel_attributes>
<element>
<id>Relation</id>
<coordinates>
<x>730</x>
<y>770</y>
<x>690</x>
<y>620</y>
<w>30</w>
<h>320</h>
</coordinates>
@ -330,8 +330,8 @@ layer=-4</panel_attributes>
<element>
<id>UMLClass</id>
<coordinates>
<x>700</x>
<y>590</y>
<x>660</x>
<y>440</y>
<w>80</w>
<h>50</h>
</coordinates>
@ -344,8 +344,8 @@ transparency=0</panel_attributes>
<element>
<id>UMLClass</id>
<coordinates>
<x>850</x>
<y>410</y>
<x>810</x>
<y>260</y>
<w>120</w>
<h>70</h>
</coordinates>
@ -357,8 +357,8 @@ modem</panel_attributes>
<element>
<id>UMLClass</id>
<coordinates>
<x>1020</x>
<y>410</y>
<x>980</x>
<y>260</y>
<w>100</w>
<h>70</h>
</coordinates>
@ -371,8 +371,8 @@ layer=-1</panel_attributes>
<element>
<id>UMLClass</id>
<coordinates>
<x>1020</x>
<y>510</y>
<x>980</x>
<y>360</y>
<w>100</w>
<h>30</h>
</coordinates>
@ -384,8 +384,8 @@ layer=-1</panel_attributes>
<element>
<id>UMLClass</id>
<coordinates>
<x>690</x>
<y>510</y>
<x>650</x>
<y>360</y>
<w>100</w>
<h>30</h>
</coordinates>
@ -397,8 +397,8 @@ layer=-1</panel_attributes>
<element>
<id>UMLClass</id>
<coordinates>
<x>460</x>
<y>570</y>
<x>420</x>
<y>420</y>
<w>910</w>
<h>110</h>
</coordinates>
@ -410,8 +410,8 @@ layer=-10</panel_attributes>
<element>
<id>UMLClass</id>
<coordinates>
<x>1030</x>
<y>590</y>
<x>990</x>
<y>440</y>
<w>80</w>
<h>50</h>
</coordinates>
@ -424,8 +424,8 @@ transparency=0</panel_attributes>
<element>
<id>Relation</id>
<coordinates>
<x>1060</x>
<y>530</y>
<x>1020</x>
<y>380</y>
<w>30</w>
<h>150</h>
</coordinates>
@ -437,8 +437,8 @@ layer=-4</panel_attributes>
<element>
<id>Relation</id>
<coordinates>
<x>730</x>
<y>530</y>
<x>690</x>
<y>380</y>
<w>30</w>
<h>150</h>
</coordinates>
@ -450,8 +450,8 @@ layer=-4</panel_attributes>
<element>
<id>Relation</id>
<coordinates>
<x>770</x>
<y>580</y>
<x>730</x>
<y>430</y>
<w>280</w>
<h>40</h>
</coordinates>
@ -462,8 +462,8 @@ POST (Available)</panel_attributes>
<element>
<id>Relation</id>
<coordinates>
<x>770</x>
<y>610</y>
<x>730</x>
<y>460</y>
<w>280</w>
<h>40</h>
</coordinates>

@ -1,6 +1,9 @@
package com.olexyn.misp.reverse;
import com.olexyn.misp.reverse.runnable.CheckSuppyR;
import com.olexyn.misp.reverse.runnable.JourneyGeneratorR;
public class Reverse implements Runnable {
public String FORWARD_URL = "http://localhost:8090/forward";
@ -15,7 +18,7 @@ public class Reverse implements Runnable {
checkSupplyT.setName("checkSupplyT");
checkSupplyT.start();
Thread journeyGeneratorT = new Thread(new JourneyGenerator(this, checkSuppyR));
Thread journeyGeneratorT = new Thread(new JourneyGeneratorR(this, checkSuppyR));
journeyGeneratorT.setName("journeyGeneratorT");
journeyGeneratorT.start();
}

@ -10,7 +10,7 @@ import java.net.URL;
public class Tools {
static String send(String method, String urlString, String body) throws IOException {
public static String send(String method, String urlString, String body) throws IOException {
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
@ -22,20 +22,14 @@ public class Tools {
if (method.equals("POST") || getToForward) {
connection.setDoOutput(true);
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
if (body != null) {
outputStream.writeBytes(body);
}
if (body != null) { outputStream.writeBytes(body); }
outputStream.flush();
outputStream.close();
}
int i = connection.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String out;
StringBuilder sb = new StringBuilder();

@ -1,5 +1,7 @@
package com.olexyn.misp.reverse;
package com.olexyn.misp.reverse.runnable;
import com.olexyn.misp.reverse.Reverse;
import com.olexyn.misp.reverse.Tools;
import org.json.JSONObject;
public class CheckSuppyR implements Runnable {

@ -1,7 +1,9 @@
package com.olexyn.misp.reverse;
package com.olexyn.misp.reverse.runnable;
public class JourneyGenerator implements Runnable {
import com.olexyn.misp.reverse.Reverse;
public class JourneyGeneratorR implements Runnable {
public int OVERHEAD = 8;
public int CHECK_DEPLETION_INTERVAL = 500;
@ -10,7 +12,7 @@ public class JourneyGenerator implements Runnable {
private Reverse reverse;
private CheckSuppyR checkSuppyR;
public JourneyGenerator(Reverse reverse , CheckSuppyR checkSuppyR) {
public JourneyGeneratorR(Reverse reverse , CheckSuppyR checkSuppyR) {
this.reverse = reverse;
this.checkSuppyR = checkSuppyR;
}
@ -19,16 +21,23 @@ public class JourneyGenerator implements Runnable {
@Override
public void run() {
int LIMIT = 0;
while (true) {
try {
Thread journeyT = new Thread(new JourneyR(reverse));
journeyT.setName("journeyT");
journeyT.start();
LIMIT++;
while (checkSuppyR.getAvailable() > OVERHEAD) { Thread.sleep(CHECK_DEPLETION_INTERVAL); }
while (checkSuppyR.getAvailable() > OVERHEAD ) { Thread.sleep(CHECK_DEPLETION_INTERVAL); }
Thread.sleep(START_NEW_JOURNEY_INTERVAL);
if(LIMIT > 2* OVERHEAD){
Thread.sleep(CHECK_DEPLETION_INTERVAL);
LIMIT = 0;
}
// TODO rework this, so it sends - but not too much, and so it wais - but not too long.
} catch (Exception ignored) { }
}

@ -1,6 +1,8 @@
package com.olexyn.misp.reverse;
package com.olexyn.misp.reverse.runnable;
import com.olexyn.misp.helper.Ride;
import com.olexyn.misp.reverse.Reverse;
import com.olexyn.misp.reverse.Tools;
import java.io.IOException;
Loading…
Cancel
Save