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

various small fixes #1151

Merged
merged 19 commits into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
73 changes: 34 additions & 39 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ snapshot-clean: ## Cleans snapshot / release
rm -rf ./dist

host-apps: ## Build app
test -d apps && rm -r apps || true
mkdir -p ./apps
${OPTS} go build ${BUILD_OPTS} -o ./apps/ ./cmd/apps/skychat
${OPTS} go build ${BUILD_OPTS} -o ./apps/ ./cmd/apps/skysocks
Expand Down Expand Up @@ -180,6 +181,7 @@ host-apps-systray-windows:

# Static Apps
host-apps-static: ## Build app
test -d apps && rm -r apps || true
mkdir -p ./apps
${STATIC_OPTS} go build -trimpath --ldflags '-linkmode external -extldflags "-static" -buildid=' -o ./apps/ ./cmd/apps/skychat
${STATIC_OPTS} go build -trimpath --ldflags '-linkmode external -extldflags "-static" -buildid=' -o ./apps/ ./cmd/apps/skysocks
Expand Down Expand Up @@ -233,68 +235,61 @@ install-deps-ui: ## Install the UI dependencies
run: ## Run skywire visor with skywire-config.json, and start a browser if running a hypervisor
./skywire-visor -bc ./skywire-config.json

## Run skywire from source, without compiling binaries - requires skywire cloned
run-source:
## Prepare to run skywire from source, without compiling binaries
prepare:
test -d apps && rm -r apps || true
ln -s scripts/_apps apps
chmod +x apps/*
mkdir -p apps
ln ./scripts/_apps/skychat ./apps/
ln ./scripts/_apps/skysocks ./apps/
ln ./scripts/_apps/skysocks-client ./apps/
ln ./scripts/_apps/vpn-server ./apps/
ln ./scripts/_apps/vpn-client ./apps/
chmod +x ./apps/*
sudo echo "sudo cache"

prepare-systray: prepare
rm apps/vpn*
ln -f ./scripts/_apps/vpn-server-systray ./apps/vpn-server
ln -f ./scripts/_apps/vpn-client-systray ./apps/vpn-client

## Run skywire from source, without compiling binaries - requires skywire cloned
run-source: prepare
go run ./cmd/skywire-cli/skywire-cli.go config gen -in | go run ./cmd/skywire-visor/skywire-visor.go -nb || true

## Run skywire from source, with vpn server enabled
run-systray: prepare-systray
go run -tags systray ./cmd/skywire-cli/skywire-cli.go config gen -ni | go run -tags systray ./cmd/skywire-visor/skywire-visor.go -nb || true

## Run skywire from source, without compiling binaries - requires skywire cloned
run-vpnsrv:
test -d apps && rm -r apps || true
ln -s scripts/_apps apps
chmod +x apps/*
sudo echo "sudo cache"
run-vpnsrv: prepare
go run ./cmd/skywire-cli/skywire-cli.go config gen -in --servevpn | go run ./cmd/skywire-visor/skywire-visor.go -nb || true

## Run skywire from source with test endpoints
run-source-test:
test -d apps && rm -r apps || true
ln -s scripts/_apps apps
chmod +x apps/*
sudo echo "sudo cache"
run-source-test: prepare
go run ./cmd/skywire-cli/skywire-cli.go config gen -nit | go run ./cmd/skywire-visor/skywire-visor.go -nb || true

## Run skywire from source, with vpn server enabled
run-vpnsrv-test:
test -d apps && rm -r apps || true
ln -s scripts/_apps apps
chmod +x apps/*
sudo echo "sudo cache"
run-vpnsrv-test: prepare
go run ./cmd/skywire-cli/skywire-cli.go config gen -nit --servevpn | go run ./cmd/skywire-visor/skywire-visor.go -nb || true

## Run skywire from source, with vpn server enabled
run-systray-test: prepare-systray
go run -tags systray ./cmd/skywire-cli/skywire-cli.go config gen -nit | go run -tags systray ./cmd/skywire-visor/skywire-visor.go -nb || true

## Run skywire from source with dmsghttp config
run-source-dmsghttp:
test -d apps && rm -r apps || true
ln -s scripts/_apps apps
chmod +x apps/*
sudo echo "sudo cache"
run-source-dmsghttp: prepare
go run ./cmd/skywire-cli/skywire-cli.go config gen -din | go run ./cmd/skywire-visor/skywire-visor.go -nb || true

## Run skywire from source with dmsghttp config and vpn server
run-vpnsrv-dmsghttp:
test -d apps && rm -r apps || true
ln -s scripts/_apps apps
chmod +x apps/*
sudo echo "sudo cache"
run-vpnsrv-dmsghttp: prepare
go run ./cmd/skywire-cli/skywire-cli.go config gen -din --servevpn | go run ./cmd/skywire-visor/skywire-visor.go -nb || true

## Run skywire from source with dmsghttp config and test endpoints
run-source-dmsghttp-test:
test -d apps && rm -r apps || true
ln -s scripts/_apps apps
chmod +x apps/*
sudo echo "sudo cache"
run-source-dmsghttp-test: prepare
go run ./cmd/skywire-cli/skywire-cli.go config gen -dint | go run ./cmd/skywire-visor/skywire-visor.go -nb || true

## Run skywire from source with dmsghttp config, vpn server, and test endpoints
run-vpnsrv-dmsghttp-test:
test -d apps && rm -r apps || true
ln -s scripts/_apps apps
chmod +x apps/*
sudo echo "sudo cache"
run-vpnsrv-dmsghttp-test: prepare
go run ./cmd/skywire-cli/skywire-cli.go config gen -dint --servevpn | go run ./cmd/skywire-visor/skywire-visor.go -nb || true

lint-ui: ## Lint the UI code
Expand Down
112 changes: 73 additions & 39 deletions cmd/apps/skychat/chat.go → cmd/apps/skychat/skychat.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"embed"
"encoding/json"
"flag"
"fmt"
"io/fs"
"net"
Expand All @@ -17,8 +16,10 @@ import (
"sync"
"time"

cc "github.com/ivanpirog/coloredcobra"
ipc "github.com/james-barrow/golang-ipc"
"github.com/skycoin/skycoin/src/util/logging"
"github.com/spf13/cobra"

"github.com/skycoin/skywire-utilities/pkg/buildinfo"
"github.com/skycoin/skywire-utilities/pkg/cipher"
Expand All @@ -34,62 +35,95 @@ const (
port = routing.Port(1)
)

var log = logging.MustGetLogger("chat")
var addr = flag.String("addr", ":8001", "address to bind")
var r = netutil.NewRetrier(log, 50*time.Millisecond, netutil.DefaultMaxBackoff, 5, 2)

var (
appC *app.Client
clientCh chan string
conns map[cipher.PubKey]net.Conn // Chat connections
connsMu sync.Mutex
// the go embed static points to skywire/cmd/apps/skychat/static
//go:embed static
embededFiles embed.FS
log = logging.MustGetLogger("chat")
r = netutil.NewRetrier(log, 50*time.Millisecond, netutil.DefaultMaxBackoff, 5, 2)
addr string
appC *app.Client
clientCh chan string
conns map[cipher.PubKey]net.Conn // Chat connections
connsMu sync.Mutex
)

// the go embed static points to skywire/cmd/apps/skychat/static
func init() {
rootCmd.Flags().SortFlags = false
rootCmd.Flags().StringVarP(&addr, "addr", "a", ":8001", "address to bind")
}

//go:embed static
var embededFiles embed.FS
var rootCmd = &cobra.Command{
Use: "skysocks",
Short: "Skywire SOCKS5 Proxy Server",
0pcom marked this conversation as resolved.
Show resolved Hide resolved
Long: `
┌─┐┬┌─┬ ┬┌─┐┬ ┬┌─┐┌┬┐
└─┐├┴┐└┬┘│ ├─┤├─┤ │
└─┘┴ ┴ ┴ └─┘┴ ┴┴ ┴ ┴ `,
Run: func(_ *cobra.Command, _ []string) {
appC = app.NewClient(nil)
defer appC.Close()

if _, err := buildinfo.Get().WriteTo(os.Stdout); err != nil {
fmt.Printf("Failed to output build info: %v", err)
}

func main() {
appC = app.NewClient(nil)
defer appC.Close()
fmt.Print("Successfully started skychat.")
0pcom marked this conversation as resolved.
Show resolved Hide resolved

if _, err := buildinfo.Get().WriteTo(os.Stdout); err != nil {
fmt.Printf("Failed to output build info: %v", err)
}
clientCh = make(chan string)
defer close(clientCh)

flag.Parse()
fmt.Print("Successfully started skychat.")
conns = make(map[cipher.PubKey]net.Conn)
go listenLoop()

clientCh = make(chan string)
defer close(clientCh)
if runtime.GOOS == "windows" {
ipcClient, err := ipc.StartClient(skyenv.SkychatName, nil)
if err != nil {
fmt.Printf("Error creating ipc server for skychat client: %v\n", err)
os.Exit(1)
}
go handleIPCSignal(ipcClient)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

conns = make(map[cipher.PubKey]net.Conn)
go listenLoop()
http.Handle("/", http.FileServer(getFileSystem()))
http.HandleFunc("/message", messageHandler(ctx))
http.HandleFunc("/sse", sseHandler)

if runtime.GOOS == "windows" {
ipcClient, err := ipc.StartClient(skyenv.SkychatName, nil)
fmt.Print("Serving HTTP on", addr)
err := http.ListenAndServe(addr, nil)
if err != nil {
fmt.Printf("Error creating ipc server for skychat client: %v\n", err)
fmt.Println(err)
os.Exit(1)
}
go handleIPCSignal(ipcClient)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

http.Handle("/", http.FileServer(getFileSystem()))
http.HandleFunc("/message", messageHandler(ctx))
http.HandleFunc("/sse", sseHandler)
},
}

fmt.Print("Serving HTTP on", *addr)
err := http.ListenAndServe(*addr, nil)
if err != nil {
// Execute executes root CLI command.
func Execute() {
cc.Init(&cc.Config{
RootCmd: rootCmd,
Headings: cc.HiBlue + cc.Bold,
Commands: cc.HiBlue + cc.Bold,
CmdShortDescr: cc.HiBlue,
Example: cc.HiBlue + cc.Italic,
ExecName: cc.HiBlue + cc.Bold,
Flags: cc.HiBlue + cc.Bold,
FlagsDescr: cc.HiBlue,
NoExtraNewlines: true,
NoBottomNewline: true,
})

if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}

func main() {
Execute()
}

func listenLoop() {
l, err := appC.Listen(netType, port)
if err != nil {
Expand Down
Loading