mirror of
https://github.com/kubeshark/kubeshark.git
synced 2026-07-10 00:51:09 +00:00
* WIP * Update tap.go, provider.go, and 2 more files... * WIP * WIP * Solved routine hanging forever: Added missing flag when calling mizuagent. * Iterate channel with range. * Panic if har channel is nil or if websocket connection is nil. * StartPassiveTapper returns read only channel. * Solved program exiting immediately: Wait for interrupt signal instead of exiting. * Solve connecting issue - Retry a few times. * Use lib const instead of magic. * Nicer error prints. * Don't coninue piping message if there is an error. * Comment. * Dependency injection. * no message * Fixed comment. * Print tapped addresses when they are updated. * Print errors in cleanup if there are any. Co-authored-by: RamiBerm <rami.berman@up9.com> Co-authored-by: Roee Gadot <roee.gadot@up9.com>
32 lines
1.2 KiB
Go
32 lines
1.2 KiB
Go
package routes
|
|
|
|
import (
|
|
"github.com/antoniodipinto/ikisocket"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
type EventHandlers interface {
|
|
WebSocketConnect(ep *ikisocket.EventPayload)
|
|
WebSocketDisconnect(ep *ikisocket.EventPayload)
|
|
WebSocketClose(ep *ikisocket.EventPayload)
|
|
WebSocketError(ep *ikisocket.EventPayload)
|
|
WebSocketMessage(ep *ikisocket.EventPayload)
|
|
}
|
|
|
|
func WebSocketRoutes(app *fiber.App, eventHandlers EventHandlers) {
|
|
app.Get("/ws", ikisocket.New(func(kws *ikisocket.Websocket) {
|
|
kws.SetAttribute("is_tapper", false)
|
|
}))
|
|
|
|
app.Get("/wsTapper", ikisocket.New(func(kws *ikisocket.Websocket) {
|
|
// Tapper clients are handled differently, they don't need to receive new message broadcasts.
|
|
kws.SetAttribute("is_tapper", true)
|
|
}))
|
|
|
|
ikisocket.On(ikisocket.EventMessage, eventHandlers.WebSocketMessage)
|
|
ikisocket.On(ikisocket.EventConnect, eventHandlers.WebSocketConnect)
|
|
ikisocket.On(ikisocket.EventDisconnect, eventHandlers.WebSocketDisconnect)
|
|
ikisocket.On(ikisocket.EventClose, eventHandlers.WebSocketClose) // This event is called when the server disconnects the user actively with .Close() method
|
|
ikisocket.On(ikisocket.EventError, eventHandlers.WebSocketError) // On error event
|
|
}
|