Skip to content

Commit 2f04edc

Browse files
authored
refactor: move outline-ss-server to cmd/ and hide code (#136)
- Moves the binary to the standard `cmd` directory, and paves the way for having more binaries. - Hides internal code to prevent external dependencies.
1 parent 4881f8b commit 2f04edc

File tree

16 files changed

+31
-29
lines changed

16 files changed

+31
-29
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@
2121

2222
# Git submodules
2323
/third_party/maxmind/
24+
25+
# Prometheus
26+
/data/

.goreleaser.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ project_name: outline-ss-server
1818
# Skip 32 bit macOS builds.
1919
builds:
2020
-
21+
main: ./cmd/outline-ss-server/main.go
2122
env:
2223
- CGO_ENABLED=0
2324
goos:

Makefile

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
BUILDDIR=$(CURDIR)/dist
2-
GOBIN=$(CURDIR)/bin
3-
GORELEASER=$(GOBIN)/goreleaser
2+
GORELEASER=go run github.com/goreleaser/goreleaser
43

54
.PHONY: release release-local test clean clean-all
65

76
# This requires GITHUB_TOKEN to be set.
8-
release: clean-all $(GORELEASER)
7+
release: clean-all
98
$(GORELEASER)
109

11-
release-local: $(GORELEASER)
10+
release-local:
1211
$(GORELEASER) --rm-dist --snapshot
1312

1413
test: third_party/maxmind/test-data/GeoIP2-Country-Test.mmdb
@@ -17,9 +16,6 @@ test: third_party/maxmind/test-data/GeoIP2-Country-Test.mmdb
1716
third_party/maxmind/test-data/GeoIP2-Country-Test.mmdb:
1817
git submodule update --init
1918

20-
$(GORELEASER): go.mod
21-
env GOBIN=$(GOBIN) go install github.com/goreleaser/goreleaser
22-
2319
go.mod: tools.go
2420
go mod tidy
2521
touch go.mod
@@ -30,4 +26,3 @@ clean:
3026

3127
clean-all: clean
3228
rm -rf $(CURDIR)/third_party/maxmind/*
33-
rm -rf $(GOBIN)

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Outline ss-server
22

33
![Build Status](https://github.com/Jigsaw-Code/outline-ss-server/actions/workflows/go.yml/badge.svg)
4+
[![Go Report Card](https://goreportcard.com/badge/github.com/Jigsaw-Code/outline-ss-server)](https://goreportcard.com/report/github.com/Jigsaw-Code/outline-ss-server)
5+
[![Go Reference](https://pkg.go.dev/badge/github.com/Jigsaw-Code/outline-ss-server.svg)](https://pkg.go.dev/github.com/Jigsaw-Code/outline-ss-server)
6+
47
[![Mattermost](https://badgen.net/badge/Mattermost/Outline%20Community/blue)](https://community.internetfreedomfestival.org/community/channels/outline-community)
58
[![Reddit](https://badgen.net/badge/Reddit/r%2Foutlinevpn/orange)](https://www.reddit.com/r/outlinevpn/)
69

@@ -22,29 +25,29 @@ The Outline Shadowsocks service allows for:
2225

2326
Fetch dependencies for this demo:
2427
```
25-
GO111MODULE=off go get github.com/shadowsocks/go-shadowsocks2 github.com/prometheus/prometheus/cmd/...
28+
GO111MODULE=off go get github.com/prometheus/prometheus/cmd/...
2629
```
27-
If that doesn't work, download the [prometheus](https://prometheus.io/download/) or [go-shadowsocks2](https://github.com/shadowsocks/go-shadowsocks2/releases) binaries directly.
30+
If that doesn't work, download the [prometheus](https://prometheus.io/download/) binary directly.
2831

2932

3033
### Run the server
3134
On Terminal 1, from the repository directory, build and start the SS server:
3235
```
33-
go run . -config config_example.yml -metrics localhost:9091 --replay_history=10000
36+
go run ./cmd/outline-ss-server -config cmd/outline-ss-server/config_example.yml -metrics localhost:9091 --replay_history=10000
3437
```
3538
In production, you may want to specify `-ip_country_db` to get per-country metrics. See [how the Outline Server calls outline-ss-server](https://github.com/Jigsaw-Code/outline-server/blob/master/src/shadowbox/server/outline_shadowsocks_server.ts).
3639

3740

3841
### Run the Prometheus scraper for metrics collection
3942
On Terminal 2, start prometheus scraper for metrics collection:
4043
```
41-
$(go env GOPATH)/bin/prometheus --config.file=prometheus_example.yml
44+
$(go env GOPATH)/bin/prometheus --config.file=cmd/outline-ss-server/prometheus_example.yml
4245
```
4346

4447
### Run the SOCKS-to-Shadowsocks client
4548
On Terminal 3, start the SS client:
4649
```
47-
$(go env GOPATH)/bin/go-shadowsocks2 -c ss://chacha20-ietf-poly1305:Secret0@:9000 -verbose -socks localhost:1080
50+
go run github.com/shadowsocks/go-shadowsocks2 -c ss://chacha20-ietf-poly1305:Secret0@:9000 -verbose -socks localhost:1080
4851
```
4952

5053
### Fetch a page over Shadowsocks
@@ -70,12 +73,12 @@ iperf3 -s
7073

7174
Start the SS server (listening on port 9000):
7275
```
73-
go run . -config config_example.yml
76+
go run ./cmd/outline-ss-server -config cmd/outline-ss-server/config_example.yml
7477
```
7578

7679
Start the SS tunnel to redirect port 8000 -> localhost:5201 via the proxy on 9000:
7780
```
78-
$(go env GOPATH)/bin/go-shadowsocks2 -c ss://chacha20-ietf-poly1305:Secret0@:9000 -tcptun ":8000=localhost:5201" -udptun ":8000=localhost:5201" -verbose
81+
go run github.com/shadowsocks/go-shadowsocks2 -c ss://chacha20-ietf-poly1305:Secret0@:9000 -tcptun ":8000=localhost:5201" -udptun ":8000=localhost:5201" -verbose
7982
```
8083

8184
Test TCP upload (client -> server):
@@ -102,7 +105,7 @@ iperf3 -c localhost -p 8000 --udp -b 0 --reverse
102105

103106
Run the commands above, but start the SS server with
104107
```
105-
$(go env GOPATH)/bin/go-shadowsocks2 -s ss://chacha20-ietf-poly1305:Secret0@:9000 -verbose
108+
go run github.com/shadowsocks/go-shadowsocks2 -s ss://chacha20-ietf-poly1305:Secret0@:9000 -verbose
106109
```
107110

108111

client/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66
"net"
77
"time"
88

9+
"github.com/Jigsaw-Code/outline-ss-server/internal/slicepool"
910
onet "github.com/Jigsaw-Code/outline-ss-server/net"
1011
ss "github.com/Jigsaw-Code/outline-ss-server/shadowsocks"
11-
"github.com/Jigsaw-Code/outline-ss-server/slicepool"
1212
"github.com/shadowsocks/go-shadowsocks2/socks"
1313
)
1414

@@ -156,7 +156,7 @@ func (c *packetConn) ReadFrom(b []byte) (int, net.Addr, error) {
156156
if socksSrcAddr == nil {
157157
return 0, nil, errors.New("Failed to read source address")
158158
}
159-
srcAddr := NewAddr(socksSrcAddr.String(), "udp")
159+
srcAddr := newAddr(socksSrcAddr.String(), "udp")
160160
n = copy(b, buf[len(socksSrcAddr):]) // Strip the SOCKS source address
161161
if len(b) < len(buf)-len(socksSrcAddr) {
162162
return n, srcAddr, io.ErrShortBuffer
@@ -177,8 +177,8 @@ func (a *addr) Network() string {
177177
return a.network
178178
}
179179

180-
// NewAddr returns a net.Addr that holds an address of the form `host:port` with a domain name or IP as host.
180+
// newAddr returns a net.Addr that holds an address of the form `host:port` with a domain name or IP as host.
181181
// Used for SOCKS addressing.
182-
func NewAddr(address, network string) net.Addr {
182+
func newAddr(address, network string) net.Addr {
183183
return &addr{address: address, network: network}
184184
}

client/client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func TestShadowsocksClient_ListenUDP(t *testing.T) {
176176
}
177177
defer conn.Close()
178178
conn.SetReadDeadline(time.Now().Add(time.Second * 5))
179-
pcrw := &packetConnReadWriter{PacketConn: conn, targetAddr: NewAddr(testTargetAddr, "udp")}
179+
pcrw := &packetConnReadWriter{PacketConn: conn, targetAddr: newAddr(testTargetAddr, "udp")}
180180
expectEchoPayload(pcrw, ss.MakeTestPayload(1024), make([]byte, 1024), t)
181181

182182
proxy.Close()
@@ -236,7 +236,7 @@ func BenchmarkShadowsocksClient_ListenUDP(b *testing.B) {
236236
buf := make([]byte, clientUDPBufferSize)
237237
for n := 0; n < b.N; n++ {
238238
payload := ss.MakeTestPayload(1024)
239-
pcrw := &packetConnReadWriter{PacketConn: conn, targetAddr: NewAddr(testTargetAddr, "udp")}
239+
pcrw := &packetConnReadWriter{PacketConn: conn, targetAddr: newAddr(testTargetAddr, "udp")}
240240
b.StartTimer()
241241
expectEchoPayload(pcrw, payload, buf, b)
242242
b.StopTimer()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)