Skip to content

Commit a893960

Browse files
authored
Merge pull request #8 from DrOctavius/main
websocket fixes
2 parents 24ccbb5 + c949210 commit a893960

File tree

11 files changed

+62
-19
lines changed

11 files changed

+62
-19
lines changed

Diff for: core/clients/db/constructor/client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (dbc *DBClient) New(
5555
// GetDefaultClient -> it returns the default client based on the existing app configuration
5656
func (dbc *DBClient) GetDefaultClient() (*gorm.DB, error) {
5757
conf := mainConfig.GetConfig()
58-
//defaultConnName := conf.Clients.MySQL.DefaultConn.Name
58+
//defaultConnName := conf.ClientsStatus.MySQL.DefaultConn.Name
5959

6060
// TODO: get driverType and get from config
6161

Diff for: core/config/autoloader/generate.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func SaveConfigFromMemory(cfg Config) error {
3232
c := viper.New()
3333

3434
// Create the map!
35-
//MainConfig.Clients.MySQL.Connections = make(map[string]mysql.Config)
35+
//MainConfig.ClientsStatus.MySQL.Connections = make(map[string]mysql.Config)
3636
//MainConfig.Listeners.Http.Instances = make(map[string]http.Config)
3737

3838
// This is the default config!
@@ -232,7 +232,7 @@ func SaveConfigFromMemory(cfg Config) error {
232232
//---------------------------------------------------------------------------------\\
233233

234234
// Cassandra Default Config Instance
235-
/*if _, ok := cfgData.MainConfig.Clients.Cassandra.Instances["default"]; !ok {
235+
/*if _, ok := cfgData.MainConfig.ClientsStatus.Cassandra.Instances["default"]; !ok {
236236
_cassandra := &cassandraConfig.Config{
237237
Hosts: []cassandraConfig.Host{
238238
cassandraConfig.Host{
@@ -245,11 +245,11 @@ func SaveConfigFromMemory(cfg Config) error {
245245
panic(_err)
246246
}
247247
// If the map is empty... we need to create it
248-
if cfgData.MainConfig.Clients.Cassandra.Instances == nil {
248+
if cfgData.MainConfig.ClientsStatus.Cassandra.Instances == nil {
249249
// Creating the map, where we will set afterwards the default object
250-
cfgData.MainConfig.Clients.Cassandra.Instances = make(map[string]cassandraConfig.Config)
250+
cfgData.MainConfig.ClientsStatus.Cassandra.Instances = make(map[string]cassandraConfig.Config)
251251
}
252-
cfgData.MainConfig.Clients.Cassandra.Instances["default"] = *_cassandra
252+
cfgData.MainConfig.ClientsStatus.Cassandra.Instances["default"] = *_cassandra
253253
}*/
254254

255255
//---------------------------------------------------------------------------------\\

Diff for: core/console/menu/menu.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func (m *Menu) AddCommand(c *command.AddCmd) *Menu {
268268
// -------Run Services--------\\
269269

270270
if c.EnableStartupServices {
271-
// Run Broker Clients
271+
// Run Broker ClientsStatus
272272
if c.StartupCoreServices.BrokerClients {
273273
// Register the broker client service
274274
brokerClientService.RegisterBrokerService()

Diff for: core/listeners/http/server/server_client_indexing.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ func (c *clientsData) getClientsByFilter(filter FindClientsFilter) map[uint64]*C
479479
// Prepare the filter..
480480
prepareFilter(&filter)
481481

482-
// TODO: we can also save where we have found the Clients
482+
// TODO: we can also save where we have found the ClientsStatus
483483
// We are searching through 6 indexes!
484484

485485
// There are no overheads on local slices when using len function!
@@ -785,7 +785,7 @@ func NewClientsInstance() *clientsData {
785785
return &clientsData{
786786
// Here we store the c
787787
clients: make(map[*Client]bool),
788-
// Creating map of Clients indexes
788+
// Creating map of ClientsStatus indexes
789789
clientsIndex: ClientsIndex{
790790
Users: make(map[string]map[uint64]*Client),
791791
Devices: make(map[string]map[uint64]*Client),

Diff for: core/listeners/http/server/server_structure.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ type Server struct {
9393
onBeforeStart *_map_string_interface.MapStringInterface
9494
onStarted *_map_string_interface.MapStringInterface
9595

96-
// Here we store the active/registered Clients (Connections)
96+
// Here we store the active/registered ClientsStatus (Connections)
9797
c *clientsData
9898
}
9999

Diff for: core/listeners/websocket/server/hub_broadcast.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ const SplitForPercentageLoad = 25 // 25 percentage*/
2222
// 1750 / 437.5 = 4 GoRoutines
2323
//
2424
// ---------------ALGO nr. 2------------------\\
25-
// Total nr of Clients
26-
// If Nr of Clients
25+
// Total nr of ClientsStatus
26+
// If Nr of ClientsStatus
2727
// x < 10 -> 2 routine
2828
// 10 < x < 50 -> 5 routines
2929
// 50 < x < 100 -> 10 routines
@@ -97,7 +97,7 @@ func (h *Hub) run() {
9797
nrOfRoutines := getNrOfRoutines(uint64(nrOfClients))
9898
clients := h.c.GetClientsInChunks(nrOfRoutines)
9999

100-
// Split in multiple routines if there are many Clients
100+
// Split in multiple routines if there are many ClientsStatus
101101

102102
for _, clientsChunk := range clients {
103103
go func(c map[*Client]bool) {
@@ -119,7 +119,7 @@ func (h *Hub) run() {
119119
}()
120120
case broadcastTo := <-h.broadcastTo:
121121

122-
// For faster broadcasting maybe we should goroutine here... because looping through Clients takes some time...!
122+
// For faster broadcasting maybe we should goroutine here... because looping through ClientsStatus takes some time...!
123123
// And if starting more goroutines that will also start looping and transmit messages will not be a problem!
124124
// This will improve speed, but can consume resources!
125125

Diff for: core/listeners/websocket/server/hub_structure.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type Hub struct {
6363
// ControlMessages
6464
ControlChannel chan int
6565

66-
// Unregistered Clients
66+
// Unregistered ClientsStatus
6767
UnregisterClientChannel chan *Client
6868
}
6969

Diff for: core/listeners/websocket/server/server_client_indexing.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ func (c *clientsData) getClientsByFilter(filter FindClientsFilter) map[uint64]*C
487487
// Prepare the filter..
488488
prepareFilter(&filter)
489489

490-
// TODO: we can also save where we have found the Clients
490+
// TODO: we can also save where we have found the ClientsStatus
491491
// We are searching through 6 indexes!
492492

493493
// There are no overheads on local slices when using len function!
@@ -793,7 +793,7 @@ func NewClientsInstance() *clientsData {
793793
return &clientsData{
794794
// Here we store the c
795795
clients: make(map[*Client]bool),
796-
// Creating map of Clients indexes
796+
// Creating map of ClientsStatus indexes
797797
clientsIndex: ClientsIndex{
798798
Users: make(map[string]map[uint64]*Client),
799799
Devices: make(map[string]map[uint64]*Client),

Diff for: core/listeners/websocket/server/server_model.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ type Server struct {
137137

138138
// ------Settings ---------\\
139139

140-
// Here we store the active/registered Clients (Connections)
140+
// Here we store the active/registered ClientsStatus (Connections)
141141
// c map[*Client]bool
142142
// clientsIndex ClientsIndex
143143
c *clientsData

Diff for: core/listeners/websocket/server/server_registration_hub.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (h *RegistrationHub) unregisterClient(client *Client) {
3232
}
3333
}()
3434

35-
// Hub -> Server -> Clients
35+
// Hub -> Server -> ClientsStatus
3636
h.s.c.unregisterClient(client)
3737

3838
// Close the channel for output buffering

Diff for: core/listeners/websocket/server/server_status.go

+43
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,17 @@ import (
55
"github.com/kyaxcorp/go-core/core/helpers/info"
66
"runtime"
77
"strings"
8+
"time"
89
)
910

11+
type ClientDetails struct {
12+
IPAddress string
13+
ConnectedAt time.Time
14+
ConnectedSeconds int64
15+
UserID string
16+
DeviceID string
17+
}
18+
1019
type FullStatus struct {
1120
Name string
1221
ListeningAddresses []string
@@ -112,6 +121,34 @@ func (s *Server) Stack(onCollected func(stack string)) {
112121
}()
113122
}
114123

124+
func (s *Server) ClientsStatus(onCollected func(clients []ClientDetails)) {
125+
go func() {
126+
127+
/*
128+
IP
129+
Device ID
130+
Connected Time
131+
*/
132+
133+
now := time.Now()
134+
currentClients := s.GetClients()
135+
var cls []ClientDetails
136+
for c, _ := range currentClients {
137+
cls = append(cls, ClientDetails{
138+
IPAddress: c.GetIPAddress(),
139+
ConnectedAt: c.connectTime,
140+
ConnectedSeconds: now.Unix() - c.connectTime.Unix(),
141+
UserID: c.GetUserID(),
142+
DeviceID: c.GetDeviceID(),
143+
})
144+
}
145+
146+
if onCollected != nil {
147+
onCollected(cls)
148+
}
149+
}()
150+
}
151+
115152
func (s *Server) StatusHubs(onCollected func(status HubsStatus)) {
116153
go func() {
117154
status := HubsStatus{
@@ -168,6 +205,11 @@ func (s *Server) startServerStatus() *Server {
168205
// We have received the status, and we return through channel the response!
169206
awaitStatus <- stack
170207
})
208+
case "clients":
209+
s.ClientsStatus(func(clients []ClientDetails) {
210+
// We have received the status, and we return through channel the response!
211+
awaitStatus <- clients
212+
})
171213
default:
172214
s.Status(func(status FullStatus) {
173215
// We have received the status, and we return through channel the response!
@@ -194,6 +236,7 @@ func (s *Server) startServerStatus() *Server {
194236
serverStatus.GET("/stack", getStatus)
195237
serverStatus.GET("/hubs", getStatus)
196238
serverStatus.GET("/nr_of_clients", getStatus)
239+
serverStatus.GET("/clients", getStatus)
197240
serverStatus.GET("/system_status", getStatus)
198241
}
199242
return s

0 commit comments

Comments
 (0)