Skip to content

Commit 793cf52

Browse files
Removed unnecessary websockets and planning to convert it into blanks
1 parent f5d6084 commit 793cf52

File tree

1 file changed

+8
-118
lines changed

1 file changed

+8
-118
lines changed

internal/session/handler.go

Lines changed: 8 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ const (
8484
CtxStreamUserTransactionsPending handlerCtxKey = "stream_user_transactions_pending"
8585
CtxStreamAllSessions handlerCtxKey = "stream_all_sessions"
8686
CtxStreamAllTransactions handlerCtxKey = "stream_all_transactions"
87-
CtxStreamUserArchiveSession handlerCtxKey = "stream_user_archive_sessions"
88-
CtxStreamUserArchiveResultsTransactions handlerCtxKey = "stream_user_archive_results_transactions"
89-
CtxStreamUserArchivePendingTransactions handlerCtxKey = "stream_user_archive_pending_transactions"
9087
)
9188

9289
/*
@@ -280,125 +277,18 @@ get user archived sessions information
280277
requires user authentication from middleware
281278
user/
282279
*/
283-
func (m *Manager) StreamUserArchiveSessions(w http.ResponseWriter, r *http.Request) {
284-
/* get the username */
285-
username, ok := r.Context().Value(middleware.ContextKeyUsername).(string)
286-
if !ok {
287-
http.Error(w, "Invalid user context", http.StatusInternalServerError)
288-
return
289-
}
290-
291-
/* get the session id */
292-
sessionID, ok := r.Context().Value(middleware.ContextKeySessionID).(string)
293-
if !ok {
294-
http.Error(w, "Invalid session ID context", http.StatusInternalServerError)
295-
return
296-
}
297-
298-
m.mutex.RLock()
299-
session, exists := m.sessionsMap[username]
300-
m.mutex.RUnlock()
301-
302-
if !exists || session.ID.String() != sessionID {
303-
http.Error(w, "unauthorized", http.StatusUnauthorized)
304-
return
305-
}
306-
307-
/* user exists and verified, upgrade the websocket connection */
308-
conn, err := m.upgrader.Upgrade(w, r, nil)
309-
if err != nil {
310-
m.errCh <- fmt.Errorf("websocket upgrade error: %w", err)
311-
return
312-
}
313-
defer conn.Close()
314-
315-
/*
316-
context with cancel for web socket handlers
317-
this is the official context for a websocket connection
318-
cancelling this means closing components of the websocket handler
319-
*/
320-
ctx, cancel := context.WithCancel(context.Background())
321-
defer cancel()
322-
323-
/* sending initial session data */
324-
if err := m.sendCurrentArchivedSessions(conn, username, 1, 1); err != nil {
325-
m.errCh <- fmt.Errorf("error sending initial session: %w", err)
326-
return
327-
}
280+
func (m *Manager) StreamUserArchiveSessions(w http.ResponseWriter, r *http.Request) {}
328281

329-
/*
330-
don't send updated stream of data
331-
archive is updated when session expires
332-
so user will have no access to the dashboard and can't see new
333-
*/
334-
335-
/* specify the handler context */
336-
ctxVal := context.WithValue(ctx, "type", CtxStreamUserArchiveSession)
337-
338-
/* handle web socket instructions from client */
339-
m.handleWebSocketCommands(conn, username, sessionID, ctxVal, cancel)
340-
}
282+
/*
283+
get user archived results transactions information
284+
requires user authentication from middleware
285+
user/
286+
*/
287+
func (m *Manager) StreamUserArchiveResultsTransactions(w http.ResponseWriter, r *http.Request) {}
341288

342289
/*
343290
get user archived pending transactions information
344291
requires user authentication from middleware
345292
user/
346293
*/
347-
func (m *Manager) StreamUserArchivePendingTransactions(w http.ResponseWriter, r *http.Request) {
348-
/* get the username */
349-
username, ok := r.Context().Value(middleware.ContextKeyUsername).(string)
350-
if !ok {
351-
http.Error(w, "Invalid user context", http.StatusInternalServerError)
352-
return
353-
}
354-
355-
/* get the session id */
356-
sessionID, ok := r.Context().Value(middleware.ContextKeySessionID).(string)
357-
if !ok {
358-
http.Error(w, "Invalid session ID context", http.StatusInternalServerError)
359-
return
360-
}
361-
362-
m.mutex.RLock()
363-
session, exists := m.sessionsMap[username]
364-
m.mutex.RUnlock()
365-
366-
if !exists || session.ID.String() != sessionID {
367-
http.Error(w, "unauthorized", http.StatusUnauthorized)
368-
return
369-
}
370-
371-
/* user exists and verified, upgrade the websocket connection */
372-
conn, err := m.upgrader.Upgrade(w, r, nil)
373-
if err != nil {
374-
m.errCh <- fmt.Errorf("websocket upgrade error: %w", err)
375-
return
376-
}
377-
defer conn.Close()
378-
379-
/*
380-
context with cancel for web socket handlers
381-
this is the official context for a websocket connection
382-
cancelling this means closing components of the websocket handler
383-
*/
384-
ctx, cancel := context.WithCancel(context.Background())
385-
defer cancel()
386-
387-
/* sending initial session data */
388-
if err := m.sendCurrentArchivedPendingTransactions(conn, username, 1, 10); err != nil {
389-
m.errCh <- fmt.Errorf("error sending initial session: %w", err)
390-
return
391-
}
392-
393-
/*
394-
don't send updated stream of data
395-
archive is updated when session expires
396-
so user will have no access to the dashboard and can't see new
397-
*/
398-
399-
/* specify the handler context */
400-
ctxVal := context.WithValue(ctx, "type", CtxStreamUserArchivePendingTransactions)
401-
402-
/* handle web socket instructions from client */
403-
m.handleWebSocketCommands(conn, username, sessionID, ctxVal, cancel)
404-
}
294+
func (m *Manager) StreamUserArchivePendingTransactions(w http.ResponseWriter, r *http.Request) {}

0 commit comments

Comments
 (0)