mirror of
https://github.com/yggdrasil-network/yggstack.git
synced 2025-04-28 14:15:07 +03:00
Merge 6c55383019
into 83bc9a2eec
This commit is contained in:
commit
9ebdad5b83
4 changed files with 57 additions and 12 deletions
13
build
13
build
|
@ -8,8 +8,9 @@ PKGVER=${PKGVER:-$(sh contrib/semver/version.sh --bare)}
|
|||
|
||||
LDFLAGS="-X $PKGSRC.buildName=$PKGNAME -X $PKGSRC.buildVersion=$PKGVER"
|
||||
ARGS="-v"
|
||||
DLL=false
|
||||
|
||||
while getopts "utc:l:dro:ps" option
|
||||
while getopts "utc:l:dro:psk" option
|
||||
do
|
||||
case "$option"
|
||||
in
|
||||
|
@ -22,6 +23,7 @@ do
|
|||
o) ARGS="$ARGS -o $OPTARG";;
|
||||
p) ARGS="$ARGS -buildmode=pie";;
|
||||
s) ARGS="$ARGS -tags netgo,osusersgo,static" LDFLAGS="$LDFLAGS -extldflags '-static'" CGO_ENABLED=0;;
|
||||
k) DLL=true;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
@ -29,11 +31,16 @@ if [ -z $TABLES ] && [ -z $DEBUG ]; then
|
|||
LDFLAGS="$LDFLAGS -s -w"
|
||||
fi
|
||||
|
||||
for CMD in yggstack ; do
|
||||
if [ "$DLL" = true ]; then
|
||||
echo "Building: shared library"
|
||||
CGO_ENABLED=1 go build $ARGS -buildmode=c-shared -ldflags="$LDFLAGS" -gcflags="$GCFLAGS" -o yggstack ./pkg/yggstack
|
||||
else
|
||||
for CMD in yggstack ; do
|
||||
echo "Building: $CMD"
|
||||
go build $ARGS -ldflags="$LDFLAGS" -gcflags="$GCFLAGS" ./cmd/$CMD
|
||||
|
||||
if [ $UPX ]; then
|
||||
upx --brute $CMD
|
||||
fi
|
||||
done
|
||||
done
|
||||
fi
|
||||
|
|
11
cmd/yggstack/program.go
Normal file
11
cmd/yggstack/program.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/yggdrasil-network/yggstack/src/driver"
|
||||
)
|
||||
|
||||
func main() {
|
||||
driver.Run(os.Args[1:])
|
||||
}
|
28
pkg/yggstack/lib.go
Normal file
28
pkg/yggstack/lib.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
//go:build cgo
|
||||
// +build cgo
|
||||
|
||||
package main
|
||||
|
||||
/*
|
||||
#include <stdlib.h>
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/yggdrasil-network/yggstack/src/driver"
|
||||
)
|
||||
|
||||
func main() {}
|
||||
|
||||
//export YggstackMain
|
||||
func YggstackMain(argc C.int, argv **C.char) {
|
||||
length := int(argc)
|
||||
args := make([]string, length)
|
||||
argvPtr := unsafe.Pointer(argv)
|
||||
for i := 0; i < length; i++ {
|
||||
arg := *(**C.char)(unsafe.Add(argvPtr, uintptr(i)*unsafe.Sizeof((*C.char)(nil))))
|
||||
args[i] = C.GoString(arg)
|
||||
}
|
||||
driver.Run(args)
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package driver
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -47,8 +47,7 @@ type UDPSession struct {
|
|||
remoteAddr net.Addr
|
||||
}
|
||||
|
||||
// The main function is responsible for configuring and starting Yggdrasil.
|
||||
func main() {
|
||||
func Run(args []string) {
|
||||
var localtcp types.TCPLocalMappings
|
||||
var localudp types.UDPLocalMappings
|
||||
var remotetcp types.TCPRemoteMappings
|
||||
|
@ -72,7 +71,7 @@ func main() {
|
|||
flag.Var(&localudp, "local-udp", "UDP ports to forward to the remote Yggdrasil node, e.g. 22:[a:b:c:d]:2022, 127.0.0.1:[a:b:c:d]:22")
|
||||
flag.Var(&remotetcp, "remote-tcp", "TCP ports to expose to the network, e.g. 22, 2022:22, 22:192.168.1.1:2022")
|
||||
flag.Var(&remoteudp, "remote-udp", "UDP ports to expose to the network, e.g. 22, 2022:22, 22:192.168.1.1:2022")
|
||||
flag.Parse()
|
||||
flag.CommandLine.Parse(args)
|
||||
|
||||
// Catch interrupts from the operating system to exit gracefully.
|
||||
ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
Loading…
Add table
Add a link
Reference in a new issue