ecco il medico

This commit is contained in:
malloc 2018-04-23 15:42:04 -05:00
parent 111e2c10db
commit 08989a8c7a
6 changed files with 99 additions and 48 deletions

View file

@ -63,7 +63,7 @@ Communication between the master server and clients will be done over a WebSocke
<thead> <thead>
<th colspan="100" class="center"> <th colspan="100" class="center">
ID 1: Key Exchange<br /> ID 1: Key Exchange<br />
Requester (resp. StM ID 0) Responder
</th> </th>
</thead> </thead>
<thead> <thead>
@ -91,7 +91,26 @@ Communication between the master server and clients will be done over a WebSocke
<table style="margin-right: 8px; margin-bottom: 8px;"> <table style="margin-right: 8px; margin-bottom: 8px;">
<thead> <thead>
<th colspan="100" class="center"> <th colspan="100" class="center">
ID 2: Positive ACK<br /> ID 2: Encryption Error<br />
Responder
</th>
</thead>
<thead>
<th>#</th>
<th>Region</th>
<th>Type</th>
</thead>
<tr>
<td>1</td>
<td>Error Message</td>
<td>String</td>
</tr>
</table>
<table style="margin-right: 8px; margin-bottom: 8px;">
<thead>
<th colspan="100" class="center">
ID 3: Positive ACK<br />
[Encrypted] Responder [Encrypted] Responder
</th> </th>
</thead> </thead>
@ -110,7 +129,7 @@ Communication between the master server and clients will be done over a WebSocke
<table style="margin-right: 8px; margin-bottom: 8px;"> <table style="margin-right: 8px; margin-bottom: 8px;">
<thead> <thead>
<th colspan="100" class="center"> <th colspan="100" class="center">
ID 3: Negative ACK<br /> ID 4: Negative ACK<br />
[Encrypted] Responder [Encrypted] Responder
</th> </th>
</thead> </thead>
@ -131,32 +150,13 @@ Communication between the master server and clients will be done over a WebSocke
</tr> </tr>
</table> </table>
<table style="margin-right: 8px; margin-bottom: 8px;">
<thead>
<th colspan="100" class="center">
ID 4: Encryption Error<br />
Responder
</th>
</thead>
<thead>
<th>#</th>
<th>Region</th>
<th>Type</th>
</thead>
<tr>
<td>1</td>
<td>Error Message</td>
<td>String</td>
</tr>
</table>
#### Slave to Master #### Slave to Master
<table style="margin-right: 8px; margin-bottom: 8px;"> <table style="margin-right: 8px; margin-bottom: 8px;">
<thead> <thead>
<th colspan="100" class="center"> <th colspan="100" class="center">
ID 0: Initiation Attempt<br /> ID 1: Initiation Attempt<br />
Blind Requester Requester
</th> </th>
</thead> </thead>
<thead> <thead>
@ -174,8 +174,8 @@ Communication between the master server and clients will be done over a WebSocke
<table style="margin-right: 8px; margin-bottom: 8px;"> <table style="margin-right: 8px; margin-bottom: 8px;">
<thead> <thead>
<th colspan="100" class="center"> <th colspan="100" class="center">
ID 1: Key Exchange<br /> ID 2: Authentication<br />
Responder [Encrypted] Requester
</th> </th>
</thead> </thead>
<thead> <thead>
@ -193,36 +193,22 @@ Communication between the master server and clients will be done over a WebSocke
<table style="margin-right: 8px; margin-bottom: 8px;"> <table style="margin-right: 8px; margin-bottom: 8px;">
<thead> <thead>
<th colspan="100" class="center"> <th colspan="100" class="center">
ID 2: Status Update<br /> ID 3: Status Update<br />
[Encrypted] Blind Requester [Encrypted] Blind Requester
</th> </th>
</thead> </thead>
<thead> <thead>
<th># (<i>r</i>)</th> <th>#</th>
<th>Region</th> <th>Region</th>
<th>Type</th> <th>Type</th>
</thead> </thead>
<tr> <tr>
<td class="center">1</td> <td class="center">1</td>
<td>Server Count (<i>n</i>)</td>
<td>Unsigned Byte</td>
</tr>
<tr>
<td><i>r</i> > 1</td>
<td colspan="2">Iterated over <i>n</i> (0 &leq; <i>i</i> &leq; <i>n - 1</i>)</td>
</tr>
<tr>
<td class="center">2 + 3<i>i</i></td>
<td>Server Id</td>
<td>Packed Unsigned Short</td>
</tr>
<tr>
<td class="center">3 + 3<i>i</i></td>
<td>User Count</td> <td>User Count</td>
<td>Packed Unsigned Short</td> <td>Packed Unsigned Short</td>
</tr> </tr>
<tr> <tr>
<td class="center">4 + 3<i>i</i></td> <td class="center">2</td>
<td>Port</td> <td>Port</td>
<td>Packed Unsigned Short</td> <td>Packed Unsigned Short</td>
</tr> </tr>
@ -473,3 +459,9 @@ The indexed list below indicates which byte (first byte being the MSB) contains
6. Second quantifier. Ranges from 0 to 59. 6. Second quantifier. Ranges from 0 to 59.
In the event that an endpoint cannot evaluate a date required by the protocol as a result of some error, an error sockstamp will be sent in its place. An error sockstamp takes the form of zeroes in all bits. If an endpoint receives a sockstamp where the year quantifier is zero but any other quantifiers are nonzero, there is a communication error and the endpoint must close the connection. In the event that an endpoint cannot evaluate a date required by the protocol as a result of some error, an error sockstamp will be sent in its place. An error sockstamp takes the form of zeroes in all bits. If an endpoint receives a sockstamp where the year quantifier is zero but any other quantifiers are nonzero, there is a communication error and the endpoint must close the connection.
## Status Code Index
### Master / Slave
#### M -> S ID 3

