Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
name: golangci-lint
on:
push:
paths:
- "go.sum"
- "go.mod"
- "**.go"
- ".github/workflows/golangci-lint.yml"
- ".golangci.yml"
pull_request:

permissions: # added using https://github.com/step-security/secure-repo
contents: read

jobs:
golangci:
permissions:
contents: read # for actions/checkout to fetch code
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
name: lint
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Install Go
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
with:
go-version: 1.23.x
- name: Lint
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1
with:
args: --verbose
version: v1.62.0
12 changes: 12 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
linters:
enable:
# - goimports
# - misspell
# - revive

issues:
exclude-rules:
- path: _test.go
linters:
- errcheck
2 changes: 1 addition & 1 deletion cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func runWebsocketClient() error {
if err != nil {
return err
}
defer c.CloseNow()
defer c.CloseNow() //nolint:errcheck
cloudLogger.Infof("websocket connected to %s", wsURL)
runCtx, cancelRun := context.WithCancel(context.Background())
defer cancelRun()
Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"kvm"
"github.com/jetkvm/kvm"
)

func main() {
Expand Down
3 changes: 2 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package kvm
import (
"encoding/json"
"fmt"
"kvm/internal/usbgadget"
"os"
"sync"

"github.com/jetkvm/kvm/internal/usbgadget"
)

type WakeOnLanDevice struct {
Expand Down
6 changes: 3 additions & 3 deletions display.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func startBacklightTickers() {
// Don't start the tickers if the display is switched off.
// Set the display to off if that's the case.
if config.DisplayMaxBrightness == 0 {
setDisplayBrightness(0)
_ = setDisplayBrightness(0)
return
}

Expand All @@ -221,7 +221,7 @@ func startBacklightTickers() {
defer dimTicker.Stop()

go func() {
for {
for { //nolint:gosimple
select {
case <-dimTicker.C:
tick_displayDim()
Expand All @@ -236,7 +236,7 @@ func startBacklightTickers() {
defer offTicker.Stop()

go func() {
for {
for { //nolint:gosimple
select {
case <-offTicker.C:
tick_displayOff()
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module kvm
module github.com/jetkvm/kvm

go 1.21.0

Expand All @@ -15,7 +15,6 @@ require (
github.com/gwatts/rootcerts v0.0.0-20240401182218-3ab9db955caf
github.com/hanwen/go-fuse/v2 v2.5.1
github.com/hashicorp/go-envparse v0.1.0
github.com/openstadia/go-usb-gadget v0.0.0-20231115171102-aebd56bbb965
github.com/pion/logging v0.2.2
github.com/pion/mdns/v2 v2.0.7
github.com/pion/webrtc/v4 v4.0.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/openstadia/go-usb-gadget v0.0.0-20231115171102-aebd56bbb965 h1:bZGtUfkOl0dqvem8ltx9KCYied0gSlRuDhaZDxgppN4=
github.com/openstadia/go-usb-gadget v0.0.0-20231115171102-aebd56bbb965/go.mod h1:6cAIK2c4O3/yETSrRjmNwsBL3yE4Vcu9M9p/Qwx5+gM=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pilebones/go-udev v0.9.0 h1:N1uEO/SxUwtIctc0WLU0t69JeBxIYEYnj8lT/Nabl9Q=
Expand Down
4 changes: 2 additions & 2 deletions hw.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func extractSerialNumber() (string, error) {
return "", err
}

r, err := regexp.Compile("Serial\\s*:\\s*(\\S+)")
r, err := regexp.Compile(`Serial\s*:\s*(\S+)`)
if err != nil {
return "", fmt.Errorf("failed to compile regex: %w", err)
}
Expand All @@ -27,7 +27,7 @@ func extractSerialNumber() (string, error) {
return matches[1], nil
}

func readOtpEntropy() ([]byte, error) {
func readOtpEntropy() ([]byte, error) { //nolint:unused
content, err := os.ReadFile("/sys/bus/nvmem/devices/rockchip-otp0/nvmem")
if err != nil {
return nil, err
Expand Down
4 changes: 0 additions & 4 deletions jiggler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import (

var lastUserInput = time.Now()

func resetUserInputTime() {
lastUserInput = time.Now()
}

var jigglerEnabled = false

func rpcSetJigglerState(enabled bool) {
Expand Down
16 changes: 8 additions & 8 deletions jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"kvm/internal/usbgadget"
"os"
"os/exec"
"path/filepath"
Expand All @@ -15,6 +14,8 @@ import (

"github.com/pion/webrtc/v4"
"go.bug.st/serial"

"github.com/jetkvm/kvm/internal/usbgadget"
)

type JSONRPCRequest struct {
Expand Down Expand Up @@ -195,8 +196,7 @@ func rpcSetEDID(edid string) error {

// Save EDID to config, allowing it to be restored on reboot.
config.EdidString = edid
SaveConfig()

_ = SaveConfig()
return nil
}

Expand Down Expand Up @@ -596,18 +596,18 @@ func rpcSetActiveExtension(extensionId string) error {
return nil
}
if config.ActiveExtension == "atx-power" {
unmountATXControl()
_ = unmountATXControl()
} else if config.ActiveExtension == "dc-power" {
unmountDCControl()
_ = unmountDCControl()
}
config.ActiveExtension = extensionId
if err := SaveConfig(); err != nil {
return fmt.Errorf("failed to save config: %w", err)
}
if extensionId == "atx-power" {
mountATXControl()
_ = mountATXControl()
} else if extensionId == "dc-power" {
mountDCControl()
_ = mountDCControl()
}
return nil
}
Expand Down Expand Up @@ -728,7 +728,7 @@ func rpcSetSerialSettings(settings SerialSettings) error {
Parity: parity,
}

port.SetMode(serialPortMode)
_ = port.SetMode(serialPortMode)

return nil
}
Expand Down
1 change: 0 additions & 1 deletion log.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ import "github.com/pion/logging"
// we use logging framework from pion
// ref: https://github.com/pion/webrtc/wiki/Debugging-WebRTC
var logger = logging.NewDefaultLoggerFactory().NewLogger("jetkvm")
var usbLogger = logging.NewDefaultLoggerFactory().NewLogger("usb")
var cloudLogger = logging.NewDefaultLoggerFactory().NewLogger("cloud")
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func Main() {
time.Sleep(15 * time.Minute)
for {
logger.Debugf("UPDATING - Auto update enabled: %v", config.AutoUpdateEnabled)
if config.AutoUpdateEnabled == false {
if !config.AutoUpdateEnabled {
return
}
if currentSession != nil {
Expand Down
7 changes: 4 additions & 3 deletions native.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"encoding/json"
"fmt"
"io"
"kvm/resource"
"net"
"os"
"os/exec"
"sync"
"syscall"
"time"

"github.com/jetkvm/kvm/resource"

"github.com/pion/webrtc/v4/pkg/media"
)

Expand Down Expand Up @@ -90,8 +91,8 @@ func WriteCtrlMessage(message []byte) error {
return err
}

var nativeCtrlSocketListener net.Listener
var nativeVideoSocketListener net.Listener
var nativeCtrlSocketListener net.Listener //nolint:unused
var nativeVideoSocketListener net.Listener //nolint:unused

var ctrlClientConnected = make(chan struct{})

Expand Down
2 changes: 1 addition & 1 deletion network.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func checkNetworkState() {
if newState != networkState {
logger.Info("network state changed")
// restart MDNS
startMDNS()
_ = startMDNS()
networkState = newState
requestDisplayUpdate()
}
Expand Down
2 changes: 0 additions & 2 deletions ntp.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const (
)

var (
timeSynced = false
timeSyncRetryInterval = 0 * time.Second
defaultNTPServers = []string{
"time.cloudflare.com",
Expand Down Expand Up @@ -58,7 +57,6 @@ func TimeSyncLoop() {
continue
}
logger.Infof("Time sync successful, now is: %v, time taken: %v", time.Now(), time.Since(start))
timeSynced = true
time.Sleep(timeSyncInterval) // after the first sync is done
}
}
Expand Down
2 changes: 1 addition & 1 deletion remote_mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (w *WebRTCDiskReader) Read(ctx context.Context, offset int64, size int64) (
if err != nil {
return nil, err
}
buf := make([]byte, 0)
var buf []byte
for {
select {
case data := <-diskReadChan:
Expand Down
14 changes: 7 additions & 7 deletions serial.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ const serialPortPath = "/dev/ttyS3"
var port serial.Port

func mountATXControl() error {
port.SetMode(defaultMode)
_ = port.SetMode(defaultMode)
go runATXControl()

return nil
}

func unmountATXControl() error {
reopenSerialPort()
_ = reopenSerialPort()
return nil
}

Expand Down Expand Up @@ -122,13 +122,13 @@ func pressATXResetButton(duration time.Duration) error {
}

func mountDCControl() error {
port.SetMode(defaultMode)
_ = port.SetMode(defaultMode)
go runDCControl()
return nil
}

func unmountDCControl() error {
reopenSerialPort()
_ = reopenSerialPort()
return nil
}

Expand Down Expand Up @@ -212,11 +212,11 @@ var defaultMode = &serial.Mode{
}

func initSerialPort() {
reopenSerialPort()
_ = reopenSerialPort()
if config.ActiveExtension == "atx-power" {
mountATXControl()
_ = mountATXControl()
} else if config.ActiveExtension == "dc-power" {
mountDCControl()
_ = mountDCControl()
}
}

Expand Down
8 changes: 5 additions & 3 deletions terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ func handleTerminalChannel(d *webrtc.DataChannel) {
var size TerminalSize
err := json.Unmarshal([]byte(msg.Data), &size)
if err == nil {
pty.Setsize(ptmx, &pty.Winsize{
err = pty.Setsize(ptmx, &pty.Winsize{
Rows: uint16(size.Rows),
Cols: uint16(size.Cols),
})
return
if err == nil {
return
}
}
logger.Errorf("Failed to parse terminal size: %v", err)
}
Expand All @@ -74,7 +76,7 @@ func handleTerminalChannel(d *webrtc.DataChannel) {
ptmx.Close()
}
if cmd != nil && cmd.Process != nil {
cmd.Process.Kill()
_ = cmd.Process.Kill()
}
})
}
6 changes: 1 addition & 5 deletions usb.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package kvm

import (
"kvm/internal/usbgadget"
"github.com/jetkvm/kvm/internal/usbgadget"
"time"
)

Expand Down Expand Up @@ -37,10 +37,6 @@ func rpcWheelReport(wheelY int8) error {
return gadget.AbsMouseWheelReport(wheelY)
}

func rpcRelMouseReport(mx, my int8, buttons uint8) error {
return gadget.RelMouseReport(mx, my, buttons)
}

var usbState = "unknown"

func rpcGetUSBState() (state string) {
Expand Down
Loading
Loading