Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add skywire-utilities libraries #1911

Merged
merged 1 commit into from
Dec 16, 2024
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
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,15 @@ lint: ## Run linters. Use make install-linters first
${OPTS} golangci-lint run -c .golangci.yml ./cmd/...
${OPTS} golangci-lint run -c .golangci.yml ./pkg/...
${OPTS} golangci-lint run -c .golangci.yml ./...

gocyclo: ## Run gocyclo
gocyclo -over 14 .

lint-windows: ## Run linters. Use make install-linters-windows first
powershell 'golangci-lint --version'
powershell 'golangci-lint run -c .golangci.yml ./...'

gocyclo-windows: ## Run gocyclo on windows
powershell 'gocyclo -over 14 .'

test: ## Run tests
Expand Down Expand Up @@ -214,7 +218,6 @@ tidy: ## Tidies and vendors dependencies.
format: tidy ## Formats the code. Must have goimports and goimports-reviser installed (use make install-linters).
${OPTS} goimports -w -local ${PROJECT_BASE} ./pkg ./cmd ./internal
find . -type f -name '*.go' -not -path "./.git/*" -not -path "./vendor/*" -exec goimports-reviser -project-name ${PROJECT_BASE} {} \;
gocyclo -over 14 .

format-windows: tidy ## Formats the code. Must have goimports and goimports-reviser installed (use make install-linters).
powershell 'Get-ChildItem -Directory | where Name -NotMatch vendor | % { Get-ChildItem $$_ -Recurse -Include *.go } | % {goimports -w -local ${PROJECT_BASE} $$_ }'
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/gen2brain/dlgs v0.0.0-20220603100644-40c77870fa8d
github.com/gin-gonic/gin v1.10.0
github.com/go-chi/chi/v5 v5.1.0
github.com/go-redis/redis/v8 v8.11.5
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1
github.com/google/uuid v1.6.0
github.com/gorilla/securecookie v1.1.2
Expand All @@ -25,8 +26,11 @@ require (
github.com/ivanpirog/coloredcobra v1.0.1
github.com/james-barrow/golang-ipc v1.2.4
github.com/jaypipes/ghw v0.13.0
github.com/json-iterator/go v1.1.12
github.com/lib/pq v1.10.9
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
github.com/orandin/lumberjackrus v1.0.1
github.com/pires/go-proxyproto v0.8.0
github.com/pterm/pterm v0.12.79
github.com/robert-nix/ansihtml v1.0.1
github.com/sirupsen/logrus v1.9.3
Expand Down Expand Up @@ -94,7 +98,6 @@ require (
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.22.1 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
Expand All @@ -113,7 +116,6 @@ require (
github.com/jaypipes/pcidb v1.0.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/klauspost/reedsolomon v1.12.4 // indirect
github.com/kyokomi/emoji/v2 v2.2.13 // indirect
Expand All @@ -124,14 +126,12 @@ require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/onsi/ginkgo/v2 v2.20.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/pires/go-proxyproto v0.8.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/quic-go/quic-go v0.48.0 // indirect
Expand Down
181 changes: 132 additions & 49 deletions pkg/skyenv/skyenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,87 +18,170 @@ const (
// Dmsg port constants.
// TODO(evanlinjin): Define these properly. These are currently random.

DmsgCtrlPort uint16 = 7 // DmsgCtrlPort Listening port for dmsgctrl protocol (similar to TCP Echo Protocol). //nolint
DmsgSetupPort uint16 = 36 // DmsgSetupPort Listening port of a setup node.
DmsgHypervisorPort uint16 = 46 // DmsgHypervisorPort Listening port of a hypervisor for incoming RPC visor connections over dmsg.
DmsgTransportSetupPort uint16 = 47 // DmsgTransportSetupPort Listening port for transport setup RPC over dmsg.
DmsgAwaitSetupPort uint16 = 136 // DmsgAwaitSetupPort Listening port of a visor for setup operations.
// DmsgCtrlPort Listening port for dmsgctrl protocol (similar to TCP Echo Protocol). //nolint
DmsgCtrlPort uint16 = 7

// DmsgSetupPort Listening port of a setup node.
DmsgSetupPort uint16 = 36

// DmsgHypervisorPort Listening port of a hypervisor for incoming RPC visor connections over dmsg.
DmsgHypervisorPort uint16 = 46

// DmsgTransportSetupPort Listening port for transport setup RPC over dmsg.
DmsgTransportSetupPort uint16 = 47

// DmsgAwaitSetupPort Listening port of a visor for setup operations.
DmsgAwaitSetupPort uint16 = 136

// Transport port constants.

TransportPort uint16 = 45 // TransportPort Listening port of a visor for incoming transports.
PublicAutoconnect = true // PublicAutoconnect ...
// TransportPort Listening port of a visor for incoming transports.
TransportPort uint16 = 45

// PublicAutoconnect determines if the visor automatically creates stcpr transports to public visors
PublicAutoconnect = true

// Dmsgpty constants.

DmsgPtyPort uint16 = 22 // DmsgPtyPort ...
DmsgPtyCLINet = "unix" // DmsgPtyCLINet ...
// DmsgPtyPort is the dmsg port to listen on for dmsgpty connections
DmsgPtyPort uint16 = 22

// DmsgPtyCLINet is the type of cli net used by dmsgpty
DmsgPtyCLINet = "unix"

// Skywire-TCP constants.

STCPAddr = ":7777" // STCPAddr ...
// STCPAddr is the address to listen for stcpr or stcp transports
STCPAddr = ":7777"

// Default skywire app constants.

SkychatName = "skychat" // SkychatName ...
SkychatPort uint16 = 1 // SkychatPort ...
SkychatAddr = ":8001" // SkychatAddr ...
PingTestName = "pingtest" // PingTestName ...
PingTestPort uint16 = 2 // PingTestPort ...
SkysocksName = "skysocks" // SkysocksName ...
SkysocksPort uint16 = 3 // SkysocksPort ...
// SkychatName is the name of the skychat app
SkychatName = "skychat"

// SkychatPort is the dmsg port used by skychat
SkychatPort uint16 = 1

// SkychatAddr is the non-dmsg port used to access the skychat app on localhost
SkychatAddr = ":8001"

// PingTestName is the namew of the ping test
PingTestName = "pingtest"

SkysocksClientName = "skysocks-client" // SkysocksClientName ...
SkysocksClientPort uint16 = 13 // SkysocksClientPort ...
SkysocksClientAddr = ":1080" // SkysocksClientAddr ...
// PingTestPort is the port to user for ping tests
PingTestPort uint16 = 2

VPNServerName = "vpn-server" // VPNServerName ...
VPNServerPort uint16 = 44 // VPNServerPort ...
// SkysocksName is the name of the skysocks app
SkysocksName = "skysocks"

VPNClientName = "vpn-client" // VPNClientName ...
// SkysocksPort is the skysocks port on dmsg
SkysocksPort uint16 = 3

// SkysocksClientName is the skysocks-client app name
SkysocksClientName = "skysocks-client"

// SkysocksClientPort is the skysocks-client app dmsg port
SkysocksClientPort uint16 = 13

// SkysocksClientAddr is the default port the socks5 proxy client serves on
SkysocksClientAddr = ":1080"

// VPNServerName is the name of the vpn server app
VPNServerName = "vpn-server"

// VPNServerPort is the vpn server dmsg port
VPNServerPort uint16 = 44

// VPNClientName is the name of the vpn client app
VPNClientName = "vpn-client"

// TODO(darkrengarius): this one's not needed for the app to run but lack of it causes errors

VPNClientPort uint16 = 43 // VPNClientPort ...
ExampleServerName = "example-server-app" // ExampleServerName ...
ExampleServerPort uint16 = 45 // ExampleServerPort ...
ExampleClientName = "example-client-app" // ExampleClientName ...
ExampleClientPort uint16 = 46 // ExampleClientPort ...
SkyForwardingServerName = "sky-forwarding" // SkyForwardingServerName ...
SkyForwardingServerPort uint16 = 47 // SkyForwardingServerPort ...
SkyPingName = "sky-ping" // SkyPingName ...
SkyPingPort uint16 = 48 // SkyPingPort ...
// VPNClientPort over dmsg
VPNClientPort uint16 = 43

// ExampleServerName is the name of the example server app
ExampleServerName = "example-server-app"

// ExampleServerPort is dmsg port of example server app
ExampleServerPort uint16 = 45

// ExampleClientName is the name of the example client app
ExampleClientName = "example-client-app"

// ExampleClientPort dmsg port of example client app
ExampleClientPort uint16 = 46

// SkyForwardingServerName name of sky forwarding server app
SkyForwardingServerName = "sky-forwarding"

// SkyForwardingServerPort dmsg port of skyfwd server app
SkyForwardingServerPort uint16 = 47

// SkyPingName is the name of the sky ping
SkyPingName = "sky-ping"

// SkyPingPort dmsg port of sky ping
SkyPingPort uint16 = 48

// RPC constants.

RPCAddr = "localhost:3435" // RPCAddr ...
RPCTimeout = 20 * time.Second // RPCTimeout ...
TransportRPCTimeout = 1 * time.Minute // TransportRPCTimeout ...
UpdateRPCTimeout = 6 * time.Hour // UpdateRPCTimeout update requires huge timeout
// RPCAddr for skywire-cli to access skywire-visor
RPCAddr = "localhost:3435"

// RPCTimeout timeout of rpc requests
RPCTimeout = 20 * time.Second

// TransportRPCTimeout timeout of transport rpc
TransportRPCTimeout = 1 * time.Minute

// UpdateRPCTimeout update requires huge timeout - NOTE: this is likely unused
UpdateRPCTimeout = 6 * time.Hour

// Default skywire app server and discovery constants

AppSrvAddr = "localhost:5505" // AppSrvAddr ...
ServiceDiscUpdateInterval = time.Minute // ServiceDiscUpdateInterval ...
AppBinPath = "./" // AppBinPath ...
LogLevel = "info" // LogLevel ...
// AppSrvAddr address of app server
AppSrvAddr = "localhost:5505"

// ServiceDiscUpdateInterval update interval for apps in service discovery
ServiceDiscUpdateInterval = time.Minute

// AppBinPath is the default path for the apps
AppBinPath = "./"

// LogLevel is the default log level of the visor
LogLevel = "info"

// Routing constants

TpLogStore = "transport_logs" // TpLogStore ...
Custom = "custom" // Custom ...
// TpLogStore is where tp logs are stored
TpLogStore = "transport_logs"

// LocalPath constants
// Custom path to serve files from dmsghttp log server over dmsg
Custom = "custom"

// LocalPath where the visor writes files to
LocalPath = "./local"

// Default hypervisor constants

HypervisorDB = ".skycoin/hypervisor/users.db" //HypervisorDB ...
EnableAuth = false // EnableAuth ...
PackageEnableAuth = true // PackageEnableAuth ...
EnableTLS = false // EnableTLS ...
TLSKey = "./ssl/key.pem" // TLSKey ...
TLSCert = "./ssl/cert.pem" // TLSCert ...
//HypervisorDB stores the password to access the hypervisor
HypervisorDB = ".skycoin/hypervisor/users.db"

// EnableAuth enables auth on the hypervisor UI
EnableAuth = false

// PackageEnableAuth is the default auth for package-based installations for hypervisor UI
PackageEnableAuth = true

// EnableTLS enables tls for accessing hypervisor ui
EnableTLS = false

// TLSKey for access to hvui
TLSKey = "./ssl/key.pem"

// TLSCert for access to hvui
TLSCert = "./ssl/cert.pem"

// IPCShutdownMessageType sends IPC shutdown message type
IPCShutdownMessageType = 68
Expand Down
81 changes: 81 additions & 0 deletions pkg/skywire-utilities/pkg/buildinfo/buildinfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Package buildinfo pkg/buildinfo/buildinfo.go
package buildinfo

import (
"encoding/json"
"fmt"
"io"
)

const unknown = "unknown"

//$ go build -mod=vendor -ldflags="-X 'github.com/skycoin/skywire-utilities/pkg/buildinfo.version=$(git describe)' -X 'github.com/skycoin/skywire-utilities/pkg/buildinfo.date=$(date -u "+%Y-%m-%dT%H:%M:%SZ")' -X 'github.com/skycoin/skywire-utilities/pkg/buildinfo.commit=$(git rev-list -1 HEAD)'" .

var (
version = unknown
commit = unknown
date = unknown
)

// $ go build -ldflags="-X 'github.com/skycoin/skywire-utilities/pkg/buildinfo.golist=$(go list -m -json -mod=mod github.com/skycoin/<repo>@<branch>)' -X 'github.com/skycoin/skywire-utilities/pkg/buildinfo.date=$(date -u "+%Y-%m-%dT%H:%M:%SZ")'" .
var golist string

// ModuleInfo represents the JSON structure returned by `go list -m -json`.
type ModuleInfo struct {
Version string `json:"Version"`
Origin struct {
Hash string `json:"Hash"`
} `json:"Origin"`
}

func init() {
if golist != "" {
var mInfo ModuleInfo
if err := json.Unmarshal([]byte(golist), &mInfo); err == nil {
if mInfo.Version != "" && version == unknown {
version = mInfo.Version
}
if mInfo.Origin.Hash != "" && commit == unknown {
commit = mInfo.Origin.Hash
}
}
}
}

// Version returns version from the parsed module info.
func Version() string {
return version
}

// Commit returns commit hash from the parsed module info.
func Commit() string {
return commit
}

// Date returns date of build in RFC3339 format.
func Date() string {
return date
}

// Get returns build info summary.
func Get() *Info {
return &Info{
Version: Version(),
Commit: Commit(),
Date: Date(),
}
}

// Info is build info summary.
type Info struct {
Version string `json:"version"`
Commit string `json:"commit"`
Date string `json:"date"`
}

// WriteTo writes build info summary to io.Writer.
func (info *Info) WriteTo(w io.Writer) (int64, error) {
msg := fmt.Sprintf("Version %q built on %q against commit %q\n", info.Version, info.Date, info.Commit)
n, err := w.Write([]byte(msg))
return int64(n), err
}
Loading
Loading