Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

Koggle patch 1 #439

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
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
37 changes: 33 additions & 4 deletions cmd/shadowsocks-local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,19 @@ func handleConnection(conn net.Conn) {
debug.Println("send connection confirmation:", err)
return
}


//need some data for wirte
buf := make([]byte, 4096)
copy(buf, rawaddr)
ss.SetReadTimeout(conn)
if n, err = conn.Read(buf[len(rawaddr):cap(buf)]); err != nil {
return
}
rawaddr = buf[: n+len(rawaddr)]
remote, err := createServerConn(rawaddr, addr)
buf = nil
rawaddr = nil

if err != nil {
if len(servers.srvCipher) > 1 {
log.Println("Failed connect to all available shadowsocks server")
Expand All @@ -322,11 +333,12 @@ func handleConnection(conn net.Conn) {
remote.Close()
}
}()


remote.Flags = 1
go ss.PipeThenClose(conn, remote, nil)
ss.PipeThenClose(remote, conn, nil)
closed = true
debug.Println("closed connection to", addr)
//debug.Println("closed connection to", addr)
}

func run(listenAddr string) {
Expand Down Expand Up @@ -401,9 +413,26 @@ func parseURI(u string, cfg *ss.Config) (string, error) {

}

func logoForWindows() {
var count uint64 = 0
cur := 0
for {
if ss.RecvCount != 0 {
cur = ss.RecvCount
ss.RecvCount = 0
count += uint64(cur)
fmt.Printf("\n当前流量:%d ,%d", cur, count/1024/1024)
}
time.Sleep(time.Second * 5)
}
}

func main() {
log.SetOutput(os.Stdout)

//for windows view
if os.DevNull == "NUL" {
go logoForWindows()
}
var configFile, cmdServer, cmdURI string
var cmdConfig ss.Config
var printVer bool
Expand Down
6 changes: 6 additions & 0 deletions shadowsocks/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ const (
AddrMask byte = 0xf
)

var RecvCount int = 0

type Conn struct {
net.Conn
*Cipher
readBuf []byte
writeBuf []byte
Flags int
}

func NewConn(c net.Conn, cipher *Cipher) *Conn {
Expand Down Expand Up @@ -114,6 +117,9 @@ func (c *Conn) Read(b []byte) (n int, err error) {
n, err = c.Conn.Read(cipherData)
if n > 0 {
c.decrypt(b[0:n], cipherData[0:n])
if (c.Flags & 1) != 0 {
RecvCount += n
}
}
return
}
Expand Down