Merge pull request 'Adding proxy option' (#2) from dev into master
Reviewed-on: #2
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>org.openautonomousconnection</groupId>
|
<groupId>org.openautonomousconnection</groupId>
|
||||||
<artifactId>protocol</artifactId>
|
<artifactId>protocol</artifactId>
|
||||||
<version>1.0.0-BETA.5</version>
|
<version>1.0.0-BETA.6</version>
|
||||||
<organization>
|
<organization>
|
||||||
<name>Open Autonomous Connection</name>
|
<name>Open Autonomous Connection</name>
|
||||||
<url>https://open-autonomous-connection.org/</url>
|
<url>https://open-autonomous-connection.org/</url>
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Class
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.Proxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main bridge class for the protocol connection.
|
* The main bridge class for the protocol connection.
|
||||||
@@ -94,6 +95,13 @@ public final class ProtocolBridge {
|
|||||||
@Setter
|
@Setter
|
||||||
private ClassicHandlerClient classicHandlerClient;
|
private ClassicHandlerClient classicHandlerClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The proxy for client side
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private Proxy proxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the ProtocolBridge instance for the DNS server side
|
* Initialize the ProtocolBridge instance for the DNS server side
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ public class CallTracker<A extends Annotation> extends GenericReflectClass<A> {
|
|||||||
|
|
||||||
public CallTracker(CallInterceptor interceptor) {
|
public CallTracker(CallInterceptor interceptor) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
atomicClass.set(this.persistentClass);
|
atomicClass.set(this.persistentClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,8 +30,7 @@ public class CallTracker<A extends Annotation> extends GenericReflectClass<A> {
|
|||||||
new AgentBuilder.Default()
|
new AgentBuilder.Default()
|
||||||
.type(any()) // instrument all classes, you can restrict here
|
.type(any()) // instrument all classes, you can restrict here
|
||||||
.transform((builder, type, classLoader, module, protectionDomain) ->
|
.transform((builder, type, classLoader, module, protectionDomain) ->
|
||||||
builder.visit(Advice.to(CallInterceptor.class).on(isMethod()))
|
builder.visit(Advice.to(CallInterceptor.class).on(isMethod()))).installOn(inst);
|
||||||
).installOn(inst);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract static class CallInterceptor {
|
public abstract static class CallInterceptor {
|
||||||
@@ -44,15 +42,12 @@ public class CallTracker<A extends Annotation> extends GenericReflectClass<A> {
|
|||||||
|
|
||||||
@Advice.OnMethodEnter
|
@Advice.OnMethodEnter
|
||||||
static void intercept(@Advice.Origin Method method) {
|
static void intercept(@Advice.Origin Method method) {
|
||||||
|
|
||||||
for (CallInterceptor interceptor : interceptors) {
|
for (CallInterceptor interceptor : interceptors) {
|
||||||
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
|
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
|
||||||
|
|
||||||
if (stack.length <= 3)
|
if (stack.length <= 3) return;
|
||||||
return;
|
|
||||||
|
|
||||||
StackTraceElement caller = stack[3];
|
StackTraceElement caller = stack[3];
|
||||||
|
|
||||||
interceptor.onCall(method, caller);
|
interceptor.onCall(method, caller);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,45 +38,34 @@ public class ProtocolInfoProcessing extends AnnotationProcessor<ProtocolInfo> {
|
|||||||
@Override
|
@Override
|
||||||
public void onCall(Method method, @Nullable StackTraceElement callerMethod) {
|
public void onCall(Method method, @Nullable StackTraceElement callerMethod) {
|
||||||
ProtocolVersion.ProtocolSide side, callerSide;
|
ProtocolVersion.ProtocolSide side, callerSide;
|
||||||
|
|
||||||
Object o;
|
Object o;
|
||||||
|
|
||||||
if ((o = methodGetByName(callerMethod.getMethodName())) != null)
|
if ((o = methodGetByName(callerMethod.getMethodName())) != null)
|
||||||
callerSide = ((Method) o).getAnnotation(ProtocolInfo.class).protocolSide();
|
callerSide = ((Method) o).getAnnotation(ProtocolInfo.class).protocolSide();
|
||||||
else if ((o = typeHasAnnotation(callerMethod.getClassName())) != null)
|
else if ((o = typeHasAnnotation(callerMethod.getClassName())) != null)
|
||||||
callerSide = ((Class<?>) o).getAnnotation(ProtocolInfo.class).protocolSide();
|
callerSide = ((Class<?>) o).getAnnotation(ProtocolInfo.class).protocolSide();
|
||||||
else
|
else return;
|
||||||
return;
|
|
||||||
|
|
||||||
|
|
||||||
if (methodReferences.get().contains(method))
|
if (methodReferences.get().contains(method))
|
||||||
side = method.getAnnotation(ProtocolInfo.class).protocolSide();
|
side = method.getAnnotation(ProtocolInfo.class).protocolSide();
|
||||||
|
|
||||||
else if (typeReferences.get().contains(method.getDeclaringClass()))
|
else if (typeReferences.get().contains(method.getDeclaringClass()))
|
||||||
side = method.getDeclaringClass().getAnnotation(ProtocolInfo.class).protocolSide();
|
side = method.getDeclaringClass().getAnnotation(ProtocolInfo.class).protocolSide();
|
||||||
else
|
else return;
|
||||||
return;
|
|
||||||
|
|
||||||
if (callerSide.equals(ProtocolVersion.ProtocolSide.CLIENT) &&
|
if (callerSide.equals(ProtocolVersion.ProtocolSide.CLIENT) && !side.equals(callerSide))
|
||||||
!side.equals(callerSide))
|
|
||||||
throw new IncompatibleProtocolSideException(callerSide, side);
|
throw new IncompatibleProtocolSideException(callerSide, side);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private Method methodGetByName(String methodName) {
|
private Method methodGetByName(String methodName) {
|
||||||
for (Method method : this.annotatedMethods)
|
for (Method method : this.annotatedMethods) if (method.getName().equals(methodName)) return method;
|
||||||
if (method.getName().equals(methodName))
|
|
||||||
return method;
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Class<?> typeHasAnnotation(String typeName) {
|
private Class<?> typeHasAnnotation(String typeName) {
|
||||||
for (Class<?> type : this.annotatedTypes)
|
for (Class<?> type : this.annotatedTypes) if (type.getName().equals(typeName)) return type;
|
||||||
if (type.getName().equals(typeName))
|
|
||||||
return type;
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
|||||||
folderStructure = new ClientCertificateFolderStructure();
|
folderStructure = new ClientCertificateFolderStructure();
|
||||||
|
|
||||||
// Initialize connection to DNS server
|
// Initialize connection to DNS server
|
||||||
clientToDNS = new NetworkClient.ClientBuilder().setLogger(ProtocolBridge.getInstance().getLogger()).
|
clientToDNS = new NetworkClient.ClientBuilder().setLogger(ProtocolBridge.getInstance().getLogger()).setProxy(ProtocolBridge.getInstance().getProxy()).
|
||||||
setHost(ProtocolBridge.getInstance().getProtocolSettings().host).setPort(ProtocolBridge.getInstance().getProtocolSettings().port).
|
setHost(ProtocolBridge.getInstance().getProtocolSettings().host).setPort(ProtocolBridge.getInstance().getProtocolSettings().port).
|
||||||
setPacketHandler(ProtocolBridge.getInstance().getProtocolSettings().packetHandler).setEventManager(ProtocolBridge.getInstance().getProtocolSettings().eventManager).
|
setPacketHandler(ProtocolBridge.getInstance().getProtocolSettings().packetHandler).setEventManager(ProtocolBridge.getInstance().getProtocolSettings().eventManager).
|
||||||
setRootCAFolder(folderStructure.publicCAFolder).setClientCertificatesFolder(folderStructure.publicClientFolder, folderStructure.privateClientFolder).
|
setRootCAFolder(folderStructure.publicCAFolder).setClientCertificatesFolder(folderStructure.publicClientFolder, folderStructure.privateClientFolder).
|
||||||
|
|||||||
@@ -135,10 +135,7 @@ public final class WebClient {
|
|||||||
// Start the receive thread
|
// Start the receive thread
|
||||||
this.receiveThread.start();
|
this.receiveThread.start();
|
||||||
}
|
}
|
||||||
} /**
|
}
|
||||||
* Thread for receiving data from the web server.
|
|
||||||
*/
|
|
||||||
private final Thread receiveThread = new Thread(this::receive);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the NetworkClient used for the pipeline connection to the web server.
|
* Gets the NetworkClient used for the pipeline connection to the web server.
|
||||||
@@ -147,7 +144,10 @@ public final class WebClient {
|
|||||||
*/
|
*/
|
||||||
public NetworkClient getClientPipelineConnection() {
|
public NetworkClient getClientPipelineConnection() {
|
||||||
return clientToWebPipeline;
|
return clientToWebPipeline;
|
||||||
}
|
} /**
|
||||||
|
* Thread for receiving data from the web server.
|
||||||
|
*/
|
||||||
|
private final Thread receiveThread = new Thread(this::receive);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the SSLSocket used for communication with the web server.
|
* Gets the SSLSocket used for communication with the web server.
|
||||||
|
|||||||
@@ -55,11 +55,7 @@ public final class ConnectedWebClient {
|
|||||||
* Indicates if the client version has been loaded.
|
* Indicates if the client version has been loaded.
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
private boolean clientVersionLoaded = false; /**
|
private boolean clientVersionLoaded = false;
|
||||||
* Thread for receiving data from the client.
|
|
||||||
*/
|
|
||||||
private final Thread receiveThread = new Thread(this::receive);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a ConnectedWebClient with the given connection handler.
|
* Constructs a ConnectedWebClient with the given connection handler.
|
||||||
*
|
*
|
||||||
@@ -67,7 +63,10 @@ public final class ConnectedWebClient {
|
|||||||
*/
|
*/
|
||||||
public ConnectedWebClient(ConnectionHandler pipelineConnection) {
|
public ConnectedWebClient(ConnectionHandler pipelineConnection) {
|
||||||
this.pipelineConnection = pipelineConnection;
|
this.pipelineConnection = pipelineConnection;
|
||||||
}
|
} /**
|
||||||
|
* Thread for receiving data from the client.
|
||||||
|
*/
|
||||||
|
private final Thread receiveThread = new Thread(this::receive);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends an HTTP redirect response to the client.
|
* Sends an HTTP redirect response to the client.
|
||||||
@@ -717,4 +716,5 @@ public final class ConnectedWebClient {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user