Пример #1
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)
}
Пример #2
0
func (w *WebsocketServer) streamLogs(appId string, ws *websocket.Conn) {
	defer ws.WriteControl(websocket.CloseMessage, []byte{}, time.Now().Add(100*time.Millisecond))
	websocketSink := sinks.NewWebsocketSink(
		appId,
		w.logger,
		ws,
		w.keepAliveInterval,
		w.bufferSize,
	)
	w.logger.Debugf("WebsocketServer: Requesting a wss sink for app %s", websocketSink.AppId())
	w.sinkManager.RegisterSink(websocketSink, false)
}
Пример #3
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()
}
Пример #4
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()
}