Skip to content
Open
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
80 changes: 80 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: CI (lints, tests (todo), and builds)

on:
push:
branches: [ main ]
pull_request:
workflow_dispatch:

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
build-lint-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.22
cache-dependency-path: src/go.sum

- name: Verify dependencies
run: go mod verify
working-directory: src

- name: Install dependencies
run: go mod tidy
working-directory: src

- name: Build
run: go build ./...
working-directory: src

- name: Lint code (go vet)
run: go vet ./...
working-directory: src

- name: Run tests
run: go test ./...
working-directory: src

- name: install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest
working-directory: src

- name: Lint code (staticcheck)
run: staticcheck ./...
working-directory: src

check-example-plugins:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.22
cache-dependency-path: src/go.sum

- name: Verify dependencies (for zoraxy)
run: go mod verify
working-directory: src

- name: Install dependencies (for zoraxy)
run: go mod tidy
working-directory: src

- name: Example plugins are up to date and build successfully
run: |
bash build_all.sh && git diff --exit-code # if code fails to build, or if there are code changes, this step will fail
working-directory: example/plugins

# TODO: if possible, it may be good to test whether the plugins correctly
# report their introspection data when run with the -introspect flag.
22 changes: 19 additions & 3 deletions example/plugins/build_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,40 @@ for dir in ./*; do
done


# Initialize error flag
build_failed=0
# Iterate over all directories in the current directory
echo "Running go mod tidy and go build for all directories"
for dir in */; do
if [ -d "$dir" ]; then
echo "Processing directory: $dir"
cd "$dir"

# Execute go mod tidy
echo "Running go mod tidy in $dir"
go mod tidy
if ! go mod tidy; then
echo "ERROR: go mod tidy failed in $dir"
build_failed=1
fi

# Execute go build
echo "Running go build in $dir"
go build
if ! go build; then
echo "ERROR: go build failed in $dir"
build_failed=1
fi

# Return to the parent directory
cd ..
fi
done

echo "Build process completed for all directories."

if [ $build_failed -eq 1 ]; then
echo "One or more builds failed."
exit 1
else
echo "All builds succeeded."
exit 0
fi
8 changes: 4 additions & 4 deletions src/mod/ipscan/ipscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ func ScanIpRange(start, end string) ([]*DiscoveredHost, error) {
ipStart := net.ParseIP(start)
ipEnd := net.ParseIP(end)
if ipStart == nil || ipEnd == nil {
return nil, fmt.Errorf("Invalid IP address")
return nil, fmt.Errorf("invalid IP address")
}

if bytes.Compare(ipStart, ipEnd) > 0 {
return nil, fmt.Errorf("Invalid IP range")
return nil, fmt.Errorf("invalid IP range")
}

var wg sync.WaitGroup
Expand Down Expand Up @@ -108,7 +108,7 @@ func (host *DiscoveredHost) CheckPing() error {
pinger.Run()
stats := pinger.Statistics()
if stats.PacketsRecv == 0 {
return fmt.Errorf("Host unreachable for " + host.IP)
return fmt.Errorf("host unreachable for %s", host.IP)
}
host.Ping = int(stats.AvgRtt.Milliseconds())
return nil
Expand Down Expand Up @@ -136,7 +136,7 @@ func (host *DiscoveredHost) ScanPorts(startPort, endPort int) []int {
var openPorts []int

for port := startPort; port <= endPort; port++ {
target := fmt.Sprintf("%s:%d", host.IP, port)
target := net.JoinHostPort(host.IP, fmt.Sprintf("%d", port))
conn, err := net.DialTimeout("tcp", target, time.Millisecond*500)
if err == nil {
conn.Close()
Expand Down
2 changes: 1 addition & 1 deletion src/mod/ipscan/portscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func ScanPorts(host string) []*OpenedPort {
wg.Add(1)
go func(port int) {
defer wg.Done()
address := fmt.Sprintf("%s:%d", host, port)
address := net.JoinHostPort(host, fmt.Sprintf("%d", port))

// Check TCP
conn, err := net.DialTimeout("tcp", address, 5*time.Second)
Expand Down
16 changes: 8 additions & 8 deletions src/mod/streamproxy/streamproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ type ProxyRelayInstance struct {
Timeout int //Timeout for connection in sec

/* Internal */
tcpStopChan chan bool //Stop channel for TCP listener
udpStopChan chan bool //Stop channel for UDP listener
aTobAccumulatedByteTransfer atomic.Int64 //Accumulated byte transfer from A to B
bToaAccumulatedByteTransfer atomic.Int64 //Accumulated byte transfer from B to A
udpClientMap sync.Map //map storing the UDP client-server connections
parent *Manager `json:"-"`
tcpStopChan chan bool //Stop channel for TCP listener
udpStopChan chan bool //Stop channel for UDP listener
aTobAccumulatedByteTransfer *atomic.Int64 //Accumulated byte transfer from A to B
bToaAccumulatedByteTransfer *atomic.Int64 //Accumulated byte transfer from B to A
udpClientMap sync.Map //map storing the UDP client-server connections
parent *Manager `json:"-"`
}

type Options struct {
Expand Down Expand Up @@ -183,8 +183,8 @@ func (m *Manager) NewConfig(config *ProxyRelayOptions) string {
Timeout: config.Timeout,
tcpStopChan: nil,
udpStopChan: nil,
aTobAccumulatedByteTransfer: aAcc,
bToaAccumulatedByteTransfer: bAcc,
aTobAccumulatedByteTransfer: &aAcc,
bToaAccumulatedByteTransfer: &bAcc,
udpClientMap: sync.Map{},
parent: m,
}
Expand Down
2 changes: 1 addition & 1 deletion src/mod/streamproxy/tcpprox.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (c *ProxyRelayInstance) Port2host(allowPort string, targetAddress string, s
}
}

c.forward(target, conn, &c.aTobAccumulatedByteTransfer, &c.bToaAccumulatedByteTransfer)
c.forward(target, conn, c.aTobAccumulatedByteTransfer, c.bToaAccumulatedByteTransfer)
}(targetAddress)
}
}
17 changes: 13 additions & 4 deletions src/mod/websocketproxy/websocketproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,18 @@ func TestProxy(t *testing.T) {

mux := http.NewServeMux()
mux.Handle("/proxy", proxy)
errChan := make(chan error)
go func() {
if err := http.ListenAndServe(":7777", mux); err != nil {
t.Fatal("ListenAndServe: ", err)
errChan <- err
}
}()

time.Sleep(time.Millisecond * 100)
select {
case err := <-errChan:
t.Fatal("ListenAndServe: ", err)
case <-time.After(time.Millisecond * 100):
}

// backend echo server
go func() {
Expand Down Expand Up @@ -73,11 +78,15 @@ func TestProxy(t *testing.T) {

err := http.ListenAndServe(":8888", mux2)
if err != nil {
t.Fatal("ListenAndServe: ", err)
errChan <- err
}
}()

time.Sleep(time.Millisecond * 100)
select {
case err := <-errChan:
t.Fatal("ListenAndServe: ", err)
case <-time.After(time.Millisecond * 100):
}

// let's us define two subprotocols, only one is supported by the server
clientSubProtocols := []string{"test-protocol", "test-notsupported"}
Expand Down
Loading