Skip to content

Commit 4b8e336

Browse files
authored
Merge pull request #10 from Jigsaw-Code/fortuna-cgo
Disable CGO
2 parents 600da79 + e820258 commit 4b8e336

File tree

3 files changed

+98
-7
lines changed

3 files changed

+98
-7
lines changed

.goreleaser.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
project_name: outline-ss-server
16+
1517
# Build for macOS, Linux, and Windows.
1618
# Skip 32 bit macOS builds.
1719
builds:
1820
-
21+
env:
22+
- CGO_ENABLED=0
1923
goos:
20-
# Disable macOS while the build is broken: https://github.com/golang/go/issues/29170
21-
# - darwin
24+
- darwin
2225
- windows
2326
- linux
2427
ignore:

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,25 @@ Run the iperf3 client tests listed above on port 10002.
107107

108108
You can mix and match the libev and go servers and clients.
109109

110+
## Benchmark
111+
112+
You can benchmark the cipher finding code with
113+
```
114+
go test -cpuprofile cpu.prof -memprofile mem.prof -bench . -benchmem -run=^$ github.com/Jigsaw-Code/outline-ss-server/shadowsocks
115+
```
116+
117+
You can inspect the CPU or memory profiles with `go tool pprof cpu.prof` or `go tool pprof mem.prof`, and then enter `web` on the prompt.
110118

111119
## Release
112120

113121
We use [GoReleaser](https://goreleaser.com/) to build and upload binaries to our [GitHub releases](https://github.com/Jigsaw-Code/outline-ss-server/releases).
114122

115123
Summary:
116124
- [Install GoReleaser](https://goreleaser.com/install/).
125+
- Test the build locally:
126+
```
127+
goreleaser --rm-dist --snapshot
128+
```
117129
- Export an environment variable named `GITHUB_TOKEN` with a repo-scoped GitHub token ([create one here](https://github.com/settings/tokens/new)):
118130
```bash
119131
export GITHUB_TOKEN=yournewtoken
@@ -128,9 +140,4 @@ Summary:
128140
goreleaser
129141
```
130142

131-
To test locally without tagging/uploading , use `--skip-publish`:
132-
```bash
133-
goreleaser --skip-publish
134-
```
135-
136143
Full instructions in [GoReleaser's Quick Start](https://goreleaser.com/quick-start) (jump to the section starting "You’ll need to export a GITHUB_TOKEN environment variable").

shadowsocks/cipher_cache.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright 2018 Jigsaw Operations LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package shadowsocks
16+
17+
import (
18+
"container/list"
19+
"time"
20+
)
21+
22+
type CipherCache struct {
23+
ipCiphers map[string]*list.List
24+
}
25+
26+
type CachedItem struct {
27+
itemsList *list.List
28+
element *list.Element
29+
}
30+
31+
func (c *CipherCache) GetCiphers(ip string) []*CachedItem {
32+
cipherList, ok := c.ipCiphers[ip]
33+
if !ok {
34+
return []*CachedItem{}
35+
}
36+
items := make([]*CachedItem, cipherList.Len())
37+
pos := 0
38+
for el := cipherList.Front(); el != nil; el = el.Next() {
39+
items[pos] = &CachedItem{cipherList, el}
40+
}
41+
return items
42+
}
43+
44+
type cipherTime struct {
45+
CipherID string
46+
Timestamp time.Time
47+
}
48+
49+
// WARNING
50+
// TODO: All of this needs a MUTEX!!!!!!!
51+
// WARNING
52+
func (cc *CipherCache) AddCipher(ip string, cipherId string) {
53+
cipherList, ok := cc.ipCiphers[ip]
54+
if !ok {
55+
cipherList = list.New()
56+
cc.ipCiphers[ip] = cipherList
57+
}
58+
cipherList.PushFront(cipherTime{CipherID: cipherId, Timestamp: time.Now()})
59+
}
60+
61+
func (cc *CipherCache) ExpireOlderThan(oldestTime time.Time) {
62+
for key, itemList := range cc.ipCiphers {
63+
// Remove expired items
64+
for item := itemList.Back(); item != nil && item.Value.(*cipherTime).Timestamp.Sub(oldestTime) < 0; item = itemList.Back() {
65+
itemList.Remove(item)
66+
}
67+
if itemList.Len() == 0 {
68+
// TODO: Make this not break the loop
69+
delete(cc.ipCiphers, key)
70+
}
71+
}
72+
}
73+
74+
func (ci *CachedItem) Refresh() {
75+
ci.element.Value.(*cipherTime).Timestamp = time.Now()
76+
ci.itemsList.MoveToFront(ci.element)
77+
}
78+
79+
func (ci *CachedItem) CipherId() string {
80+
return ci.element.Value.(*cipherTime).CipherID
81+
}

0 commit comments

Comments
 (0)