Commit 01ff442d authored by Vít Kabele's avatar Vít Kabele

Session id moved to the ClientMessage root.

parent 6bee27e0
......@@ -610,20 +610,8 @@ const ProtobufCMessageDescriptor session_init_response__descriptor =
(ProtobufCMessageInit) session_init_response__init,
NULL,NULL,NULL /* reserved[123] */
};
static const ProtobufCFieldDescriptor instrumentation_delivery__field_descriptors[2] =
static const ProtobufCFieldDescriptor instrumentation_delivery__field_descriptors[1] =
{
{
"session_id",
1,
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_INT32,
0, /* quantifier_offset */
offsetof(InstrumentationDelivery, session_id),
NULL,
NULL,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"instrumentation",
2,
......@@ -638,13 +626,12 @@ static const ProtobufCFieldDescriptor instrumentation_delivery__field_descriptor
},
};
static const unsigned instrumentation_delivery__field_indices_by_name[] = {
1, /* field[1] = instrumentation */
0, /* field[0] = session_id */
0, /* field[0] = instrumentation */
};
static const ProtobufCIntRange instrumentation_delivery__number_ranges[1 + 1] =
{
{ 1, 0 },
{ 0, 2 }
{ 2, 0 },
{ 0, 1 }
};
const ProtobufCMessageDescriptor instrumentation_delivery__descriptor =
{
......@@ -654,7 +641,7 @@ const ProtobufCMessageDescriptor instrumentation_delivery__descriptor =
"InstrumentationDelivery",
"",
sizeof(InstrumentationDelivery),
2,
1,
instrumentation_delivery__field_descriptors,
instrumentation_delivery__field_indices_by_name,
1, instrumentation_delivery__number_ranges,
......@@ -712,20 +699,8 @@ const ProtobufCMessageDescriptor instrumentation_accept_confirmation__descriptor
(ProtobufCMessageInit) instrumentation_accept_confirmation__init,
NULL,NULL,NULL /* reserved[123] */
};
static const ProtobufCFieldDescriptor instrument_class_request__field_descriptors[4] =
static const ProtobufCFieldDescriptor instrument_class_request__field_descriptors[3] =
{
{
"session_id",
1,
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_INT32,
0, /* quantifier_offset */
offsetof(InstrumentClassRequest, session_id),
NULL,
NULL,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"flags",
2,
......@@ -764,15 +739,14 @@ static const ProtobufCFieldDescriptor instrument_class_request__field_descriptor
},
};
static const unsigned instrument_class_request__field_indices_by_name[] = {
3, /* field[3] = classBytes */
2, /* field[2] = className */
1, /* field[1] = flags */
0, /* field[0] = session_id */
2, /* field[2] = classBytes */
1, /* field[1] = className */
0, /* field[0] = flags */
};
static const ProtobufCIntRange instrument_class_request__number_ranges[1 + 1] =
{
{ 1, 0 },
{ 0, 4 }
{ 2, 0 },
{ 0, 3 }
};
const ProtobufCMessageDescriptor instrument_class_request__descriptor =
{
......@@ -782,7 +756,7 @@ const ProtobufCMessageDescriptor instrument_class_request__descriptor =
"InstrumentClassRequest",
"",
sizeof(InstrumentClassRequest),
4,
3,
instrument_class_request__field_descriptors,
instrument_class_request__field_indices_by_name,
1, instrument_class_request__number_ranges,
......@@ -913,7 +887,7 @@ static const ProtobufCFieldDescriptor close_connection__field_descriptors[1] =
{
{
"reason",
1,
2,
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_ENUM,
0, /* quantifier_offset */
......@@ -929,7 +903,7 @@ static const unsigned close_connection__field_indices_by_name[] = {
};
static const ProtobufCIntRange close_connection__number_ranges[1 + 1] =
{
{ 1, 0 },
{ 2, 0 },
{ 0, 1 }
};
const ProtobufCMessageDescriptor close_connection__descriptor =
......@@ -947,12 +921,24 @@ const ProtobufCMessageDescriptor close_connection__descriptor =
(ProtobufCMessageInit) close_connection__init,
NULL,NULL,NULL /* reserved[123] */
};
static const ProtobufCFieldDescriptor client_message__field_descriptors[4] =
static const ProtobufCFieldDescriptor client_message__field_descriptors[5] =
{
{
"session_init_request",
"session_id",
1,
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_INT32,
0, /* quantifier_offset */
offsetof(ClientMessage, session_id),
NULL,
NULL,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"session_init_request",
2,
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(ClientMessage, request_case),
offsetof(ClientMessage, session_init_request),
......@@ -963,7 +949,7 @@ static const ProtobufCFieldDescriptor client_message__field_descriptors[4] =
},
{
"instrumentation_delivery",
2,
3,
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(ClientMessage, request_case),
......@@ -975,7 +961,7 @@ static const ProtobufCFieldDescriptor client_message__field_descriptors[4] =
},
{
"instrument_class_request",
3,
4,
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(ClientMessage, request_case),
......@@ -987,7 +973,7 @@ static const ProtobufCFieldDescriptor client_message__field_descriptors[4] =
},
{
"close_connection",
4,
5,
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(ClientMessage, request_case),
......@@ -999,15 +985,16 @@ static const ProtobufCFieldDescriptor client_message__field_descriptors[4] =
},
};
static const unsigned client_message__field_indices_by_name[] = {
3, /* field[3] = close_connection */
2, /* field[2] = instrument_class_request */
1, /* field[1] = instrumentation_delivery */
0, /* field[0] = session_init_request */
4, /* field[4] = close_connection */
3, /* field[3] = instrument_class_request */
2, /* field[2] = instrumentation_delivery */
0, /* field[0] = session_id */
1, /* field[1] = session_init_request */
};
static const ProtobufCIntRange client_message__number_ranges[1 + 1] =
{
{ 1, 0 },
{ 0, 4 }
{ 0, 5 }
};
const ProtobufCMessageDescriptor client_message__descriptor =
{
......@@ -1017,7 +1004,7 @@ const ProtobufCMessageDescriptor client_message__descriptor =
"ClientMessage",
"",
sizeof(ClientMessage),
4,
5,
client_message__field_descriptors,
client_message__field_indices_by_name,
1, client_message__number_ranges,
......
......@@ -96,13 +96,12 @@ struct _SessionInitResponse
struct _InstrumentationDelivery
{
ProtobufCMessage base;
int32_t session_id;
size_t n_instrumentation;
ProtobufCBinaryData *instrumentation;
};
#define INSTRUMENTATION_DELIVERY__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&instrumentation_delivery__descriptor) \
, 0, 0,NULL }
, 0,NULL }
/*
......@@ -126,14 +125,13 @@ struct _InstrumentationAcceptConfirmation
struct _InstrumentClassRequest
{
ProtobufCMessage base;
int32_t session_id;
int32_t flags;
char *classname;
ProtobufCBinaryData classbytes;
};
#define INSTRUMENT_CLASS_REQUEST__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&instrument_class_request__descriptor) \
, 0, 0, (char *)protobuf_c_empty_string, {0,NULL} }
, 0, (char *)protobuf_c_empty_string, {0,NULL} }
/*
......@@ -166,10 +164,10 @@ struct _CloseConnection
typedef enum {
CLIENT_MESSAGE__REQUEST__NOT_SET = 0,
CLIENT_MESSAGE__REQUEST_SESSION_INIT_REQUEST = 1,
CLIENT_MESSAGE__REQUEST_INSTRUMENTATION_DELIVERY = 2,
CLIENT_MESSAGE__REQUEST_INSTRUMENT_CLASS_REQUEST = 3,
CLIENT_MESSAGE__REQUEST_CLOSE_CONNECTION = 4
CLIENT_MESSAGE__REQUEST_SESSION_INIT_REQUEST = 2,
CLIENT_MESSAGE__REQUEST_INSTRUMENTATION_DELIVERY = 3,
CLIENT_MESSAGE__REQUEST_INSTRUMENT_CLASS_REQUEST = 4,
CLIENT_MESSAGE__REQUEST_CLOSE_CONNECTION = 5
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(CLIENT_MESSAGE__REQUEST)
} ClientMessage__RequestCase;
......@@ -179,6 +177,7 @@ typedef enum {
struct _ClientMessage
{
ProtobufCMessage base;
int32_t session_id;
ClientMessage__RequestCase request_case;
union {
SessionInitRequest *session_init_request;
......@@ -189,7 +188,7 @@ struct _ClientMessage
};
#define CLIENT_MESSAGE__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&client_message__descriptor) \
, CLIENT_MESSAGE__REQUEST__NOT_SET, {0} }
, 0, CLIENT_MESSAGE__REQUEST__NOT_SET, {0} }
typedef enum {
......
......@@ -29,7 +29,6 @@ message SessionInitResponse {
// When the client obtains the session_id, next step should be sending
// the instrumentation jar (or more of them) to the instrumentation server.
message InstrumentationDelivery {
int32 session_id = 1;
repeated bytes instrumentation = 2;
}
......@@ -41,7 +40,6 @@ message InstrumentationAcceptConfirmation {
// This is the request to the instrumentaion server to instrument attached class.
message InstrumentClassRequest {
int32 session_id = 1;
int32 flags = 2;
string className = 3;
bytes classBytes = 4;
......@@ -63,22 +61,22 @@ message InstrumentClassResponse {
// Notify server about closing connection
message CloseConnection {
enum CloseReason {
FINISHED = 0;
}
CloseReason reason = 1;
CloseReason reason = 2;
}
// Pack together messages from client to simply distinguish them at the server side.
message ClientMessage {
int32 session_id = 1;
oneof request {
SessionInitRequest session_init_request = 1;
InstrumentationDelivery instrumentation_delivery = 2;
InstrumentClassRequest instrument_class_request = 3;
CloseConnection close_connection = 4;
SessionInitRequest session_init_request = 2;
InstrumentationDelivery instrumentation_delivery = 3;
InstrumentClassRequest instrument_class_request = 4;
CloseConnection close_connection = 5;
}
}
......
/**
/*
* Handle the connection from a client.
*
* File: ConnectionHandler.java
* Author: Vit Kabele <vit@kabele.me>
* Created by Vit Kabele <vit@kabele.me> on 16/10/2018
*/
package ch.usi.dag.dislserver;
......@@ -20,21 +20,42 @@ import java.nio.channels.SocketChannel;
import ch.usi.dag.dislserver.Protocol.ClientMessage;
import ch.usi.dag.dislserver.Protocol.ServerMessage;
/**
* Handle one connection to the client.
*/
final class ConnectionHandler implements Runnable {
/**
* Socket to the client.
*/
private final SocketChannel __clientSocket;
/**
* Disl environment.
*/
private final RequestProcessor __requestProcessor;
/**
* Related server thread.
*/
private final Thread __serverThread;
/**
* Related server
*/
private final DiSLServer __server;
private static final Logger __log = Logging.getPackageInstance ();
//
/**
* Constructs new instance of class.
* @param server Related server
* @param clientSocket Socket to the client
* @param requestProcessor Disl environment
* @param serverThread Server thread
*/
ConnectionHandler (
final DiSLServer server,
final SocketChannel clientSocket,
......@@ -48,6 +69,9 @@ final class ConnectionHandler implements Runnable {
}
/**
* Main method
*/
@Override
public void run () {
__server.__workerCount.incrementAndGet ();
......@@ -147,9 +171,9 @@ final class ConnectionHandler implements Runnable {
/**
* Send the message.
* @param response
* @param timer
* @throws IOException
* @param response The object to send
* @param timer Timer
* @throws IOException On communication error
*/
private void sendMessage (
final ServerMessage response,
......@@ -196,6 +220,14 @@ final class ConnectionHandler implements Runnable {
timer.mark (DiSLServer.ElapsedTime.TRANSMIT);
}
/**
* Receive the message.
* @param timer Timer
* @param stats Stats
* @return Received message or null on failure.
* @throws IOException Communication error
*/
private ClientMessage receiveMessage(
final IntervalTimer<DiSLServer.ElapsedTime> timer,
final CounterSet<DiSLServer.ElapsedTime> stats
......
package ch.usi.dag.dislserver;
/**
* This file is part of disl
* Created by Vit Kabele <vit@kabele.me> on 16/10/2018
*/
public class SessionCredentials {
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment