Add transaction IDs to messages and handle on the server
This commit is contained in:
parent
c683f72e10
commit
959be64cc1
@ -12,12 +12,17 @@ Session ::= SEQUENCE {
|
|||||||
minutes INTEGER
|
minutes INTEGER
|
||||||
}
|
}
|
||||||
|
|
||||||
Request ::= CHOICE {
|
RequestBody ::= CHOICE {
|
||||||
ping [0] NULL,
|
ping [0] NULL,
|
||||||
listPrioritizedActivities [1] NULL,
|
listPrioritizedActivities [1] NULL,
|
||||||
logSession [2] Session
|
logSession [2] Session
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Request ::= SEQUENCE {
|
||||||
|
transactionId INTEGER,
|
||||||
|
body RequestBody
|
||||||
|
}
|
||||||
|
|
||||||
PrioritizedActivity ::= SEQUENCE {
|
PrioritizedActivity ::= SEQUENCE {
|
||||||
subjectId INTEGER,
|
subjectId INTEGER,
|
||||||
subjectName UTF8String,
|
subjectName UTF8String,
|
||||||
@ -31,10 +36,15 @@ Error ::= ENUMERATED {
|
|||||||
serverError(2)
|
serverError(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
Response ::= CHOICE {
|
ResponseBody ::= CHOICE {
|
||||||
error [0] Error,
|
error [0] Error,
|
||||||
ack [1] NULL,
|
ack [1] NULL,
|
||||||
prioritizedActivities [2] SEQUENCE OF PrioritizedActivity
|
prioritizedActivities [2] SEQUENCE OF PrioritizedActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Response ::= SEQUENCE {
|
||||||
|
transactionId INTEGER,
|
||||||
|
body ResponseBody
|
||||||
|
}
|
||||||
|
|
||||||
END
|
END
|
||||||
|
@ -23,13 +23,16 @@ handle_cast(_Msg, State) ->
|
|||||||
|
|
||||||
handle_info({ssl, Socket, Data}, State) ->
|
handle_info({ssl, Socket, Data}, State) ->
|
||||||
case 'StudySystemProtocol':decode('Request', Data) of
|
case 'StudySystemProtocol':decode('Request', Data) of
|
||||||
{ok, {ping, _}} ->
|
{ok, {'Request', TransactionId, RequestBody}} ->
|
||||||
|
ResponseBody = map_request(RequestBody),
|
||||||
{ok, Encoded} = 'StudySystemProtocol':encode(
|
{ok, Encoded} = 'StudySystemProtocol':encode(
|
||||||
'Response', {ack, 'NULL'}),
|
'Response',
|
||||||
|
{'Response', TransactionId, ResponseBody}),
|
||||||
ok = ssl:send(Socket, Encoded);
|
ok = ssl:send(Socket, Encoded);
|
||||||
{error, {asn1, _Reason}} ->
|
{error, {asn1, _Reason}} ->
|
||||||
{ok, Encoded} = 'StudySystemProtocol':encode(
|
{ok, Encoded} = 'StudySystemProtocol':encode(
|
||||||
'Response', {error, invalidRequest}),
|
'Response',
|
||||||
|
{'Response', -1, {error, invalidRequest}}),
|
||||||
ok = ssl:send(Socket, Encoded)
|
ok = ssl:send(Socket, Encoded)
|
||||||
end,
|
end,
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
@ -45,3 +48,8 @@ terminate(_Reason, #{socket := Socket}) ->
|
|||||||
|
|
||||||
code_change(_OldVsn, State, _Extra) ->
|
code_change(_OldVsn, State, _Extra) ->
|
||||||
{ok, State}.
|
{ok, State}.
|
||||||
|
|
||||||
|
map_request({ping, 'NULL'}) ->
|
||||||
|
{ack, 'NULL'};
|
||||||
|
map_request(_) ->
|
||||||
|
{error, invalidRequest}.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user