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

@ -1,18 +1,35 @@
### About ### About
The goal of this project is to bypass the limitations caused by ISPs blocking incoming connections. 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> <br>
### Overview ### Overview
![](overview.png) ![](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> <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> <br>
### Run / Deploy
#### How to Run / Debug #### How to Run / Debug
* `com.olexyn.misp.embedded.RunAll.main()` * `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`) * Build (e.g. with `build-install-all.sh`)
* Put the generated `forward-0.1.war` in a servlet container (e.g. Jetty). * Put the generated `forward-0.1.war` in a servlet container (e.g. Jetty).
* Launch the `reverse-0.1.jar` on your host. * 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; import com.olexyn.misp.mirror.Mirror;
public class Embedded implements Runnable { public class EmbeddedR implements Runnable {
@Override @Override

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

@ -1,2 +1,9 @@
#### About #### About
The `forward` servlet. 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> <build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins> <plugins>
<plugin> <plugin>

@ -16,151 +16,89 @@ import java.util.Map;
public class Forward extends HttpServlet { 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<>(); private final Map<Long, Ride> available = new HashMap<>();
public final Map<Long, Ride> booked = new HashMap<>(); private final Map<Long, Ride> booked = new HashMap<>();
public final Map<Long, Ride> loaded = new HashMap<>(); private final Map<Long, Ride> loaded = new HashMap<>();
// #######
//
// #######
@Override @Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { public void doGet(HttpServletRequest request, HttpServletResponse response) {
Thread handleGetRequestThread = new Thread(() -> { handleGetRequest(request, response); });
Thread handleGetRequestThread = new Thread(() -> {
try {
handleGetRequest(request, response);
} catch (IOException | InterruptedException e) {e.printStackTrace(); }
});
handleGetRequestThread.setName("handleGetRequestThread"); handleGetRequestThread.setName("handleGetRequestThread");
handleGetRequestThread.start(); handleGetRequestThread.start();
try {handleGetRequestThread.join(); } catch (InterruptedException ignored) { } try {handleGetRequestThread.join(); } catch (InterruptedException ignored) { }
} }
/** /**
* handle GET (Link) * Handle GET (Request).
* remove Ride from AvailableRides * Remove next Ride from `available`.
* add Ride to ReservedRides * Put the Ride to `booked`.
* send OK (Ride) to mispclient * Wait for Ride to appear in `loaded`. This happens due to POST (Ride)(Request)(Data) from `reverse`.
* send OK (Ride) to public * Finally send OK (Data) to `user`.
*/ */
protected void handleGetRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, InterruptedException { protected void handleGetRequest(HttpServletRequest request, HttpServletResponse response) {
final Ride ride; try {
final ServletInputStream in = request.getInputStream(); final Ride ride;
final String parsedRequest = new String(in.readAllBytes()); final ServletInputStream in = request.getInputStream();
final String parsedRequest = new String(in.readAllBytes());
synchronized (available) { synchronized (available) {
while (available.size() < 1) { while (available.size() < 1) {
available.notify();
available.wait();
}
// ride exists only locally, thus safe
ride = available.entrySet().iterator().next().getValue();
// ride exists only in "available", access through which is sync, thus safe
available.remove(ride.getID());
// needed because POST (Ride) wait()s
available.notify(); available.notify();
available.wait();
} }
// ride exists only locally, thus safe
ride = available.entrySet().iterator().next().getValue();
// ride exists only in "available", access through which is sync, thus safe
available.remove(ride.getID());
// needed because POST (Ride) wait()s
available.notify();
}
synchronized (booked) {
// ride exists only locally, thus safe
booked.put(ride.getID(), ride);
// ride exists only in "booked", access through which is sync, thus safe
ride.setRequest(parsedRequest);
// POST (Ride) wait()s
booked.notify();
}
synchronized (loaded) {
boolean realcondition = !loaded.containsKey(ride.getID());
boolean relaxedcondition = loaded.size() == 0;
while (loaded.size() == 0) {
loaded.notify();
if (loaded.size() > 0) {
break;
}
loaded.wait();
synchronized (booked) {
// ride exists only locally, thus safe
booked.put(ride.getID(), ride);
// ride exists only in "booked", access through which is sync, thus safe
ride.setRequest(parsedRequest);
// POST (Ride) wait()s
booked.notify();
} }
// CARE this is tricky synchronized (loaded) {
// 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());
}
response.setStatus(200);
final PrintWriter writer = response.getWriter();
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) { while (!loaded.containsKey(ride.getID())) {
loaded.put(ride.getID(), ride);
loaded.notify();
}
}
loaded.notify();
if (loaded.size() > 0) { break; }
loaded.wait();
}
protected void handlePostAvailable(HttpServletRequest request, HttpServletResponse response) { // CARE this is tricky
JSONObject obj = new JSONObject(); // what if ride exists in another map, e.g. "available'
obj.put("available", available.size()); // in that case illegal access is possible
// be carefull to removing ride from all other references, when adding it to "loaded".
ride.setData(loaded.remove(ride.getID()).getData());
}
response.setStatus(200); response.setStatus(200);
try { final PrintWriter writer = response.getWriter();
PrintWriter writer = response.getWriter(); writer.write(ride.getData());
writer.write(obj.toString());
writer.flush(); writer.flush();
writer.close(); writer.close();
} catch (Exception ignored) {} } catch (Exception ignored) {}
} }
// #######
//
// #######
@Override @Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { 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; boolean hasData = obj.has("data") && obj.getString("data") != null;
if (obj.has("id") && !hasData) { if (obj.has("id") && !hasData) {
Thread handlePostRideT = new Thread(() -> { handlePostRide(request, response); }); Thread handlePostRideT = new Thread(() -> { handlePostRide(request, response, payload); });
handlePostRideT.setName("handlePostRideT"); handlePostRideT.setName("handlePostRideT");
handlePostRideT.start(); handlePostRideT.start();
try {handlePostRideT.join(); } catch (InterruptedException ignored) { } try {handlePostRideT.join(); } catch (InterruptedException ignored) { }
@ -195,17 +133,54 @@ public class Forward extends HttpServlet {
} }
} }
/** /**
* handle POST (Ride) * Handle POST (Ride)(Request)(Data)
* add Ride to AvailableRides * 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 { 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) { synchronized (available) {
available.put(ride.getID(), ride); available.put(ride.getID(), ride);
@ -214,16 +189,13 @@ public class Forward extends HttpServlet {
// ID is final/threadsafe // ID is final/threadsafe
while (!(booked.containsKey(ride.getID()))) { while (!(booked.containsKey(ride.getID()))) {
Thread.sleep(500); Thread.sleep(WAIT_FOR_USER_REQUEST);
} }
synchronized (booked) { synchronized (booked) {
//booked.notify();
//booked.wait();
ride.setRequest(booked.get(ride.getID()).getRequest()); ride.setRequest(booked.get(ride.getID()).getRequest());
} }
response.setStatus(200); response.setStatus(200);
PrintWriter writer = response.getWriter(); PrintWriter writer = response.getWriter();
writer.write(ride.json()); writer.write(ride.json());
@ -231,6 +203,5 @@ public class Forward extends HttpServlet {
writer.close(); writer.close();
} catch (Exception ignored) {} } catch (Exception ignored) {}
} }
} }

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

@ -3,7 +3,6 @@ package com.olexyn.misp.helper;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Objects;
public class Ride { public class Ride {
@ -14,70 +13,24 @@ public class Ride {
private String data; private String data;
public Ride() { public Ride() {
id = count++; id = count++;
} }
public Ride(String jsonString) { public Ride(String jsonString) { this(new JSONObject(jsonString)); }
JSONObject obj = new JSONObject();
try {
obj = new JSONObject(jsonString);
}catch (JSONException e){
int br = 0;
}
public Ride(JSONObject obj) {
long _id; long _id;
try { _id = obj.getLong("id"); } catch (JSONException e) { _id = count++; }
try {
_id = obj.getLong("id");
}catch (JSONException e){
_id = count++;
}
id = _id; id = _id;
try{
request = obj.getString("request");
} catch (JSONException e){
request = null;
}
try{
data = obj.getString("data");
}catch (JSONException e){
data = null;
}
}
public Ride(JSONObject obj){ try { request = obj.getString("request"); } catch (JSONException e) { request = null; }
long _id;
try { try { data = obj.getString("data"); } catch (JSONException e) { data = null; }
_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) { public void setRequest(String request) {
this.request = request; this.request = request;
} }
@ -86,9 +39,6 @@ public class Ride {
this.data = data; this.data = data;
} }
public String getRequest() { public String getRequest() {
return this.request; 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() { public String json() {
JSONObject obj = new JSONObject(); JSONObject obj = new JSONObject();
obj.put("id", id); obj.put("id", id);
obj.put("request", request); obj.put("request", request);
obj.put("data",data); obj.put("data", data);
return obj.toString(); 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 #### About
The `mirror` servlet. Prints the list of request it received. The `mirror` servlet. Prints the list of request it received.
* `./src` the code.
* `./war/wrapper` supplements needed for `.war`. #### Deploy
* `./war/<name>.war` copy this to `tomcat/webapps`. * 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> </dependencies>
<build> <build>
<finalName>${project.artifactId}</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins> <plugins>
<plugin> <plugin>

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

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

@ -1,6 +1,9 @@
package com.olexyn.misp.reverse; 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 class Reverse implements Runnable {
public String FORWARD_URL = "http://localhost:8090/forward"; public String FORWARD_URL = "http://localhost:8090/forward";
@ -9,13 +12,13 @@ public class Reverse implements Runnable {
public void start() { public void start() {
CheckSuppyR checkSuppyR = new CheckSuppyR(this); CheckSuppyR checkSuppyR = new CheckSuppyR(this);
Thread checkSupplyT = new Thread(checkSuppyR); Thread checkSupplyT = new Thread(checkSuppyR);
checkSupplyT.setName("checkSupplyT"); checkSupplyT.setName("checkSupplyT");
checkSupplyT.start(); checkSupplyT.start();
Thread journeyGeneratorT = new Thread(new JourneyGenerator(this, checkSuppyR)); Thread journeyGeneratorT = new Thread(new JourneyGeneratorR(this, checkSuppyR));
journeyGeneratorT.setName("journeyGeneratorT"); journeyGeneratorT.setName("journeyGeneratorT");
journeyGeneratorT.start(); journeyGeneratorT.start();
} }

@ -10,7 +10,7 @@ import java.net.URL;
public class Tools { 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); URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); HttpURLConnection connection = (HttpURLConnection) url.openConnection();
@ -22,20 +22,14 @@ public class Tools {
if (method.equals("POST") || getToForward) { if (method.equals("POST") || getToForward) {
connection.setDoOutput(true); connection.setDoOutput(true);
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream()); DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
if (body != null) { if (body != null) { outputStream.writeBytes(body); }
outputStream.writeBytes(body);
}
outputStream.flush(); outputStream.flush();
outputStream.close(); outputStream.close();
} }
int i = connection.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String out; String out;
StringBuilder sb = new StringBuilder(); 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; import org.json.JSONObject;
public class CheckSuppyR implements Runnable { 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 OVERHEAD = 8;
public int CHECK_DEPLETION_INTERVAL = 500; public int CHECK_DEPLETION_INTERVAL = 500;
@ -10,7 +12,7 @@ public class JourneyGenerator implements Runnable {
private Reverse reverse; private Reverse reverse;
private CheckSuppyR checkSuppyR; private CheckSuppyR checkSuppyR;
public JourneyGenerator(Reverse reverse , CheckSuppyR checkSuppyR) { public JourneyGeneratorR(Reverse reverse , CheckSuppyR checkSuppyR) {
this.reverse = reverse; this.reverse = reverse;
this.checkSuppyR = checkSuppyR; this.checkSuppyR = checkSuppyR;
} }
@ -19,16 +21,23 @@ public class JourneyGenerator implements Runnable {
@Override @Override
public void run() { public void run() {
int LIMIT = 0;
while (true) { while (true) {
try { try {
Thread journeyT = new Thread(new JourneyR(reverse)); Thread journeyT = new Thread(new JourneyR(reverse));
journeyT.setName("journeyT"); journeyT.setName("journeyT");
journeyT.start(); 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); 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) { } } 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.helper.Ride;
import com.olexyn.misp.reverse.Reverse;
import com.olexyn.misp.reverse.Tools;
import java.io.IOException; import java.io.IOException;
Loading…
Cancel
Save