fix(core): update
This commit is contained in:
parent
b34be4dcba
commit
f4ce784a59
@ -1,5 +1,5 @@
|
|||||||
# gitzone ci_default
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
@ -50,13 +50,13 @@ testLTS:
|
|||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
testSTABLE:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install lts
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
@ -65,7 +65,7 @@ testSTABLE:
|
|||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci node install lts
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
@ -98,7 +98,9 @@ trigger:
|
|||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: hosttoday/ht-docker-dbase:npmci
|
||||||
|
services:
|
||||||
|
- docker:18-dind
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
"ts_web/*",
|
"ts_web/*",
|
||||||
"dist/*",
|
"dist/*",
|
||||||
"dist_web/*",
|
"dist_web/*",
|
||||||
|
"dist_ts_web/*",
|
||||||
"assets/*",
|
"assets/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
export type IServerCallActions = 'subscribe' | 'sendmessage' | 'unsubscribe';
|
export type IServerCallActions =
|
||||||
|
| 'channelSubscription'
|
||||||
|
| 'processMessage'
|
||||||
|
| 'channelUnsubscribe'
|
||||||
|
| 'terminateConnection';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the interface for a subscription
|
* the interface for a subscription
|
||||||
|
@ -74,13 +74,13 @@ export class ClientUniverse {
|
|||||||
*/
|
*/
|
||||||
public async sendMessage(messageArg: interfaces.IMessageCreator) {
|
public async sendMessage(messageArg: interfaces.IMessageCreator) {
|
||||||
await this.checkConnection();
|
await this.checkConnection();
|
||||||
const requestBody: interfaces.IUniverseMessage = {
|
const universeMessageToSend: interfaces.IUniverseMessage = {
|
||||||
id: plugins.smartunique.shortId(),
|
id: plugins.smartunique.shortId(),
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
passphrase: (await this.getChannel(messageArg.targetChannelName)).passphrase,
|
passphrase: (await this.getChannel(messageArg.targetChannelName)).passphrase,
|
||||||
...messageArg
|
...messageArg
|
||||||
};
|
};
|
||||||
// TODO: User websocket connection if available
|
await this.smartsocketClient.serverCall('processMessage', universeMessageToSend);
|
||||||
}
|
}
|
||||||
|
|
||||||
public close() {
|
public close() {
|
||||||
@ -113,13 +113,21 @@ export class ClientUniverse {
|
|||||||
const unsubscribe = new plugins.smartsocket.SocketFunction({
|
const unsubscribe = new plugins.smartsocket.SocketFunction({
|
||||||
funcName: 'unsubscribe',
|
funcName: 'unsubscribe',
|
||||||
allowedRoles: [],
|
allowedRoles: [],
|
||||||
funcDef: async (data: interfaces.IServerUnsubscribeActionPayload) => {}
|
funcDef: async (data: interfaces.IServerUnsubscribeActionPayload) => {
|
||||||
|
throw new Error('TODO');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* should handle a message reception
|
* should handle a message reception
|
||||||
*/
|
*/
|
||||||
const receiveMessage = async () => {};
|
const processMessageSocketFunction = new plugins.smartsocket.SocketFunction({
|
||||||
|
funcName: 'processMessage',
|
||||||
|
allowedRoles: [],
|
||||||
|
funcDef: async (data: interfaces.IServerUnsubscribeActionPayload) => {
|
||||||
|
throw new Error('TODO');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
await this.smartsocketClient.connect();
|
await this.smartsocketClient.connect();
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
|
|||||||
* tells the universe about this instances interest into a channel
|
* tells the universe about this instances interest into a channel
|
||||||
*/
|
*/
|
||||||
public async subscribe() {
|
public async subscribe() {
|
||||||
const serverCallActionName: interfaces.IServerCallActions = 'subscribe';
|
const serverCallActionName: interfaces.IServerCallActions = 'channelSubscription';
|
||||||
const serverCallActionPayload: interfaces.IServerCallSubscribeActionPayload = {
|
const serverCallActionPayload: interfaces.IServerCallSubscribeActionPayload = {
|
||||||
name: this.name,
|
name: this.name,
|
||||||
passphrase: this.passphrase
|
passphrase: this.passphrase
|
||||||
|
@ -6,7 +6,6 @@ import { UniverseCache, UniverseChannel, UniverseMessage } from './';
|
|||||||
import * as paths from './smartuniverse.paths';
|
import * as paths from './smartuniverse.paths';
|
||||||
|
|
||||||
import * as interfaces from './interfaces';
|
import * as interfaces from './interfaces';
|
||||||
import { UniverseConnectionManager } from './smartuniverse.classes.universeconnectionmanager';
|
|
||||||
import { UniverseConnection } from './smartuniverse.classes.universeconnection';
|
import { UniverseConnection } from './smartuniverse.classes.universeconnection';
|
||||||
|
|
||||||
export interface ISmartUniverseConstructorOptions {
|
export interface ISmartUniverseConstructorOptions {
|
||||||
@ -14,12 +13,11 @@ export interface ISmartUniverseConstructorOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* main class that setsup a Universe
|
* main class that setups a Universe
|
||||||
*/
|
*/
|
||||||
export class Universe {
|
export class Universe {
|
||||||
// subinstances
|
// subinstances
|
||||||
public universeCache: UniverseCache;
|
public universeCache: UniverseCache;
|
||||||
public universeConnectionManager: UniverseConnectionManager;
|
|
||||||
|
|
||||||
// options
|
// options
|
||||||
private options: ISmartUniverseConstructorOptions;
|
private options: ISmartUniverseConstructorOptions;
|
||||||
@ -37,7 +35,6 @@ export class Universe {
|
|||||||
constructor(optionsArg: ISmartUniverseConstructorOptions) {
|
constructor(optionsArg: ISmartUniverseConstructorOptions) {
|
||||||
this.options = optionsArg;
|
this.options = optionsArg;
|
||||||
this.universeCache = new UniverseCache(this.options.messageExpiryInMilliseconds);
|
this.universeCache = new UniverseCache(this.options.messageExpiryInMilliseconds);
|
||||||
this.universeConnectionManager = new UniverseConnectionManager();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,15 +92,53 @@ export class Universe {
|
|||||||
const SubscriptionSocketFunction = new plugins.smartsocket.SocketFunction({
|
const SubscriptionSocketFunction = new plugins.smartsocket.SocketFunction({
|
||||||
allowedRoles: [ClientRole], // there is only one client role, Authentication happens on another level
|
allowedRoles: [ClientRole], // there is only one client role, Authentication happens on another level
|
||||||
funcName: 'channelSubscription',
|
funcName: 'channelSubscription',
|
||||||
funcDef: async (dataArg: interfaces.IServerCallSubscribeActionPayload, socketConnectionArg) => {
|
funcDef: async (
|
||||||
|
dataArg: interfaces.IServerCallSubscribeActionPayload,
|
||||||
|
socketConnectionArg
|
||||||
|
) => {
|
||||||
// run in "this context" of this class
|
// run in "this context" of this class
|
||||||
(() => {
|
await (async () => {
|
||||||
// TODO: properly add the connection
|
// TODO: properly add the connection
|
||||||
const universeConnection = new UniverseConnection({
|
const universeConnection = new UniverseConnection({
|
||||||
socketConnection: socketConnectionArg,
|
socketConnection: socketConnectionArg,
|
||||||
authenticationRequests: []
|
authenticationRequests: []
|
||||||
})
|
});
|
||||||
this.universeConnectionManager.addConnection(universeConnection);
|
await UniverseConnection.addConnectionToCache(this.universeCache, universeConnection);
|
||||||
|
return {
|
||||||
|
'subscription status': 'success'
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const ProcessMessageSocketFunction = new plugins.smartsocket.SocketFunction({
|
||||||
|
allowedRoles: [ClientRole], // there is only one client role, Authentication happens on another level
|
||||||
|
funcName: 'processMessage',
|
||||||
|
funcDef: async (dataArg: interfaces.IUniverseMessage, socketConnectionArg) => {
|
||||||
|
// run in "this" context of this class
|
||||||
|
await (async () => {
|
||||||
|
const universeConnection = UniverseConnection.findUniverseConnectionBySocketConnection(
|
||||||
|
this.universeCache,
|
||||||
|
socketConnectionArg
|
||||||
|
);
|
||||||
|
if (universeConnection) {
|
||||||
|
console.log('found UniverseConnection for socket');
|
||||||
|
} else {
|
||||||
|
console.log('universe client not yet present');
|
||||||
|
console.log('creating one now as send only');
|
||||||
|
const universeConnectionInstance = new UniverseConnection({
|
||||||
|
socketConnection: socketConnectionArg,
|
||||||
|
authenticationRequests: []
|
||||||
|
});
|
||||||
|
await UniverseConnection.addConnectionToCache(
|
||||||
|
this.universeCache,
|
||||||
|
universeConnectionInstance
|
||||||
|
);
|
||||||
|
}
|
||||||
|
await UniverseChannel.authorizeAMessageForAChannel(
|
||||||
|
this.universeCache,
|
||||||
|
UniverseMessage.createMessageFromPayload(dataArg)
|
||||||
|
);
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -8,6 +8,7 @@ import { Objectmap } from '@pushrocks/lik';
|
|||||||
import { Observable, from } from 'rxjs';
|
import { Observable, from } from 'rxjs';
|
||||||
import { filter } from 'rxjs/operators';
|
import { filter } from 'rxjs/operators';
|
||||||
import { rxjs } from '@pushrocks/smartrx';
|
import { rxjs } from '@pushrocks/smartrx';
|
||||||
|
import { UniverseConnection } from './smartuniverse.classes.universeconnection';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* universe store handles the creation, storage and retrieval of messages.
|
* universe store handles the creation, storage and retrieval of messages.
|
||||||
@ -29,6 +30,8 @@ export class UniverseCache {
|
|||||||
*/
|
*/
|
||||||
public channelMap = new Objectmap<UniverseChannel>();
|
public channelMap = new Objectmap<UniverseChannel>();
|
||||||
|
|
||||||
|
public connectionMap = new plugins.lik.Objectmap<UniverseConnection>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* allows messages to be processed in a blacklist mode for further analysis
|
* allows messages to be processed in a blacklist mode for further analysis
|
||||||
*/
|
*/
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import * as plugins from './smartuniverse.plugins';
|
import * as plugins from './smartuniverse.plugins';
|
||||||
|
|
||||||
import { Objectmap } from '@pushrocks/lik';
|
|
||||||
import { UniverseCache } from './smartuniverse.classes.universecache';
|
import { UniverseCache } from './smartuniverse.classes.universecache';
|
||||||
import { UniverseMessage } from './smartuniverse.classes.universemessage';
|
import { UniverseMessage } from './smartuniverse.classes.universemessage';
|
||||||
|
|
||||||
@ -41,6 +40,13 @@ export class UniverseChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a static message authorization function that takes the UniverseCache
|
||||||
|
* (where messages and channels are stored and their lifetime is managed)
|
||||||
|
* and the universemessage to find a fitting channel for the message
|
||||||
|
* @param universeCacheArg
|
||||||
|
* @param universeMessageArg
|
||||||
|
*/
|
||||||
public static authorizeAMessageForAChannel(
|
public static authorizeAMessageForAChannel(
|
||||||
universeCacheArg: UniverseCache,
|
universeCacheArg: UniverseCache,
|
||||||
universeMessageArg: UniverseMessage
|
universeMessageArg: UniverseMessage
|
||||||
@ -56,6 +62,7 @@ export class UniverseChannel {
|
|||||||
} else {
|
} else {
|
||||||
universeMessageArg.authenticated = false;
|
universeMessageArg.authenticated = false;
|
||||||
universeMessageArg.universeChannelList.add(universeCacheArg.blackListChannel);
|
universeMessageArg.universeChannelList.add(universeCacheArg.blackListChannel);
|
||||||
|
console.log('message not valid');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +86,9 @@ export class UniverseChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* authenticates a client on the server side
|
* authenticates a client on the server side by matching
|
||||||
|
* # the messages channelName against the unverseChannel's name
|
||||||
|
* # the messages password against the universeChannel's password
|
||||||
*/
|
*/
|
||||||
public authenticate(universeMessageArg: UniverseMessage): boolean {
|
public authenticate(universeMessageArg: UniverseMessage): boolean {
|
||||||
return (
|
return (
|
||||||
|
@ -1,12 +1,87 @@
|
|||||||
import * as plugins from './smartuniverse.plugins';
|
import * as plugins from './smartuniverse.plugins';
|
||||||
|
import * as interfaces from './interfaces';
|
||||||
import { UniverseChannel } from './smartuniverse.classes.universechannel';
|
import { UniverseChannel } from './smartuniverse.classes.universechannel';
|
||||||
|
import { UniverseCache } from './smartuniverse.classes.universecache';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* represents a connection to the universe
|
* represents a connection to the universe
|
||||||
*/
|
*/
|
||||||
export class UniverseConnection {
|
export class UniverseConnection {
|
||||||
public terminatedDeferred = plugins.smartpromise.defer();
|
/**
|
||||||
|
*
|
||||||
|
* @param universeConnectionArg
|
||||||
|
*/
|
||||||
|
public static async addConnectionToCache(
|
||||||
|
universeCache: UniverseCache,
|
||||||
|
universeConnectionArg: UniverseConnection
|
||||||
|
) {
|
||||||
|
let universeConnection = universeConnectionArg;
|
||||||
|
universeConnection = await UniverseConnection.deduplicateUniverseConnection(
|
||||||
|
universeCache,
|
||||||
|
universeConnection
|
||||||
|
);
|
||||||
|
universeConnection = await UniverseConnection.authenticateAuthenticationRequests(
|
||||||
|
universeConnection
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deduplicates UniverseConnections
|
||||||
|
*/
|
||||||
|
public static async deduplicateUniverseConnection(
|
||||||
|
universeCache: UniverseCache,
|
||||||
|
universeConnectionArg: UniverseConnection
|
||||||
|
): Promise<UniverseConnection> {
|
||||||
|
let connectionToReturn: UniverseConnection;
|
||||||
|
universeCache.connectionMap.forEach(async existingConnection => {
|
||||||
|
if (existingConnection.socketConnection === universeConnectionArg.socketConnection) {
|
||||||
|
connectionToReturn = await this.mergeUniverseConnections(
|
||||||
|
existingConnection,
|
||||||
|
universeConnectionArg
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!connectionToReturn) {
|
||||||
|
connectionToReturn = universeConnectionArg;
|
||||||
|
}
|
||||||
|
return connectionToReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* authenticate AuthenticationRequests
|
||||||
|
*/
|
||||||
|
public static authenticateAuthenticationRequests(
|
||||||
|
universeConnectionArg
|
||||||
|
): Promise<UniverseConnection> {
|
||||||
|
// TODO: authenticate connections
|
||||||
|
return universeConnectionArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* merges two UniverseConnections
|
||||||
|
*/
|
||||||
|
public static mergeUniverseConnections(
|
||||||
|
connectionArg1: UniverseConnection,
|
||||||
|
connectionArg2: UniverseConnection
|
||||||
|
) {
|
||||||
|
// TODO: merge connections
|
||||||
|
return connectionArg1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* finds a UniverseConnection by providing a socket connection
|
||||||
|
*/
|
||||||
|
public static findUniverseConnectionBySocketConnection(
|
||||||
|
universeCache: UniverseCache,
|
||||||
|
socketConnectionArg: plugins.smartsocket.SocketConnection
|
||||||
|
): UniverseConnection {
|
||||||
|
const universeConnection = universeCache.connectionMap.find(universeConnectionArg => {
|
||||||
|
return universeConnectionArg.socketConnection === socketConnectionArg;
|
||||||
|
});
|
||||||
|
return universeConnection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public terminatedDeferred = plugins.smartpromise.defer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the socketClient to ping
|
* the socketClient to ping
|
||||||
@ -27,9 +102,9 @@ export class UniverseConnection {
|
|||||||
|
|
||||||
constructor(optionsArg: {
|
constructor(optionsArg: {
|
||||||
socketConnection: plugins.smartsocket.SocketConnection;
|
socketConnection: plugins.smartsocket.SocketConnection;
|
||||||
authenticationRequests
|
authenticationRequests: interfaces.IServerCallSubscribeActionPayload[];
|
||||||
}) {
|
}) {
|
||||||
// TODO: check if this is correct
|
// TODO: check if this is correct
|
||||||
this.socketConnection.socket.disconnect();
|
this.socketConnection = optionsArg.socketConnection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,48 +0,0 @@
|
|||||||
import * as plugins from './smartuniverse.plugins';
|
|
||||||
import { UniverseConnection } from './smartuniverse.classes.universeconnection';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* manages connections to a universe
|
|
||||||
*/
|
|
||||||
export class UniverseConnectionManager {
|
|
||||||
public connectionMap = new plugins.lik.Objectmap<UniverseConnection>();
|
|
||||||
|
|
||||||
public async addConnection(universeConnectionArg: UniverseConnection) {
|
|
||||||
let universeConnection = universeConnectionArg;
|
|
||||||
universeConnection = await this.deduplicateUniverseConnection(universeConnection);
|
|
||||||
universeConnection = await this.authenticateAuthenticationRequests(universeConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* deduplicates UniverseConnections
|
|
||||||
*/
|
|
||||||
public async deduplicateUniverseConnection (universeConnectionArg: UniverseConnection): Promise<UniverseConnection> {
|
|
||||||
let connectionToReturn: UniverseConnection;
|
|
||||||
this.connectionMap.forEach(async existingConnection => {
|
|
||||||
if (existingConnection.socketConnection = universeConnectionArg.socketConnection) {
|
|
||||||
connectionToReturn = await this.mergeUniverseConnections(existingConnection, universeConnectionArg);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (!connectionToReturn) {
|
|
||||||
connectionToReturn = universeConnectionArg;
|
|
||||||
}
|
|
||||||
return connectionToReturn;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* authenticate AuthenticationRequests
|
|
||||||
*/
|
|
||||||
public authenticateAuthenticationRequests(universeConnectionArg): Promise<UniverseConnection> {
|
|
||||||
// TODO: authenticate connections
|
|
||||||
return universeConnectionArg;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* merges two UniverseConnections
|
|
||||||
*/
|
|
||||||
public mergeUniverseConnections (connectionArg1: UniverseConnection, connectionArg2: UniverseConnection) {
|
|
||||||
// TODO: merge connections
|
|
||||||
return connectionArg1;
|
|
||||||
}
|
|
||||||
}
|
|
@ -14,6 +14,10 @@ import { IUniverseMessage } from './interfaces';
|
|||||||
* acts as a container to save message states like authentication status
|
* acts as a container to save message states like authentication status
|
||||||
*/
|
*/
|
||||||
export class UniverseMessage implements interfaces.IUniverseMessage {
|
export class UniverseMessage implements interfaces.IUniverseMessage {
|
||||||
|
public static createMessageFromPayload(dataArg: interfaces.IUniverseMessage) {
|
||||||
|
return new UniverseMessage(dataArg);
|
||||||
|
}
|
||||||
|
|
||||||
public id: string;
|
public id: string;
|
||||||
|
|
||||||
public timestamp: number;
|
public timestamp: number;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user