Archived
2
0

lint fix.

This commit is contained in:
Miroslav Šedivý 2021-10-05 23:10:10 +02:00
parent 1ff743c598
commit 9c014336ff
16 changed files with 76 additions and 46 deletions

View File

@ -47,7 +47,7 @@ func init() {
}
if _, err := os.Stat(logs); os.IsNotExist(err) {
os.Mkdir(logs, os.ModePerm)
_ = os.Mkdir(logs, os.ModePerm)
}
latest := filepath.Join(logs, "neko-latest.log")

View File

@ -30,6 +30,11 @@ func New(remote *config.Remote, config *config.Broadcast) *BroadcastManager {
}
}
func (manager *BroadcastManager) Shutdown() error {
manager.Destroy()
return nil
}
func (manager *BroadcastManager) Start() error {
if !manager.enabled || manager.IsActive() {
return nil

View File

@ -63,10 +63,8 @@ func errResponse(input interface{}) *ErrResponse {
case *error:
e := err.(error)
res.Details = e.Error()
break
default:
res.Details = fmt.Sprintf("%+v", err)
break
}
}

View File

@ -3,7 +3,6 @@ package http
import (
"context"
"encoding/json"
"fmt"
"net/http"
"os"
@ -32,21 +31,22 @@ func New(conf *config.Server, webSocketHandler types.WebSocketHandler) *Server {
router.Use(middleware.Logger) // Log API request calls
router.Get("/ws", func(w http.ResponseWriter, r *http.Request) {
webSocketHandler.Upgrade(w, r)
err := webSocketHandler.Upgrade(w, r)
if err != nil {
logger.Warn().Err(err).Msg("failed to upgrade websocket conection")
}
})
router.Get("/stats", func(w http.ResponseWriter, r *http.Request) {
password := r.URL.Query().Get("pwd")
isAdmin, err := webSocketHandler.IsAdmin(password)
if err != nil {
w.WriteHeader(http.StatusForbidden)
fmt.Fprint(w, err)
http.Error(w, err.Error(), http.StatusForbidden)
return
}
if !isAdmin {
w.WriteHeader(http.StatusUnauthorized)
fmt.Fprint(w, "bad authorization")
http.Error(w, "bad authorization", http.StatusUnauthorized)
return
}
@ -59,7 +59,7 @@ func New(conf *config.Server, webSocketHandler types.WebSocketHandler) *Server {
})
router.Get("/health", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("true"))
_, _ = w.Write([]byte("true"))
})
fs := http.FileServer(http.Dir(conf.Static))
@ -67,8 +67,7 @@ func New(conf *config.Server, webSocketHandler types.WebSocketHandler) *Server {
if _, err := os.Stat(conf.Static + r.URL.Path); !os.IsNotExist(err) {
fs.ServeHTTP(w, r)
} else {
w.WriteHeader(http.StatusNotFound)
fmt.Fprint(w, "404 page not found")
http.NotFound(w, r)
}
})

View File

@ -250,7 +250,7 @@ func (manager *RemoteManager) GetScreenSize() *types.ScreenSize {
}
func (manager *RemoteManager) SetKeyboardLayout(layout string) {
exec.Command("setxkbmap", layout).Run()
_ = exec.Command("setxkbmap", layout).Run()
}
func (manager *RemoteManager) SetKeyboardModifiers(NumLock int, CapsLock int, ScrollLock int) {

View File

@ -141,7 +141,7 @@ func (manager *SessionManager) Members() []*types.Member {
return members
}
func (manager *SessionManager) Destroy(id string) error {
func (manager *SessionManager) Destroy(id string) {
manager.mu.Lock()
session, ok := manager.members[id]
if ok {
@ -154,11 +154,11 @@ func (manager *SessionManager) Destroy(id string) error {
manager.mu.Unlock()
manager.emmiter.Emit("destroyed", id, session)
return err
manager.logger.Err(err).Str("session_id", id).Msg("destorying session")
return
}
manager.mu.Unlock()
return nil
}
func (manager *SessionManager) Clear() error {

View File

@ -1,6 +1,7 @@
package types
type BroadcastManager interface {
Shutdown() error
Start() error
Stop()
IsActive() bool

View File

@ -38,7 +38,7 @@ type SessionManager interface {
Get(id string) (Session, bool)
Members() []*Member
Admins() []*Member
Destroy(id string) error
Destroy(id string)
Clear() error
Broadcast(v interface{}, exclude interface{}) error
OnHost(listener func(id string))

View File

@ -15,7 +15,7 @@ type WebSocket interface {
}
type WebSocketHandler interface {
Start() error
Start()
Shutdown() error
Upgrade(w http.ResponseWriter, r *http.Request) error
Stats() Stats

View File

@ -93,7 +93,7 @@ func (manager *WebRTCManager) CreatePeer(id string, session types.Session) (stri
settings.SetLite(true)
}
settings.SetEphemeralUDPPortRange(manager.config.EphemeralMin, manager.config.EphemeralMax)
_ = settings.SetEphemeralUDPPortRange(manager.config.EphemeralMin, manager.config.EphemeralMax)
settings.SetNAT1To1IPs(manager.config.NAT1To1IPs, webrtc.ICECandidateTypeHost)
settings.SetICETimeouts(6*time.Second, 6*time.Second, 3*time.Second)
settings.SetSRTPReplayProtectionWindow(512)
@ -101,8 +101,8 @@ func (manager *WebRTCManager) CreatePeer(id string, session types.Session) (stri
// Create MediaEngine based off sdp
engine := webrtc.MediaEngine{}
engine.RegisterCodec(manager.audioCodec, webrtc.RTPCodecTypeAudio)
engine.RegisterCodec(manager.videoCodec, webrtc.RTPCodecTypeVideo)
_ = engine.RegisterCodec(manager.audioCodec, webrtc.RTPCodecTypeAudio)
_ = engine.RegisterCodec(manager.videoCodec, webrtc.RTPCodecTypeVideo)
i := &interceptor.Registry{}
if err := webrtc.RegisterDefaultInterceptors(&engine, i); err != nil {

View File

@ -66,7 +66,10 @@ func (h *MessageHandler) adminControl(id string, session types.Session) error {
host, ok := h.sessions.GetHost()
h.sessions.SetHost(id)
err := h.sessions.SetHost(id)
if err != nil {
return err
}
if ok {
if err := h.sessions.Broadcast(
@ -138,7 +141,10 @@ func (h *MessageHandler) adminGive(id string, session types.Session, payload *me
}
// set host
h.sessions.SetHost(payload.ID)
err := h.sessions.SetHost(payload.ID)
if err != nil {
return err
}
// let everyone know
if err := h.sessions.Broadcast(

View File

@ -35,7 +35,10 @@ func (h *MessageHandler) controlRequest(id string, session types.Session) error
// check for host
if !h.sessions.HasHost() {
// set host
h.sessions.SetHost(id)
err := h.sessions.SetHost(id)
if err != nil {
return err
}
// let everyone know
if err := h.sessions.Broadcast(
@ -89,7 +92,10 @@ func (h *MessageHandler) controlGive(id string, session types.Session, payload *
}
// set host
h.sessions.SetHost(payload.ID)
err := h.sessions.SetHost(payload.ID)
if err != nil {
return err
}
// let everyone know
if err := h.sessions.Broadcast(

View File

@ -42,8 +42,8 @@ func (h *MessageHandler) Connected(admin bool, socket *WebSocket) (bool, string,
return true, "", nil
}
func (h *MessageHandler) Disconnected(id string) error {
return h.sessions.Destroy(id)
func (h *MessageHandler) Disconnected(id string) {
h.sessions.Destroy(id)
}
func (h *MessageHandler) Message(id string, raw []byte) error {

View File

@ -60,7 +60,7 @@ type WebSocketHandler struct {
conns uint32
}
func (ws *WebSocketHandler) Start() error {
func (ws *WebSocketHandler) Start() {
ws.sessions.OnCreated(func(id string, session types.Session) {
if err := ws.handler.SessionCreated(id, session); err != nil {
ws.logger.Warn().Str("id", id).Err(err).Msg("session created with and error")
@ -99,25 +99,33 @@ func (ws *WebSocketHandler) Start() error {
case <-ws.shutdown:
return
default:
if ws.sessions.HasHost() {
time.Sleep(100 * time.Millisecond)
if !ws.sessions.HasHost() {
continue
}
text := ws.remote.ReadClipboard()
if text != current {
if text == current {
continue
}
session, ok := ws.sessions.GetHost()
if ok {
session.Send(message.Clipboard{
err := session.Send(message.Clipboard{
Event: event.CONTROL_CLIPBOARD,
Text: text,
})
if err != nil {
ws.logger.Err(err).Msg("unable to synchronize clipboard")
}
}
current = text
}
}
time.Sleep(100 * time.Millisecond)
}
}
}()
return nil
}
func (ws *WebSocketHandler) Shutdown() error {

View File

@ -129,12 +129,12 @@ func WriteClipboard(data string) {
func ResetKeys() {
for code := range debounce_button {
ButtonUp(code)
_ = ButtonUp(code)
delete(debounce_button, code)
}
for code := range debounce_key {
KeyUp(code)
_ = KeyUp(code)
delete(debounce_key, code)
}
@ -146,7 +146,7 @@ func CheckKeys(duration time.Duration) {
if t.Sub(start) < duration {
continue
}
ButtonUp(code)
_ = ButtonUp(code)
delete(debounce_button, code)
}
@ -154,7 +154,7 @@ func CheckKeys(duration time.Duration) {
if t.Sub(start) < duration {
continue
}
KeyUp(code)
_ = KeyUp(code)
delete(debounce_key, code)
}

View File

@ -136,6 +136,7 @@ func (neko *Neko) Start() {
server := http.New(neko.Server, webSocketHandler)
server.Start()
neko.broadcastManager = broadcastManager
neko.sessionManager = sessionManager
neko.remoteManager = remoteManager
neko.webRTCManager = webRTCManager
@ -144,6 +145,12 @@ func (neko *Neko) Start() {
}
func (neko *Neko) Shutdown() {
if err := neko.broadcastManager.Shutdown(); err != nil {
neko.logger.Err(err).Msg("broadcast manager shutdown with an error")
} else {
neko.logger.Debug().Msg("broadcast manager shutdown")
}
if err := neko.remoteManager.Shutdown(); err != nil {
neko.logger.Err(err).Msg("remote manager shutdown with an error")
} else {