Przeglądaj źródła

enhance and fix multi client test.

Enzo 1 miesiąc temu
rodzic
commit
d89bd1e035

+ 10 - 10
doc/explanation.txt

@@ -19,16 +19,16 @@ i) Explore multiple traffic concept
 ii) Move transport service instantiation to adapterManager
 ExtraNotes: In some cases, servers can only be transmitting. Although this program allows for dual roles if there's a need for me.
 
-As of 20/11/2024
-Here's what I did yesterday. Succeeded in wrapping all the messages to implement the retransmisison as well as message ordering mechanism. I also focused on getting the receiver to implement retransmission on their side as well. Didn't get to test the message ordering, even though I enabled it. 
-I assumed it worked for now. Although I didn't really observe the test to see if it really works, but it was tested previously, so, I would assume it works for now. But the thing 
-about the message ordering is that, if the previous message never arrives, the current message that arrives will always be held hostage. Just to take note. So, with that being said,
-today I will be focus in on the following:
-i) Move the instantiation of transport serivce to adapterManager Side. <DONE>
-ii) Code and test for server to respond this time round. Make sure the receiver have all the required responses. (Can also observe for the message ordering.)
--The message ordering may need to be fixed for the request response. It is not ideal to hold the last message, because that would mean that the receiver has to 
-make another action just for the message that has been held hostage to be released. Special clause should be enforced to allow the completion of a request
-iii) Test multi client. 
+For 21/11/2024 (Thursday):
+i) Test multi client. 
+-This is probelmatic. Observation: One client, but the all the transmission stop, but it shouldn't be.
+ii) Do include in the list of discussion for the message ordering mechanism
+- Currently the way it is working is not favorable. In the mean time, do think up suggestion to improve the ordering.
+- Just to acquire boss's input. Doesn't have to challenge him or anything
+iii) Start doing some R&D.
+-details down there
+iv) Also, enhancements to cater for UI side to use this mesasge transmission interface.  [MAJOR OVERHAUL]
+- That means when instantiating message transmission, the browser environment must be specified to use socket client instead of starting a server. 
 
 Things to do:
 - Connection Manager to manage different transport options. Default using websocket, but will also consider fail detection on each transport and decide on adapters swap

+ 0 - 3
src/connector/connector.manager.ts

@@ -85,9 +85,6 @@ export class ConnectionManager implements ConnectionManagerInterface {
         })
     }
 
-
-
-
 }
 
 

+ 1 - 0
src/test/proxy.ts

@@ -7,6 +7,7 @@ let fromServer = new Subject<{ event: 'profile' | 'message', payload: any }>()
 let toServer = new Subject<{ event: 'profile' | 'message', payload: any }>()
 
 startSocketServer(3001)
+// startSocketServer(3002)
 startClientSocketConnection('http://localhost:3000')
 consoleLog()
 

+ 3 - 2
src/test/receiver.ts

