MCPcopy Create free account
hub / github.com/dan-v/lambda-nat-proxy / GetCurrent

Method GetCurrent

internal/manager/manager.go:318–362  ·  view source on GitHub ↗

GetCurrent returns the current primary session

()

Source from the content-addressed store, hash-verified

316
317// GetCurrent returns the current primary session
318func (cm *ConnManager) GetCurrent() *Session {
319 cm.mu.RLock()
320 defer cm.mu.RUnlock()
321
322 var selectedSession *Session
323
324 // First, look for a healthy primary session
325 for _, session := range cm.sessions {
326 if session.IsPrimary() && session.IsHealthy() {
327 selectedSession = session
328 break
329 }
330 }
331
332 // If no healthy primary, look for any healthy secondary (during transition)
333 if selectedSession == nil {
334 for _, session := range cm.sessions {
335 if session.IsSecondary() && session.IsHealthy() {
336 selectedSession = session
337 break
338 }
339 }
340 }
341
342 // Last resort: return any healthy session (but not draining)
343 if selectedSession == nil {
344 for _, session := range cm.sessions {
345 if session.IsHealthy() && !session.IsDraining() {
346 selectedSession = session
347 break
348 }
349 }
350 }
351
352 // Only log when no session is found and we have sessions (unusual condition)
353 if selectedSession == nil && len(cm.sessions) > 0 {
354 shared.LogNetworkf("GetCurrent: No suitable session found among %d sessions", len(cm.sessions))
355 for i, session := range cm.sessions {
356 shared.LogNetworkf(" Session %d: %s (role: %s, healthy: %v, draining: %v)",
357 i, session.ID, session.Role, session.IsHealthy(), session.IsDraining())
358 }
359 }
360
361 return selectedSession
362}
363
364// GetAllSessions returns all sessions for dashboard display
365func (cm *ConnManager) GetAllSessions() []*Session {

Callers 4

PrimaryMethod · 0.95
WaitForSessionMethod · 0.95
getSystemStatusMethod · 0.80
getPublicIPMethod · 0.80

Calls 5

LogNetworkfFunction · 0.92
IsPrimaryMethod · 0.80
IsHealthyMethod · 0.80
IsSecondaryMethod · 0.80
IsDrainingMethod · 0.80

Tested by

no test coverage detected