mirror of https://github.com/jetkvm/kvm.git
Compare commits
4 Commits
b201bd391d
...
2237b133b1
Author | SHA1 | Date |
---|---|---|
|
2237b133b1 | |
|
bde0a086ab | |
|
9c9335da31 | |
|
97b00c6ffc |
4
Makefile
4
Makefile
|
@ -2,8 +2,8 @@ BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
|
||||||
BUILDDATE ?= $(shell date -u +%FT%T%z)
|
BUILDDATE ?= $(shell date -u +%FT%T%z)
|
||||||
BUILDTS ?= $(shell date -u +%s)
|
BUILDTS ?= $(shell date -u +%s)
|
||||||
REVISION ?= $(shell git rev-parse HEAD)
|
REVISION ?= $(shell git rev-parse HEAD)
|
||||||
VERSION_DEV ?= 0.4.6-dev$(shell date +%Y%m%d%H%M)
|
VERSION_DEV ?= 0.4.7-dev$(shell date +%Y%m%d%H%M)
|
||||||
VERSION ?= 0.4.5
|
VERSION ?= 0.4.6
|
||||||
|
|
||||||
PROMETHEUS_TAG := github.com/prometheus/common/version
|
PROMETHEUS_TAG := github.com/prometheus/common/version
|
||||||
KVM_PKG_NAME := github.com/jetkvm/kvm
|
KVM_PKG_NAME := github.com/jetkvm/kvm
|
||||||
|
|
3
cloud.go
3
cloud.go
|
@ -223,6 +223,7 @@ func handleCloudRegister(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiReq.Header.Set("Content-Type", "application/json")
|
apiReq.Header.Set("Content-Type", "application/json")
|
||||||
|
apiReq.Header.Set("User-Agent", httpUserAgent)
|
||||||
|
|
||||||
apiResp, err := client.Do(apiReq)
|
apiResp, err := client.Do(apiReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -537,6 +538,8 @@ func rpcDeregisterDevice() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
req.Header.Set("Authorization", "Bearer "+config.CloudToken)
|
req.Header.Set("Authorization", "Bearer "+config.CloudToken)
|
||||||
|
req.Header.Set("User-Agent", httpUserAgent)
|
||||||
|
|
||||||
client := &http.Client{Timeout: CloudAPIRequestTimeout}
|
client := &http.Client{Timeout: CloudAPIRequestTimeout}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -57,6 +57,7 @@ func (t *TimeSync) queryMultipleHttp(urls []string, timeout time.Duration) (now
|
||||||
ctx,
|
ctx,
|
||||||
url,
|
url,
|
||||||
timeout,
|
timeout,
|
||||||
|
t.httpUserAgent,
|
||||||
)
|
)
|
||||||
duration := time.Since(startTime)
|
duration := time.Since(startTime)
|
||||||
|
|
||||||
|
@ -122,6 +123,7 @@ func queryHttpTime(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
url string,
|
url string,
|
||||||
timeout time.Duration,
|
timeout time.Duration,
|
||||||
|
httpUserAgent string,
|
||||||
) (now *time.Time, response *http.Response, err error) {
|
) (now *time.Time, response *http.Response, err error) {
|
||||||
client := http.Client{
|
client := http.Client{
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
|
@ -130,6 +132,10 @@ func queryHttpTime(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
if httpUserAgent != "" {
|
||||||
|
req.Header.Set("User-Agent", httpUserAgent)
|
||||||
|
}
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
|
|
@ -32,6 +32,8 @@ type TimeSync struct {
|
||||||
httpUrls []string
|
httpUrls []string
|
||||||
networkConfig *network.NetworkConfig
|
networkConfig *network.NetworkConfig
|
||||||
|
|
||||||
|
httpUserAgent string
|
||||||
|
|
||||||
rtcDevicePath string
|
rtcDevicePath string
|
||||||
rtcDevice *os.File //nolint:unused
|
rtcDevice *os.File //nolint:unused
|
||||||
rtcLock *sync.Mutex
|
rtcLock *sync.Mutex
|
||||||
|
@ -45,6 +47,7 @@ type TimeSyncOptions struct {
|
||||||
PreCheckFunc func() (bool, error)
|
PreCheckFunc func() (bool, error)
|
||||||
Logger *zerolog.Logger
|
Logger *zerolog.Logger
|
||||||
NetworkConfig *network.NetworkConfig
|
NetworkConfig *network.NetworkConfig
|
||||||
|
HttpUserAgent string
|
||||||
}
|
}
|
||||||
|
|
||||||
type SyncMode struct {
|
type SyncMode struct {
|
||||||
|
@ -71,6 +74,7 @@ func NewTimeSync(opts *TimeSyncOptions) *TimeSync {
|
||||||
preCheckFunc: opts.PreCheckFunc,
|
preCheckFunc: opts.PreCheckFunc,
|
||||||
ntpServers: defaultNTPServers,
|
ntpServers: defaultNTPServers,
|
||||||
httpUrls: defaultHTTPUrls,
|
httpUrls: defaultHTTPUrls,
|
||||||
|
httpUserAgent: opts.HttpUserAgent,
|
||||||
networkConfig: opts.NetworkConfig,
|
networkConfig: opts.NetworkConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -143,7 +143,7 @@ func (u *UsbGadget) listenKeyboardEvents() {
|
||||||
default:
|
default:
|
||||||
l.Trace().Msg("reading from keyboard")
|
l.Trace().Msg("reading from keyboard")
|
||||||
if u.keyboardHidFile == nil {
|
if u.keyboardHidFile == nil {
|
||||||
u.logWithSupression("keyboardHidFileNil", 100, &l, nil, "keyboardHidFile is nil")
|
u.logWithSuppression("keyboardHidFileNil", 100, &l, nil, "keyboardHidFile is nil")
|
||||||
// show the error every 100 times to avoid spamming the logs
|
// show the error every 100 times to avoid spamming the logs
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
continue
|
continue
|
||||||
|
@ -153,7 +153,7 @@ func (u *UsbGadget) listenKeyboardEvents() {
|
||||||
|
|
||||||
n, err := u.keyboardHidFile.Read(buf)
|
n, err := u.keyboardHidFile.Read(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
u.logWithSupression("keyboardHidFileRead", 100, &l, err, "failed to read")
|
u.logWithSuppression("keyboardHidFileRead", 100, &l, err, "failed to read")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
u.resetLogSuppressionCounter("keyboardHidFileRead")
|
u.resetLogSuppressionCounter("keyboardHidFileRead")
|
||||||
|
@ -201,7 +201,7 @@ func (u *UsbGadget) keyboardWriteHidFile(data []byte) error {
|
||||||
|
|
||||||
_, err := u.keyboardHidFile.Write(data)
|
_, err := u.keyboardHidFile.Write(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
u.logWithSupression("keyboardWriteHidFile", 100, u.log, err, "failed to write to hidg0")
|
u.logWithSuppression("keyboardWriteHidFile", 100, u.log, err, "failed to write to hidg0")
|
||||||
u.keyboardHidFile.Close()
|
u.keyboardHidFile.Close()
|
||||||
u.keyboardHidFile = nil
|
u.keyboardHidFile = nil
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -75,7 +75,7 @@ func (u *UsbGadget) absMouseWriteHidFile(data []byte) error {
|
||||||
|
|
||||||
_, err := u.absMouseHidFile.Write(data)
|
_, err := u.absMouseHidFile.Write(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
u.logWithSupression("absMouseWriteHidFile", 100, u.log, err, "failed to write to hidg1")
|
u.logWithSuppression("absMouseWriteHidFile", 100, u.log, err, "failed to write to hidg1")
|
||||||
u.absMouseHidFile.Close()
|
u.absMouseHidFile.Close()
|
||||||
u.absMouseHidFile = nil
|
u.absMouseHidFile = nil
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -65,7 +65,7 @@ func (u *UsbGadget) relMouseWriteHidFile(data []byte) error {
|
||||||
|
|
||||||
_, err := u.relMouseHidFile.Write(data)
|
_, err := u.relMouseHidFile.Write(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
u.logWithSupression("relMouseWriteHidFile", 100, u.log, err, "failed to write to hidg2")
|
u.logWithSuppression("relMouseWriteHidFile", 100, u.log, err, "failed to write to hidg2")
|
||||||
u.relMouseHidFile.Close()
|
u.relMouseHidFile.Close()
|
||||||
u.relMouseHidFile = nil
|
u.relMouseHidFile = nil
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -81,7 +81,7 @@ func compareFileContent(oldContent []byte, newContent []byte, looserMatch bool)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UsbGadget) logWithSupression(counterName string, every int, logger *zerolog.Logger, err error, msg string, args ...interface{}) {
|
func (u *UsbGadget) logWithSuppression(counterName string, every int, logger *zerolog.Logger, err error, msg string, args ...interface{}) {
|
||||||
u.logSuppressionLock.Lock()
|
u.logSuppressionLock.Lock()
|
||||||
defer u.logSuppressionLock.Unlock()
|
defer u.logSuppressionLock.Unlock()
|
||||||
|
|
||||||
|
|
4
main.go
4
main.go
|
@ -2,6 +2,7 @@ package kvm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
@ -12,6 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var appCtx context.Context
|
var appCtx context.Context
|
||||||
|
var httpUserAgent string = fmt.Sprintf("jetkvm-app/%s", builtAppVersion)
|
||||||
|
|
||||||
func Main() {
|
func Main() {
|
||||||
LoadConfig()
|
LoadConfig()
|
||||||
|
@ -25,6 +27,8 @@ func Main() {
|
||||||
logger.Warn().Err(err).Msg("failed to get local version")
|
logger.Warn().Err(err).Msg("failed to get local version")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
httpUserAgent = fmt.Sprintf("jetkvm-app/%s jetkvm-system/%s", appVersionLocal, systemVersionLocal)
|
||||||
|
|
||||||
logger.Info().
|
logger.Info().
|
||||||
Interface("system_version", systemVersionLocal).
|
Interface("system_version", systemVersionLocal).
|
||||||
Interface("app_version", appVersionLocal).
|
Interface("app_version", appVersionLocal).
|
||||||
|
|
3
ota.go
3
ota.go
|
@ -88,6 +88,7 @@ func fetchUpdateMetadata(ctx context.Context, deviceId string, includePreRelease
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error creating request: %w", err)
|
return nil, fmt.Errorf("error creating request: %w", err)
|
||||||
}
|
}
|
||||||
|
req.Header.Set("User-Agent", httpUserAgent)
|
||||||
|
|
||||||
resp, err := http.DefaultClient.Do(req)
|
resp, err := http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -131,7 +132,7 @@ func downloadFile(ctx context.Context, path string, url string, downloadProgress
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error creating request: %w", err)
|
return fmt.Errorf("error creating request: %w", err)
|
||||||
}
|
}
|
||||||
|
req.Header.Set("User-Agent", httpUserAgent)
|
||||||
client := http.Client{
|
client := http.Client{
|
||||||
Timeout: 10 * time.Minute,
|
Timeout: 10 * time.Minute,
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
|
|
Loading…
Reference in New Issue