@@ -35,7 +35,7 @@ class SocketClient {
 
     private startListening(event: Subject<TransportEvent>): void {
         event.subscribe((event: TransportEvent) => {
-            // console.log((event.data as EventMessage).payload ?? 'Not Fis Message')
+            console.log('Event', (((event.data as EventMessage)?.payload as WrappedMessage)?.payload as FisMessage)?.header.messageID ?? 'Not Fis Message')
             if (event.event == `New Server`) {
                 this.currentSocketId = (event.data as EventMessage).clientId
 
@@ -43,7 +43,7 @@ class SocketClient {
                 if (currentClientSocket) {
                     // so retransmission is working as usual
                     this.retransmission.implementRetransmission(this.requestMessages, currentClientSocket.connectionState, true)
-                    this.startGeneratingRequest(10000, this.requestMessages)
+                    // this.startGeneratingRequest(10000, this.requestMessages)
                     this.retransmission.returnSubjectForBufferedItems().subscribe((message: WrappedMessage) => {
                         this.sendMessage(message).subscribe({
                             next: response => console.log(`Receiving response for ${message.thisMessageID}`),
@@ -91,6 +91,7 @@ class SocketClient {
 
 // Usage example:
 const client = new SocketClient("http://localhost:3001");
+// const client = new SocketClient("http://localhost:3002");
 // const client = new SocketClient("http://127.0.0.1:3000");
 // const client = new SocketClient("http://192.168.100.96:3000");
 

+ 1 - 1
src/test/transmitter.ts

@@ -56,7 +56,7 @@ class MessageProducer {
         console.log(`Contructing Application....`)
         this.incomingMessageBus = incomingMessageBus
 
-        // this.generateNotifcation().subscribe(this.generalNotification)
+        this.generateNotifcation().subscribe(this.generalNotification)
         this.handleIncomingRequests(this.incomingMessageBus.asObservable(), this.outgoingMessageBus)
     }
 

+ 1 - 2
src/transmission/msg.transmission.base.ts

@@ -7,7 +7,6 @@ import { ConnectionAdapter } from '../connector/connector.base';
 
 export class MessageTransmissionBase implements MessageTransmissionBaseInterface {
     event!: Observable<TransportEvent>
-    transmissionProfile!: TransmissionProfile
     msgRepositoryService: any;
     transmissionRole!: AdaptorTransmissionRole;
     adaptorsArray: Array<ConnectionAdapter> = []
@@ -19,7 +18,7 @@ export class MessageTransmissionBase implements MessageTransmissionBaseInterface
     }
 
     getInfo(): TransmissionProfile {
-        return this.transmissionProfile
+        throw new Error(`Method not implemented`)
     }
 
     setUpAdapter(adapterSet: AdapterSet[]): void {

+ 1 - 0
src/transmission/msg.transmission.manager.ts

@@ -40,6 +40,7 @@ export class MessageTransmissionManager implements MessageTransmissionManagerInt
     }
 
     private instantiateComponents(clientId: string): MessageTransmission {
+        console.log(`Instantiating new transmission set for another CLient`)
         let adapterSet: AdapterSet[] = []
         if (this.connectionManager.getTransportArray().length > 0) {
             this.connectionManager.getTransportArray().forEach(transport => {

+ 4 - 3
src/transmission/msg.transmission.transmitter.ts

@@ -1,6 +1,6 @@
 import { MessageTransmissionBase } from "./msg.transmission.base";
 import { EventMessage, FisMessage, MessageTransmitter as MessageTransmitterInterface, TransmitterProfile } from '../interface/transport.interface'
-import { AdapterSet, ConnectionState, Event, Transport, TransportEvent } from "../interface/connector.interface";
+import { AdapterSet, ConnectionState, Event, Transport, TransportEvent, TransportMessage } from "../interface/connector.interface";
 import { v4 as uuidv4 } from 'uuid'
 import { TransmitterConnectionAdapter } from "../connector/connector.transmitter";
 import { BehaviorSubject, filter, map, Observable, Subject } from "rxjs";
@@ -23,12 +23,13 @@ export class MessageTransmissionTransmitter extends MessageTransmissionBase impl
         this.setUpAdapter(adapterSets)
         this.setUpRetransmission()
     }
-
+    
     // by the time this transmission set is instantiated, the connected client would've been online. Need ot manually signal retransmission to release buffer immediately
     setUpRetransmission(): void {
         let connectionStateEvent = new BehaviorSubject<'OFFLINE' | 'ONLINE'>('ONLINE')
         this.event.pipe(
             filter(event => event.event == 'Client Disconnected' || event.event == 'Client Reconnected'),
+            filter(event => (event.data as EventMessage).clientId == this.transmitterProfile.id),
             map(event => {
                 if (event.event == 'Client Disconnected') {
                     return 'OFFLINE'
@@ -46,7 +47,7 @@ export class MessageTransmissionTransmitter extends MessageTransmissionBase impl
             (this.adapterService as TransmitterConnectionAdapter).emit(message)
         })
     }
-
+    
     setTransmitter(transmitterProfile: TransmitterProfile): void {
         this.transmitterProfile = transmitterProfile
     }

+ 0 - 2
src/utils/message.ordering.ts

@@ -16,8 +16,6 @@ export async function checkMessage(message: WrappedMessage, messageChecking: Sub
             ).subscribe({
                 complete: () => {
                     resolve('previousMessageID matched')
-                    // console.log(`${message.payload.header.messageID} : Previous messageID(${message.previousMessageID}) matched`)
-                    // console.log(`matched`)
                 }
             })
         } else {

+ 6 - 3
src/utils/socket.utils.ts

@@ -393,9 +393,12 @@ export function startListening(socket: SocketForConnectedClient, client: Connect
             id: uuidv4(),
             event: 'Client Disconnected',
             data: {
-                clientID: client.id,
-                time: new Date()
-            }
+                clientId: client.id,
+                message: '',
+                payload: {
+                    time: new Date()
+                }
+            } as EventMessage
         })
         eventListener.error(`Client ${client.id} disconnected. Terminating this observable event for this client socket...`)
         eventListener.complete()