Skip to content

Commit

Permalink
Merge pull request shadowsocks#266 from abeluck/master
Browse files Browse the repository at this point in the history
Add server option to disable logging of client ips
  • Loading branch information
arthurkiller authored Mar 26, 2018
2 parents f0101aa + fa26b00 commit 924943c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions cmd/shadowsocks-server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const (
)

var debug ss.DebugLog
var sanitizeIps bool
var udp bool
var managerAddr string

Expand Down Expand Up @@ -111,6 +112,14 @@ const logCntDelta = 100
var connCnt int
var nextLogConnCnt int = logCntDelta

func sanitizeAddr(addr net.Addr) string {
if sanitizeIps {
return "x.x.x.x:zzzz"
} else {
return addr.String()
}
}

func handleConnection(conn *ss.Conn, auth bool, port string) {
var host string

Expand All @@ -126,12 +135,12 @@ func handleConnection(conn *ss.Conn, auth bool, port string) {
// function arguments are always evaluated, so surround debug statement
// with if statement
if debug {
debug.Printf("new client %s->%s\n", conn.RemoteAddr().String(), conn.LocalAddr())
debug.Printf("new client %s->%s\n", sanitizeAddr(conn.RemoteAddr()), conn.LocalAddr())
}
closed := false
defer func() {
if debug {
debug.Printf("closed pipe %s<->%s\n", conn.RemoteAddr(), host)
debug.Printf("closed pipe %s<->%s\n", sanitizeAddr(conn.RemoteAddr()), host)
}
connCnt--
if !closed {
Expand All @@ -141,7 +150,7 @@ func handleConnection(conn *ss.Conn, auth bool, port string) {

host, ota, err := getRequest(conn, auth)
if err != nil {
log.Println("error getting request", conn.RemoteAddr(), conn.LocalAddr(), err)
log.Println("error getting request", sanitizeAddr(conn.RemoteAddr()), conn.LocalAddr(), err)
closed = true
return
}
Expand Down Expand Up @@ -169,7 +178,7 @@ func handleConnection(conn *ss.Conn, auth bool, port string) {
}
}()
if debug {
debug.Printf("piping %s<->%s ota=%v connOta=%v", conn.RemoteAddr(), host, ota, conn.IsOta())
debug.Printf("piping %s<->%s ota=%v connOta=%v", sanitizeAddr(conn.RemoteAddr()), host, ota, conn.IsOta())
}
if ota {
go func() {
Expand Down Expand Up @@ -453,6 +462,7 @@ func main() {
flag.StringVar(&cmdConfig.Method, "m", "", "encryption method, default: aes-256-cfb")
flag.IntVar(&core, "core", 0, "maximum number of CPU cores to use, default is determinied by Go runtime")
flag.BoolVar((*bool)(&debug), "d", false, "print debug message")
flag.BoolVar((*bool)(&sanitizeIps), "A", false, "anonymize client ip addresses in all output")
flag.BoolVar(&udp, "u", false, "UDP Relay")
flag.StringVar(&managerAddr, "manager-address", "", "shadowsocks manager listening address")
flag.Parse()
Expand Down

0 comments on commit 924943c

Please sign in to comment.