diff --git a/protocol.md b/protocol.md index 6f806e5..912d35f 100644 --- a/protocol.md +++ b/protocol.md @@ -63,7 +63,7 @@ Communication between the master server and clients will be done over a WebSocke ID 1: Key Exchange
- Requester (resp. StM ID 0) + Responder @@ -91,7 +91,26 @@ Communication between the master server and clients will be done over a WebSocke + + + + + + + + + + + +
- ID 2: Positive ACK
+ ID 2: Encryption Error
+ Responder +
#RegionType
1Error MessageString
+ + + + @@ -110,7 +129,7 @@ Communication between the master server and clients will be done over a WebSocke
+ ID 3: Positive ACK
[Encrypted] Responder
@@ -131,32 +150,13 @@ Communication between the master server and clients will be done over a WebSocke
- ID 3: Negative ACK
+ ID 4: Negative ACK
[Encrypted] Responder
- - - - - - - - - - - - - - -
- ID 4: Encryption Error
- Responder -
#RegionType
1Error MessageString
- #### Slave to Master @@ -174,8 +174,8 @@ Communication between the master server and clients will be done over a WebSocke
- ID 0: Initiation Attempt
- Blind Requester + ID 1: Initiation Attempt
+ Requester
@@ -193,36 +193,22 @@ Communication between the master server and clients will be done over a WebSocke
- ID 1: Key Exchange
- Responder + ID 2: Authentication
+ [Encrypted] Requester
- + - - - - - - - - - - - - - - - + @@ -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. 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 \ No newline at end of file diff --git a/server/src/ctx/slave.cpp b/server/src/ctx/slave.cpp index f2c726b..c442712 100644 --- a/server/src/ctx/slave.cpp +++ b/server/src/ctx/slave.cpp @@ -1,2 +1 @@ #include "slave.hpp" - diff --git a/server/src/hosts/master.hpp b/server/src/hosts/master.hpp index 8c1c3d2..74a7cae 100644 --- a/server/src/hosts/master.hpp +++ b/server/src/hosts/master.hpp @@ -23,7 +23,10 @@ private: class MasterClientPool : public Pool { protected: - bool ProcessClient(MasterClient& client) override; + bool ProcessClient(MasterClient& client) override { + // TODO implement + return true; + } }; /** MASTER -> SLAVE **/ @@ -32,10 +35,22 @@ class MasterIntra { public: MasterIntra(IntraClient client); bool Process(); - void Close(); + bool Close(); private: + enum kSlaveToMasterId { + InitAttempt = 1, + Authentication, + StatusUpdate + }; + + enum kMasterToSlaveId { + KeyExchange = 1, + EncryptionError, + PositiveAck, + NegativeAck + }; + IntraClient sock; - cgc::KeyExchange key; cgc::Cipher cipher; }; diff --git a/server/src/hosts/master_intra.cpp b/server/src/hosts/master_intra.cpp index 5150075..3ed92a1 100644 --- a/server/src/hosts/master_intra.cpp +++ b/server/src/hosts/master_intra.cpp @@ -5,5 +5,43 @@ sosc::MasterIntra::MasterIntra(IntraClient client) { } 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; } + +bool sosc::MasterIntra::Close() { + this->sock.Close(); + return false; +} diff --git a/server/src/hosts/slave.cpp b/server/src/hosts/slave.cpp index f2c726b..0d07541 100644 --- a/server/src/hosts/slave.cpp +++ b/server/src/hosts/slave.cpp @@ -1,2 +1,6 @@ #include "slave.hpp" +sosc::SlaveClient::SlaveClient(ScapeConnection client) { + this->sock = client; +} + diff --git a/server/src/hosts/slave.hpp b/server/src/hosts/slave.hpp index 3ce954a..7dc5efb 100644 --- a/server/src/hosts/slave.hpp +++ b/server/src/hosts/slave.hpp @@ -14,7 +14,10 @@ private: class SlaveClientPool : Pool { protected: - bool ProcessClient(SlaveClient* client) override; + bool ProcessClient(SlaveClient*& client) override { + // TODO implement + return true; + } }; }
- ID 2: Status Update
+ ID 3: Status Update
[Encrypted] Blind Requester
# (r)# Region Type
1Server Count (n)Unsigned Byte
r > 1Iterated over n (0 ≤ in - 1)
2 + 3iServer IdPacked Unsigned Short
3 + 3i User Count Packed Unsigned Short
4 + 3i2 Port Packed Unsigned Short