fix(core): update

This commit is contained in:
Philipp Kunz 2020-09-29 17:21:08 +00:00
parent a40a83f0bf
commit c6ad490a6f
11 changed files with 528 additions and 573 deletions

1006
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -20,14 +20,16 @@
"homepage": "https://gitlab.com/pushrocks/smartsocket#README",
"dependencies": {
"@apiglobal/typedrequest-interfaces": "^1.0.15",
"@pushrocks/isohash": "^1.0.2",
"@pushrocks/isounique": "^1.0.4",
"@pushrocks/lik": "^4.0.17",
"@pushrocks/smartdelay": "^2.0.10",
"@pushrocks/smartenv": "^4.0.11",
"@pushrocks/smartexpress": "^3.0.76",
"@pushrocks/smarthash": "^2.1.6",
"@pushrocks/smartlog": "^2.0.39",
"@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartrx": "^2.0.19",
"@pushrocks/smartunique": "^3.0.3",
"@pushrocks/smarttime": "^3.0.35",
"@types/socket.io": "^2.1.11",
"@types/socket.io-client": "^1.4.33",
"socket.io": "^2.3.0",
@ -36,7 +38,7 @@
"devDependencies": {
"@gitzone/tsbuild": "^2.1.25",
"@gitzone/tsrun": "^1.2.12",
"@gitzone/tstest": "^1.0.44",
"@gitzone/tstest": "^1.0.48",
"@pushrocks/tapbundle": "^3.2.9",
"@types/node": "^14.11.2",
"tslint": "^6.1.3",

View File

@ -1,4 +1,5 @@
import * as plugins from './smartsocket.plugins';
import * as pluginsTyped from './smartsocket.pluginstyped';
// classes
import { SocketConnection } from './smartsocket.classes.socketconnection';
@ -11,8 +12,6 @@ import { SocketRequest } from './smartsocket.classes.socketrequest';
import { SocketRole } from './smartsocket.classes.socketrole';
import { SocketServer } from './smartsocket.classes.socketserver';
// socket.io
import * as SocketIO from 'socket.io';
import { logger } from './smartsocket.logging';
export interface ISmartsocketConstructorOptions {
@ -23,9 +22,10 @@ export class Smartsocket {
/**
* a unique id to detect server restarts
*/
public shortId = plugins.smartunique.shortId();
public shortId = plugins.isounique.uni();
public smartenv = new plugins.smartenv.Smartenv();
public options: ISmartsocketConstructorOptions;
public io: SocketIO.Server;
public io: pluginsTyped.socketIo.Server;
public socketConnections = new plugins.lik.ObjectMap<SocketConnection>();
public socketRoles = new plugins.lik.ObjectMap<SocketRole>();
public socketFunctions = new plugins.lik.ObjectMap<SocketFunction<any>>();
@ -46,7 +46,8 @@ export class Smartsocket {
* starts smartsocket
*/
public async start() {
this.io = plugins.socketIo(this.socketServer.getServerForSocketIo());
const socketIoModule = this.smartenv.getSafeNodeModule('socket.io');
this.io = socketIoModule(this.socketServer.getServerForSocketIo());
await this.socketServer.start();
this.io.on('connection', (socketArg) => {
this._handleSocketConnection(socketArg);
@ -85,7 +86,7 @@ export class Smartsocket {
funcName: functionNameArg,
},
originSocketConnection: targetSocketConnectionArg,
shortId: plugins.smartunique.shortId(),
shortId: plugins.isounique.uni(),
side: 'requesting',
});
const response: ISocketFunctionCallDataResponse<T> = await socketRequest.dispatch();
@ -110,7 +111,7 @@ export class Smartsocket {
/**
* the standard handler for new socket connections
*/
private async _handleSocketConnection(socketArg: plugins.socketIo.Socket) {
private async _handleSocketConnection(socketArg: pluginsTyped.socketIo.Socket) {
const socketConnection: SocketConnection = new SocketConnection({
alias: undefined,
authenticated: false,

View File

@ -1,4 +1,5 @@
import * as plugins from './smartsocket.plugins';
import * as pluginsTyped from './smartsocket.pluginstyped';
import * as interfaces from './interfaces';
import { SocketConnection } from './smartsocket.classes.socketconnection';
@ -24,7 +25,7 @@ export interface ISmartsocketClientOptions {
export class SmartsocketClient {
// a unique id
public shortId = plugins.smartunique.shortId();
public shortId = plugins.isounique.uni();
// the shortId of the remote we connect to
public remoteShortId: string = null;
@ -175,7 +176,7 @@ export class SmartsocketClient {
const socketRequest = new SocketRequest<T>(this, {
side: 'requesting',
originSocketConnection: this.socketConnection,
shortId: plugins.smartunique.shortId(),
shortId: plugins.isounique.uni(),
funcCallData: {
funcName: functionNameArg,
funcDataArg: dataArg,

View File

@ -92,7 +92,7 @@ export class SocketConnection {
this.socket.on('dataAuth', async (dataArg: ISocketConnectionAuthenticationObject) => {
logger.log('info', 'received authentication data. now hashing and comparing...');
this.socket.removeListener('dataAuth', () => {});
if (SocketRole.checkPasswordForRole(dataArg, this.smartsocketRef)) {
if (await SocketRole.checkPasswordForRole(dataArg, this.smartsocketRef)) {
// TODO: authenticate password
this.alias = dataArg.alias;
this.authenticated = true;
@ -123,14 +123,14 @@ export class SocketConnection {
if (this.authenticated) {
this.socket.on('function', (dataArg: ISocketRequestDataObject<any>) => {
// check if requested function is available to the socket's scope
logger.log('info', 'function request received');
// logger.log('info', 'function request received');
const referencedFunction: SocketFunction<any> = this.role.allowedFunctions.find(
(socketFunctionArg) => {
return socketFunctionArg.name === dataArg.funcCallData.funcName;
}
);
if (referencedFunction) {
logger.log('ok', 'function in access scope');
// logger.log('ok', 'function in access scope');
const localSocketRequest = new SocketRequest(this.smartsocketRef, {
side: 'responding',
originSocketConnection: this,

View File

@ -107,8 +107,7 @@ export class SocketRequest<T extends plugins.typedrequestInterfaces.ITypedReques
);
if (!targetSocketFunction) {
logger.log('warn', `There is no SocketFunction defined for ${this.funcCallData.funcName}`);
logger.log('warn', `So now response is being sent.`);
logger.log('error', `There is no SocketFunction defined for ${this.funcCallData.funcName}`);
return;
}
logger.log('info', `invoking ${targetSocketFunction.name}`);

View File

@ -28,13 +28,13 @@ export class SocketRole {
});
}
public static checkPasswordForRole(
public static async checkPasswordForRole(
dataArg: ISocketConnectionAuthenticationObject,
referenceSmartsocket: Smartsocket | SmartsocketClient
): boolean {
): Promise<boolean> {
const targetPasswordHash = SocketRole.getSocketRoleByName(referenceSmartsocket, dataArg.role)
.passwordHash;
const computedCompareHash = plugins.smarthash.sha256FromStringSync(dataArg.password);
const computedCompareHash = await plugins.isohash.sha256FromString(dataArg.password);
return targetPasswordHash === computedCompareHash;
}

View File

@ -1,8 +1,7 @@
import * as plugins from './smartsocket.plugins';
import * as pluginsTyped from './smartsocket.pluginstyped';
// used in case no other server is supplied
import * as http from 'http';
import * as https from 'https';
import { Smartsocket } from './smartsocket.classes.smartsocket';
import { logger } from './smartsocket.logging';
@ -12,7 +11,7 @@ import { logger } from './smartsocket.logging';
*/
export class SocketServer {
private smartsocket: Smartsocket;
private httpServer: http.Server | https.Server;
private httpServer: pluginsTyped.http.Server | pluginsTyped.https.Server;
// wether httpServer is standalone
private standaloneServer = false;
private expressServer: any;
@ -27,7 +26,7 @@ export class SocketServer {
*/
public async setExternalServer(
serverType: 'smartexpress',
serverArg: plugins.smartexpress.Server
serverArg: pluginsTyped.smartexpress.Server
) {
await serverArg.startedPromise;
this.httpServer = serverArg.httpServer;
@ -40,7 +39,8 @@ export class SocketServer {
if (this.httpServer) {
return this.httpServer;
} else {
this.httpServer = new http.Server();
const httpModule = this.smartsocket.smartenv.getSafeNodeModule('http');
this.httpServer = new httpModule.Server();
this.standaloneServer = true;
return this.httpServer;
}

View File

@ -0,0 +1,3 @@
import * as plugins from './smartsocket.plugins';
export class SocketStats {}

View File

@ -4,30 +4,31 @@ import * as typedrequestInterfaces from '@apiglobal/typedrequest-interfaces';
export { typedrequestInterfaces };
// pushrocks scope
import * as isohash from '@pushrocks/isohash';
import * as isounique from '@pushrocks/isounique';
import * as lik from '@pushrocks/lik';
import * as smartenv from '@pushrocks/smartenv';
import * as smartlog from '@pushrocks/smartlog';
import * as smarthash from '@pushrocks/smarthash';
import * as smartdelay from '@pushrocks/smartdelay';
import * as smartexpress from '@pushrocks/smartexpress';
import * as smartpromise from '@pushrocks/smartpromise';
import * as smarttime from '@pushrocks/smarttime';
import * as smartunique from '@pushrocks/smartunique';
import * as smartrx from '@pushrocks/smartrx';
export {
isohash,
isounique,
lik,
smartenv,
smartlog,
smarthash,
smartdelay,
smartexpress,
smartpromise,
smarttime,
smartunique,
smartrx,
};
// third party scope
import socketIo from 'socket.io';
// third party
import socketIoClient from 'socket.io-client';
export { socketIo, socketIoClient };
export {
socketIoClient
};

View File

@ -0,0 +1,20 @@
// node native
import type http from 'http';
import type https from 'https';
export {
http,
https
};
// pushrocks scope
import type * as smartexpress from '@pushrocks/smartexpress';
export {
smartexpress
};
// third party scope
import type socketIo from 'socket.io';
export { socketIo };