Skip to content

Commit

Permalink
This is a priority merge & is a breaking change for the UW protocol. …
Browse files Browse the repository at this point in the history
…Merging in reliability and chunking standby.
  • Loading branch information
sentivate committed Mar 10, 2021
1 parent f39c456 commit d743d8a
Show file tree
Hide file tree
Showing 33 changed files with 9,184 additions and 1,017 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
}
},
"rules": {
"no-setter-return": "error",
"no-dupe-else-if": "error",
"no-import-assign": "off",
"object-curly-newline": [
"error",
{
Expand Down
4 changes: 2 additions & 2 deletions client/configuration/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module.exports = (socket) => {
module.exports = (socket, configuration) => {
const {
ip,
port
} = socket.service.ephemeral;
socket.logImprt('CLIENT CONFIGURATION', __dirname);
socket.configuration = {
ip,
port,
port: configuration.servicePort || port,
maxMTU: 1000,
encoding: 'binary',
max: 1280,
Expand Down
9 changes: 5 additions & 4 deletions client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class UDSP {
console.log('-------CLIENT INITIALIZING-------\n', configuration);
const {
service,
profile
profile,
} = configuration;
assign(this, configuration);
const {
crypto: {
createSessionKey,
Expand All @@ -37,12 +38,12 @@ class UDSP {
success(`Creating Shared Keys`);
const transmitKey = socket.transmitKey = createSessionKey();
const receiveKey = socket.receiveKey = createSessionKey();
// Currently unused but may in the future
const ephemeralProfileTransmitKey = socket.ephemeralProfileTransmitKey = createSessionKey();
const ephemeralProfileReceiveKey = socket.ephemeralProfileReceiveKey = createSessionKey();
console.log(ephemeralProfileTransmitKey, ephemeralProfileReceiveKey);
success(`Creating Connection Keypair`);
socket.keypair = keypair();
socket.profile = profile;
socket.service = service;
socket.ephemeralPublic = omit(profile.ephemeral, ['private']);
if (profile.master) {
socket.masterPublic = omit(profile.master, ['private']);
Expand All @@ -68,7 +69,7 @@ class UDSP {
alert(`Shared Keys Created`);
console.log(receiveKey, transmitKey);
require('./status')(socket);
require('./configuration')(socket);
require('./configuration')(socket, configuration);
require('./listening')(socket);
socket.server.on('message', socket.onMessage.bind(socket));
const serviceKey = serviceSignature.toString('base64');
Expand Down
4 changes: 2 additions & 2 deletions client/request/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = (udspPrototype) => {
uid,
promise,
uid: {
free
free: freeUid
}
},
} = udspPrototype;
Expand All @@ -31,7 +31,7 @@ module.exports = (udspPrototype) => {
response,
headers,
});
free(sid);
freeUid(sid);
});
});
}
Expand Down
44 changes: 26 additions & 18 deletions client/send/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = (udspPrototype) => {
function clientSendModule(udspPrototype) {
const {
logImprt,
error: logError,
Expand All @@ -20,14 +20,18 @@ module.exports = (udspPrototype) => {
encode
} = udspPrototype;
logImprt('Send', __dirname);
// socketId, nonce, encrypted message size, flags, packet size.
async function send(message) {
const socket = this;
// clientId, nonce, encrypted message size, flags, packet size.
async function send(message, priority) {
console.log(`Priority: ${priority}`);
const client = this;
const headers = {};
const socketStatusCode = socket.status.code;
console.log(`socket Status Code is ${socketStatusCode}`);
if (socketStatusCode === 0) {
message.head.cert = socket.ephemeralPublic;
const clientStatusCode = client.status.code;
console.log(`client Status Code is ${clientStatusCode}`);
if (clientStatusCode === 0) {
if (!message.head) {
message.head = {};
}
message.head.cert = client.ephemeralPublic;
}
if (message.head) {
message.head = encode(message.head);
Expand All @@ -39,18 +43,20 @@ module.exports = (udspPrototype) => {
server,
configuration: {
ip,
port
}
} = socket;
port: certificatePort
},
servicePort
} = client;
const port = servicePort || certificatePort;
cnsl(`Send to server`);
const nonce = nonceBox();
success(`Nonce Size: ${nonce.length} ${toBase64(nonce)}`);
headers.id = socket.serverId || socket.socketId;
headers.id = client.serverId || client.clientId;
headers.nonce = nonce;
if (socketStatusCode === 0) {
if (clientStatusCode === 0) {
// PERFECT FORWARD SECRECY USE RANDOM EPHEMERAL KEY TO ENCRYPT IDENTITY CERT
headers.key = socket.keypair.publicKey;
headers.sig = hashSign(headers.key, socket.profile.ephemeral.private);
headers.key = client.keypair.publicKey;
headers.sig = hashSign(headers.key, client.profile.ephemeral.private);
console.log(`Sig:${headers.sig.toString('base64')}`);
console.log(`Sig Size:${headers.sig.length}`);
console.log(`Setting ephemeral random public key to header & profile cert to message.body`);
Expand All @@ -62,10 +68,10 @@ module.exports = (udspPrototype) => {
console.log(headersEndIndex, headers);
const headersCompiled = Buffer.concat([headersEndIndexBuffer, headersEncoded]);
success(`Additional Data End Index ${headersEndIndex.toString()}`);
console.log(socket.transmitKey.toString('base64'));
console.log(client.transmitKey.toString('base64'));
console.log(message);
const messageEncoded = encode(message);
const encryptedMessage = encrypt(messageEncoded, headersEncoded, nonce, socket.transmitKey);
const encryptedMessage = encrypt(messageEncoded, headersEncoded, nonce, client.transmitKey);
if (!encryptedMessage) {
return errorLog('Encryption failed');
}
Expand All @@ -83,6 +89,7 @@ module.exports = (udspPrototype) => {
success(`Packet End Index ${packetSize}`);
success('Message Buffer Size', Buffer.from(messageBuffer).length);
if (packetSize >= 1280) {
console.log(messageBuffer);
errorLog(`WARNING: Packet size is larger than max allowed size -> ${packetSize}`);
}
return promise((accept, reject) => {
Expand All @@ -97,4 +104,5 @@ module.exports = (udspPrototype) => {
});
}
udspPrototype.send = send;
};
}
module.exports = clientSendModule;
Loading

0 comments on commit d743d8a

Please sign in to comment.