Skip to content

Commit

Permalink
SEND ALGO CHANGES
Browse files Browse the repository at this point in the history
  • Loading branch information
sentivate committed May 6, 2021
1 parent 31194f6 commit 37ec23f
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 54 deletions.
Empty file added certificate/domain/index.js
Empty file.
Empty file added certificate/identity/index.js
Empty file.
Empty file added certificate/index.js
Empty file.
5 changes: 3 additions & 2 deletions client/send/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ function clientSendModule(udspPrototype) {
cnsl(`Send to server`);
const nonce = nonceBox();
success(`Nonce Size: ${nonce.length} ${toBase64(nonce)}`);
if (client.serverId || client.clientId) {
headers.id = client.serverId || client.clientId;
const transmitID = client.serverId || client.clientId;
if (transmitID) {
headers.id = transmitID;
} else {
return console.error(`NO CLIENT ID IS'T ASSIGNED`);
}
Expand Down
95 changes: 52 additions & 43 deletions packetDesign.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,70 @@
## Universal Web Socket - PACKET DESIGN
## Universal Web Socket - PACKET DESIGN

#### PACKET HEADERS (MSGPack Object)(OPTIONAL ENCRYPTION)
- Nonce
- Identity Certificate (OPTIONAL)(REQUIRED AT START)
- Socket ID (CLIENT/SERVER)
- May indicate which server to send to for load balancing
- May indicate which domain to send to for virtual hosts
- May be entirely random
___

#### REQUEST PROPERTIES (MSGPack Object)(ENCRYPTED)
- id - Connection ID (MANDATORY)
- api - API function that is requested (OPTIONAL)
- Watcher (OPTIONAL)
- Head (OPTIONAL)
- Body (OPTIONAL) (MSGPack Object)
- Pid - Packet ID (MANDATORY)
- Status - Status Code (OPTIONAL)
- If status is left blank it defaults to 200 or is considered a success
- end - Kill connection (OPTIONAL)
- Puzzle - Solve a puzzle to continue (OPTIONAL)
- ReKey (OPTIONAL)
- scid - Server connection ID (OPTIONAL)

___

- Nonce
- Identity Certificate (OPTIONAL)(REQUIRED AT START)
- Socket ID (CLIENT/SERVER)
- May indicate which server to send to for load balancing
- May indicate which domain to send to for virtual hosts
- May be entirely random

---

#### PROPERTY NAMES & MEANINGS

- id - Connection ID (MANDATORY)
- api - API function that is requested (OPTIONAL)
- Watcher (OPTIONAL)
- Head (OPTIONAL)
- Body (OPTIONAL) (MSGPack Object)
- Pid - Packet ID (MANDATORY)
- Status - Status Code (OPTIONAL)
- If status is left blank it defaults to 200 or is considered a success
- end - Kill connection (OPTIONAL)
- Puzzle - Solve a puzzle to continue (OPTIONAL)
- ReKey (OPTIONAL)
- scid - Server connection ID (OPTIONAL)

---

#### HEADER LAYERS

| IPv6 HEADERS |
|:---------------------------:|
| UDP HEADERS |
| UDSP HEADERS |
| PACKET HEADERS |
| FRAME HEADERS |
| IPv6 HEADERS |
| :------------: |
| UDP HEADERS |
| UDSP HEADERS |
| PACKET HEADERS |
| FRAME HEADERS |

##### IPv6 HEADERS
- Version
- Traffic Class
- Flow Label
- Payload Length
- Next Header
- Hop Limit
- Source Address
- Destination Address

- Version
- Traffic Class
- Flow Label
- Payload Length
- Next Header
- Hop Limit
- Source Address
- Destination Address

##### UDP HEADERS

These are the standard UDP headers sent over:
- Source Port Number
- Destination Port Number
- Length
- Checksum

- Source Port Number
- Destination Port Number
- Length
- Checksum

##### MAIN HEADERS
Main Headers are public and typically none encrypted but the application can choose to encrypt certain headers such as connection IDs.

Main Headers are public and not encrypted so that the server knows how to initially handle the packet. Think of packets as a constant stream of data it just needs to know which entry node to be filtered to. The connection ID isn't encrypted so that the endpoint knows how to process & assign the packet. During handshake it's about storing and creating a client object using that connection ID or creating a new one. When sending back a response the initial connection ID is used but typically will include a server side created connection ID for all future packets sent to the server. You can think of these as a send and receive connection ID.

##### PACKET HEADERS

Packet headers are encrypted and are typically sent only once and are considered priority data they must fit into a single UDSP packet. An example of packet headers that would be sent once are security related headers such as content origin policy. If in a browser this header is attached to all other requests or placed as a meta tag in the head. This avoids the constant re-sending of these headers when they only need to be sent once. This also avoids processing on the server and client for redundant security headers.

##### FRAME HEADERS

Frame headers are request specific and will be chunked and sent over first prior to the body being sent over. Headers are treated as priority data.
33 changes: 27 additions & 6 deletions server/send/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ module.exports = (server) => {
toBase64
},
utility: {
assign,
chunk,
omit
},
success,
sendRaw,
Expand All @@ -21,15 +23,15 @@ module.exports = (server) => {
port,
nonce,
transmitKey,
clientIdRaw: id
clientIdRaw: clientId
} = client;
const {
sid
} = rawMessage;
success(`PROCESSING MESSAGE TO SEND`);
console.log('Packet Options', options);
console.log('Raw Message', rawMessage);
success(`clientId: ${toBase64(id)}`);
success(`clientId: ${toBase64(clientId)}`);
success(`Transmit Key ${toBase64(transmitKey)}`);
let size = 0;
let headLength = 0;
Expand All @@ -39,6 +41,7 @@ module.exports = (server) => {
body
} = rawMessage;
const message = rawMessage;
const msgTemplate = omit(rawMessage, ['body', 'head']);
const queued = {
sid,
rawMessage,
Expand Down Expand Up @@ -70,17 +73,35 @@ module.exports = (server) => {
}
if (size > maxPayloadSize) {
console.log('SEND - Item is too large will need to chunk into packets.');
const afterHead = maxPayloadSize - headLength;
queued.headEnd = afterHead;
const afterHeadMax = maxPayloadSize - headLength;
queued.headEnd = afterHeadMax;
message.bSize = bodyLength;
message.hSize = headLength;
if (headLength < maxPayloadSize) {
// If the body is larger than the max packet size.
if (bodyLength > size) {
/*
The max body size that can be sent in the first packet
is equal to the header size subtracted from the max packet size.
*/
const firstBody = body.slice(0, afterHeadMax);
const firstPacket = assign({
head,
body: firstBody
}, msgTemplate);
sendRaw(firstPacket, address, port, nonce, transmitKey, clientId);
}
} else if (headLength > maxPayloadSize) {
}
/**
Both head and body are treated as the same array of data.
If the head is 200bytes and the body is 200bytes the total range is 400.
At index range 0 it would be at the start of the header data while 201 may be the start of the body.
This is used to setup ranges for efficient reliability algorithms & chunking
*/
console.log('Room left after head size calculated', afterHead);
console.log('Room left after head size calculated', afterHeadMax);
} else {
return sendRaw(rawMessage, address, port, nonce, transmitKey, id);
return sendRaw(rawMessage, address, port, nonce, transmitKey, clientId);
}
}
server.send = send;
Expand Down
6 changes: 3 additions & 3 deletions server/send/raw/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ module.exports = (server) => {
} = server;
logImprt('Send', __dirname);
// clientId, nonce, encrypted message size, flags, packet size.
async function sendRaw(rawMessage, address, port, nonce, transmitKey, id) {
async function sendRaw(rawMessage, address, port, nonce, transmitKey, clientId) {
success(`SENDING MESSAGE`);
success(`clientId: ${toBase64(id)}`);
success(`clientId: ${toBase64(clientId)}`);
success(`Transmit Key ${toBase64(transmitKey)}`);
rawMessage.time = Date.now();
console.log('FULL MESSAGE', rawMessage);
const message = encode(rawMessage);
randombytes_buf(nonce);
success(`Nonce ${toBase64(nonce)} Size: ${nonce.length}`);
const headers = {
id,
id: clientId,
nonce,
};
const headersEncoded = encode(headers);
Expand Down

0 comments on commit 37ec23f

Please sign in to comment.