View file

@ -1,2 +1 @@
#include "slave.hpp" #include "slave.hpp"

View file

@ -23,7 +23,10 @@ private:
class MasterClientPool : public Pool<MasterClient> { class MasterClientPool : public Pool<MasterClient> {
protected: protected:
bool ProcessClient(MasterClient& client) override; bool ProcessClient(MasterClient& client) override {
// TODO implement
return true;
}
}; };
/** MASTER -> SLAVE **/ /** MASTER -> SLAVE **/
@ -32,10 +35,22 @@ class MasterIntra {
public: public:
MasterIntra(IntraClient client); MasterIntra(IntraClient client);
bool Process(); bool Process();
void Close(); bool Close();
private: private:
enum kSlaveToMasterId {
InitAttempt = 1,
Authentication,
StatusUpdate
};
enum kMasterToSlaveId {
KeyExchange = 1,
EncryptionError,
PositiveAck,
NegativeAck
};
IntraClient sock; IntraClient sock;
cgc::KeyExchange key; cgc::KeyExchange key;
cgc::Cipher cipher; cgc::Cipher cipher;
}; };

View file

@ -5,5 +5,43 @@ sosc::MasterIntra::MasterIntra(IntraClient client) {
} }
bool sosc::MasterIntra::Process() { bool sosc::MasterIntra::Process() {
Packet pck;
int status = this->sock.Receive(&pck);
if(status == PCK_ERR)
return this->Close();
else if(status == PCK_MORE)
return true;
switch(pck.GetId()) {
case InitAttempt:
if(!pck.Check(1, key.key_size_bytes))
return this->Close();
Packet response;
if(!this->key.ParseRequest(pck, &response)) {
this->sock.Send(
Packet(EncryptionError, {
""
})
);
this->Close();
}
this->sock.Send(response);
break;
case Authentication:
break;
default:
this->Close();
return false;
}
return true; return true;
} }
bool sosc::MasterIntra::Close() {
this->sock.Close();
return false;
}

View file

@ -1,2 +1,6 @@
#include "slave.hpp" #include "slave.hpp"
sosc::SlaveClient::SlaveClient(ScapeConnection client) {
this->sock = client;
}

View file

@ -14,7 +14,10 @@ private:
class SlaveClientPool : Pool<SlaveClient*> { class SlaveClientPool : Pool<SlaveClient*> {
protected: protected:
bool ProcessClient(SlaveClient* client) override; bool ProcessClient(SlaveClient*& client) override {
// TODO implement
return true;
}
}; };
} }