self-defined profiling server address

This commit is contained in:
ginuerzh 2019-11-28 21:21:34 +08:00
parent 2d10654be2
commit 1caabf84ad
5 changed files with 17 additions and 13 deletions

1
.gitignore vendored
View File

@ -8,6 +8,7 @@ _obj
_test
release
debian
bin
# Architecture specific extensions/prefixes
*.[568vq]

View File

@ -18,6 +18,8 @@ import (
var (
configureFile string
baseCfg = &baseConfig{}
pprofAddr string
pprofEnabled = os.Getenv("PROFILING") != ""
)
func init() {
@ -28,10 +30,13 @@ func init() {
)
flag.Var(&baseCfg.route.ChainNodes, "F", "forward address, can make a forward chain")
flag.Var(&baseCfg.route.ServeNodes, "L", "listen address, can listen on multiple ports")
flag.Var(&baseCfg.route.ServeNodes, "L", "listen address, can listen on multiple ports (required)")
flag.StringVar(&configureFile, "C", "", "configure file")
flag.BoolVar(&baseCfg.Debug, "D", false, "enable debug log")
flag.BoolVar(&printVersion, "V", false, "print version")
if pprofEnabled {
flag.StringVar(&pprofAddr, "P", ":6060", "profiling HTTP server address")
}
flag.Parse()
if printVersion {
@ -54,9 +59,10 @@ func init() {
}
func main() {
if os.Getenv("PROFILING") != "" {
if pprofEnabled {
go func() {
log.Log(http.ListenAndServe("127.0.0.1:16060", nil))
log.Log("profiling server on", pprofAddr)
log.Log(http.ListenAndServe(pprofAddr, nil))
}()
}
@ -72,7 +78,10 @@ func main() {
tlsConfig = &tls.Config{
Certificates: []tls.Certificate{cert},
}
} else {
log.Log("load TLS certificate files OK")
}
gost.DefaultTLSConfig = tlsConfig
if err := start(); err != nil {

2
go.mod
View File

@ -1,5 +1,7 @@
module github.com/ginuerzh/gost
go 1.13
require (
git.torproject.org/pluggable-transports/goptlib.git v0.0.0-20180321061416-7d56ec4f381e
git.torproject.org/pluggable-transports/obfs4.git v0.0.0-20181103133120-08f4d470188e

View File

@ -20,7 +20,7 @@ import (
)
// Version is the gost version.
const Version = "2.8.1"
const Version = "2.8.2-dev"
// Debug is a flag that enables the debug log.
var Debug bool
@ -76,7 +76,7 @@ var (
DefaultTLSConfig *tls.Config
// DefaultUserAgent is the default HTTP User-Agent header used by HTTP and websocket.
DefaultUserAgent = "Chrome/60.0.3112.90"
DefaultUserAgent = "Chrome/78.0.3904.106"
)
// SetLogger sets a new logger for internal log system.

8
ss.go
View File

@ -525,19 +525,11 @@ func (h *shadowUDPdHandler) transportUDP(sc net.Conn, cc net.PacketConn) error {
// Due to in/out byte length is inconsistent of the shadowsocks.Conn.Write,
// we wrap around it to make io.Copy happy.
type shadowConn struct {
wbuf bytes.Buffer
net.Conn
}
func (c *shadowConn) Write(b []byte) (n int, err error) {
n = len(b) // force byte length consistent
if c.wbuf.Len() > 0 {
c.wbuf.Write(b) // append the data to the cached header
_, err = c.Conn.Write(c.wbuf.Bytes())
c.wbuf.Reset()
return
}
_, err = c.Conn.Write(b)
return
}