Skip to content

Commit

Permalink
Big Feature (#14)
Browse files Browse the repository at this point in the history
* support both http chunked and pull

* fix http: multiple response.WriteHeader calls

* fix github path

* [skip ci] add test

* add more test

* [skip ci] add http version header
  • Loading branch information
ls0f authored Aug 3, 2017
1 parent 3126d2d commit b41ad74
Show file tree
Hide file tree
Showing 16 changed files with 353 additions and 328 deletions.
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


MODULES := proxy logger
BIN := server local
BIN := cmd/server cmd/local

GITTAG := `git describe --tags`
VERSION := `git describe --abbrev=0 --tags`
Expand All @@ -12,7 +12,7 @@ LDFLAGS := -ldflags "-X main.GitTag=${GITTAG} -X main.BuildTime=${BUILD_TIME}"

vendor:
go get ./...
go get github.com/stretchr/testify
go get github.com/stretchr/testify/assert


test:
Expand All @@ -30,7 +30,7 @@ build:
mkdir -p bin;\
echo ==================================; \
for m in $(BIN); do \
cd $(PWD)/$$m && go build ${LDFLAGS} -o ../bin/$$m --race ; \
cd $(PWD)/$$m && go build ${LDFLAGS} -o ../../bin/$$m --race ; \
done
echo ==================================; \
cd $(PWD) && cp gen_key_cert.sh ./bin
Expand All @@ -39,7 +39,7 @@ install: vendor build

deploy:
for m in $(BIN); do \
cd $(PWD)/$$m && gox ${LDFLAGS} -osarch="linux/amd64" -output ../dist/{{.OS}}_{{.Arch}}_{{.Dir}};\
cd $(PWD)/$$m && gox ${LDFLAGS} -os="windows" -output ../dist/{{.OS}}_{{.Arch}}_{{.Dir}};\
cd $(PWD)/$$m && gox ${LDFLAGS} -osarch="darwin/amd64" -output ../dist/{{.OS}}_{{.Arch}}_{{.Dir}};\
cd $(PWD)/$$m && gox ${LDFLAGS} -osarch="linux/amd64" -output ../../dist/{{.OS}}_{{.Arch}}_{{.Dir}};\
cd $(PWD)/$$m && gox ${LDFLAGS} -os="windows" -output ../../dist/{{.OS}}_{{.Arch}}_{{.Dir}};\
cd $(PWD)/$$m && gox ${LDFLAGS} -osarch="darwin/amd64" -output ../../dist/{{.OS}}_{{.Arch}}_{{.Dir}};\
done
26 changes: 13 additions & 13 deletions local/main.go → cmd/local/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,21 @@ import (
"fmt"
"os"

. "github.com/lovedboy/cracker/cracker/local_server"
"github.com/lovedboy/cracker/cracker/logger"
"github.com/lovedboy/cracker/cracker/proxy"
"github.com/ls0f/cracker"
p "github.com/ls0f/proxylib"
)

var (
GitTag = "2000.01.01.release"
BuildTime = "2000-01-01T00:00:00+0800"
)

var g = logger.GetLogger()

func main() {
addr := flag.String("addr", "127.0.0.1:1080", "listen addr")
raddr := flag.String("raddr", "", "remote http url(e.g, https://example.com)")
secret := flag.String("secret", "", "secret key")
debug := flag.Bool("debug", false, "debug mode")
version := flag.Bool("v", false, "version")
version := flag.Bool("version", false, "version")
interval := flag.Duration("interval", 0, "interval of pulling, 0 means use http chunked")
cert := flag.String("cert", "", "cert file")
flag.Parse()

Expand All @@ -31,13 +28,16 @@ func main() {
fmt.Printf("BuildTime: %s \n", BuildTime)
os.Exit(0)
}
logger.InitLogger(*debug)
if *cert != "" {
proxy.Init(*cert)
cracker.Init(*cert)
}
s, err := NewLocalProxyServer(*addr, *raddr, *secret)
if err != nil {
g.Fatal(err)
s := p.Server{Addr: *addr}
handler := &cracker.Handler{
Server: *raddr,
Secret: *secret,
Interval: *interval,
}
s.Wait()
s.HTTPHandler = handler
s.Socks5Handler = handler
s.ListenAndServe()
}
12 changes: 4 additions & 8 deletions server/main.go → cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,30 @@ import (
"fmt"
"os"

"github.com/lovedboy/cracker/cracker/logger"
"github.com/lovedboy/cracker/cracker/proxy"
g "github.com/golang/glog"
"github.com/ls0f/cracker"
)

var (
GitTag = "2000.01.01.release"
BuildTime = "2000-01-01T00:00:00+0800"
)

var g = logger.GetLogger()

func main() {

addr := flag.String("addr", "", "listen addr")
secret := flag.String("secret", "", "secret")
debug := flag.Bool("debug", false, "debug mode")
version := flag.Bool("v", false, "version")
version := flag.Bool("version", false, "version")
https := flag.Bool("https", false, "https")
cert := flag.String("cert", "", "cert file")
key := flag.String("key", "", "private key file")
flag.Parse()
logger.InitLogger(*debug)
if *version {
fmt.Printf("GitTag: %s \n", GitTag)
fmt.Printf("BuildTime: %s \n", BuildTime)
os.Exit(0)
}
p := proxy.NewHttpProxy(*addr, *secret, *https)
p := cracker.NewHttpProxy(*addr, *secret, *https)
if *https {
f, err := os.Stat(*cert)
if err != nil {
Expand Down
63 changes: 0 additions & 63 deletions cracker/http_connect/http.go

This file was deleted.

67 changes: 0 additions & 67 deletions cracker/local_server/local_proxy.go

This file was deleted.

27 changes: 0 additions & 27 deletions cracker/logger/logger.go

This file was deleted.

56 changes: 0 additions & 56 deletions cracker/socks/socks5.go

This file was deleted.

38 changes: 38 additions & 0 deletions handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cracker

import (
"io"
"strings"
"time"
)

type Handler struct {
Server string
Secret string
Interval time.Duration
}

func (h *Handler) Connect(addr string) (io.ReadWriteCloser, error) {
if strings.HasSuffix(h.Server, "/") {
h.Server = h.Server[:len(h.Server)-1]
}
conn := &localProxyConn{server: h.Server, secret: h.Secret, interval: h.Interval}
host := strings.Split(addr, ":")[0]
port := strings.Split(addr, ":")[1]
uuid, err := conn.connect(host, port)
if err != nil {
return nil, err
}
conn.uuid = uuid
if h.Interval == 0 {
err = conn.pull()
if err != nil {
return nil, err
}
}
conn.close = make(chan bool)
go conn.alive()
return conn, nil
}

func (h *Handler) Clean() {}
2 changes: 1 addition & 1 deletion cracker/proxy/hmac.go → hmac.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proxy
package cracker

import (
"crypto/hmac"
Expand Down
2 changes: 1 addition & 1 deletion cracker/proxy/hmac_test.go → hmac_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proxy
package cracker

import (
"testing"
Expand Down
Loading

0 comments on commit b41ad74

Please sign in to comment.