예제 #1
0
func (httpServer *httpServer) websocketRouter(ws *websocket.Conn) {
	if ws.Request().URL.Path == TAIL_PATH {
		httpServer.websocketSinkHandler(ws)
	} else if ws.Request().URL.Path == DUMP_PATH {
		httpServer.dumpSinkHandler(ws)
	} else {
		ws.CloseWithStatus(400)
		return
	}
}
예제 #2
0
func (websocketServer *websocketServer) route(ws *websocket.Conn) {
	switch ws.Request().URL.Path {
	case TAIL_LOGS_PATH:
		websocketServer.streamLogs(ws)
	case RECENT_LOGS_PATH:
		websocketServer.recentLogs(ws)
	default:
		ws.CloseWithStatus(400)
		return
	}
}
예제 #3
0
func (httpServer *httpServer) dumpSinkHandler(ws *websocket.Conn) {
	clientAddress := ws.RemoteAddr()
	appId := appid.FromUrl(ws.Request().URL)

	if appId == "" {
		httpServer.logInvalidApp(clientAddress)
		ws.CloseWithStatus(4000)
		return
	}

	dumpChan := httpServer.messageRouter.getDumpChanFor(appId)

	dumpMessagesFromChannelToWebsocket(dumpChan, ws, clientAddress, httpServer.logger)

	ws.Close()
}
예제 #4
0
func (httpServer *httpServer) websocketSinkHandler(ws *websocket.Conn) {
	clientAddress := ws.RemoteAddr()
	appId := appid.FromUrl(ws.Request().URL)

	if appId == "" {
		httpServer.logInvalidApp(clientAddress)
		ws.CloseWithStatus(4000)
		return
	}

	s := sinks.NewWebsocketSink(appId, httpServer.logger, ws, clientAddress, httpServer.messageRouter.sinkCloseChan, httpServer.keepAliveInterval, httpServer.wSMessageBufferSize)
	httpServer.logger.Debugf("HttpServer: Requesting a wss sink for app %s", s.AppId())
	httpServer.messageRouter.sinkOpenChan <- s

	s.Run()
}
예제 #5
0
func (websocketServer *websocketServer) recentLogs(ws *websocket.Conn) {
	clientAddress := ws.RemoteAddr()
	appId := appid.FromUrl(ws.Request().URL)

	if appId == "" {
		websocketServer.logInvalidApp(clientAddress)
		ws.CloseWithStatus(4000)
		return
	}

	logMessages := websocketServer.sinkManager.recentLogsFor(appId)

	sendMessagesToWebsocket(logMessages, ws, clientAddress, websocketServer.logger)

	ws.Close()
}
예제 #6
0
func (sinkServer *sinkServer) sinkRelayHandler(ws *websocket.Conn) {
	clientAddress := ws.RemoteAddr()

	appId := appid.FromUrl(ws.Request().URL)
	authToken := ws.Request().Header.Get("Authorization")

	if appId == "" {
		message := fmt.Sprintf("SinkServer: Did not accept sink connection with invalid app id: %s.", clientAddress)
		sinkServer.logger.Warn(message)
		ws.CloseWithStatus(4000)
		return
	}

	if authToken == "" {
		message := fmt.Sprintf("SinkServer: Did not accept sink connection from %s without authorization.", clientAddress)
		sinkServer.logger.Warnf(message)
		ws.CloseWithStatus(4001)
		return
	}

	if !sinkServer.authorize(authToken, appId, sinkServer.logger) {
		message := fmt.Sprintf("SinkServer: Auth token [%s] not authorized to access appId [%s].", authToken, appId)
		sinkServer.logger.Warn(message)
		ws.CloseWithStatus(4002)
		return
	}

	s := sinks.NewWebsocketSink(appId, sinkServer.logger, ws, clientAddress, sinkServer.keepAliveInterval)

	sinkServer.activeSinksChans.Register(s.Channel(), appId)
	s.Run(sinkServer.sinkCloseChan)
}
예제 #7
0
func (httpServer *httpServer) dumpSinkHandler(ws *websocket.Conn) {
	clientAddress := ws.RemoteAddr()
	appId := appid.FromUrl(ws.Request().URL)

	if appId == "" {
		httpServer.logInvalidApp(clientAddress)
		ws.CloseWithStatus(4000)
		return
	}

	dumpChan := httpServer.messageRouter.registerDumpChan(appId)

	for message := range dumpChan {
		err := websocket.Message.Send(ws, message.GetRawMessage())
		if err != nil {
			httpServer.logger.Debugf("Dump Sink %s: Error when trying to send data to sink %s. Requesting close. Err: %v", clientAddress, err)
		} else {
			httpServer.logger.Debugf("Dump Sink %s: Successfully sent data", clientAddress)
		}
	}

	ws.Close()
}
예제 #8
0
func (websocketServer *websocketServer) streamLogs(ws *websocket.Conn) {
	clientAddress := ws.RemoteAddr()
	appId := appid.FromUrl(ws.Request().URL)

	if appId == "" {
		websocketServer.logInvalidApp(clientAddress)
		ws.CloseWithStatus(4000)
		return
	}

	websocketSink := sinks.NewWebsocketSink(
		appId,
		websocketServer.logger,
		ws,
		clientAddress,
		websocketServer.sinkManager.sinkCloseChan,
		websocketServer.keepAliveInterval,
		websocketServer.bufferSize,
	)
	websocketServer.logger.Debugf("WebsocketServer: Requesting a wss sink for app %s", websocketSink.AppId())
	websocketServer.sinkManager.sinkOpenChan <- websocketSink

	websocketSink.Run()
}