Skip to content

Commit

Permalink
Update flags
Browse files Browse the repository at this point in the history
  • Loading branch information
coyove committed Sep 3, 2019
1 parent de4bfe0 commit 8d439de
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -318,3 +318,6 @@ __pycache__/
# OpenCover UI analysis results
OpenCover/
heap.txt
*.keystore
cmd/goflyway/lib
shadowsocks*
25 changes: 9 additions & 16 deletions client.go
@@ -1,9 +1,11 @@
package goflyway

import (
"context"
"encoding/binary"
"fmt"
"io"
"net/http"
"strconv"

"github.com/coyove/goflyway/toh"
Expand All @@ -26,26 +28,17 @@ type ClientConfig struct {
func NewClient(localaddr string, config *ClientConfig) error {
config.check()

//tr := *http.DefaultTransport.(*http.Transport)
//tr.MaxConnsPerHost = 100
//http.DefaultTransport.(*http.Transport).DialContext = func(ctx context.Context, network string, address string) (net.Conn, error) {
// switch {
// case config.KCP:
// return kcp.Dial(address)
// case config.VPN:
// return vpnDial(address)
// default:
// conn, err := net.Dial(network, address)
// Vprint(conn.Write([]byte("POST /1.txt HTTP/1.1\r\nHost: toh22.test.upcdn.net:80\r\nContent-Length: 2\r\nContent-Type: application/x-www-form-urlencoded\r\nUser-Agent: curl/7.54.0\r\n\r\n\x01\x02")))
// Vprint(conn)
// return conn, err
// }
//}
tr := *http.DefaultTransport.(*http.Transport)
if config.VPN {
tr.DialContext = func(ctx context.Context, network string, address string) (net.Conn, error) {
return vpnDial(address)
}
}

dialer := toh.NewDialer(config.Key, config.Upstream,
toh.WithWebSocket(config.WebSocket),
toh.WithInactiveTimeout(config.Timeout),
// toh.WithTransport(&tr),
toh.WithTransport(&tr),
toh.WithMaxWriteBuffer(int(config.WriteBuffer)),
toh.WithHeader(config.URLHeader))

Expand Down
29 changes: 24 additions & 5 deletions cmd/goflyway/main.go
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/binary"
"encoding/json"
"fmt"
"io/ioutil"
"net"
Expand Down Expand Up @@ -31,7 +32,7 @@ func printHelp(a ...interface{}) {
fmt.Printf("goflyway: ")
fmt.Println(a...)
}
fmt.Println("usage: goflyway -DLhuUvVkqpPtTwWy address:port")
fmt.Println("usage: goflyway -DLhHUvkqpPtTwWy address:port")
os.Exit(0)
}

Expand All @@ -40,14 +41,23 @@ func main() {

for i, last := 1, rune(0); i < len(os.Args); i++ {
p := strings.TrimLeft(os.Args[i], "-")

// HACK: ss-local compatible command flags
if p == "fast-open" || p == "V" || p == "u" || p == "m" || p == "b" {
if i < len(os.Args)-1 && !strings.HasPrefix(os.Args[i+1], "-") {
i++
}
continue
}

if len(p) != len(os.Args[i]) {
for i, c := range p {
switch c {
case 'h':
printHelp()
case 'V':
printHelp(version)
case 'L', 'P', 'p', 'k', 't', 'T', 'W', 'u', 'U', 'D':
//case 'V':
// printHelp(version)
case 'L', 'P', 'p', 'k', 't', 'T', 'W', 'H', 'U', 'D', 'c':
last = c
case 'v':
v.Verbose++
Expand Down Expand Up @@ -108,8 +118,17 @@ func main() {
sconfig.Timeout = cconfig.Timeout
case 'p', 'k':
sconfig.Key, cconfig.Key = p, p
case 'u':
case 'H':
cconfig.URLHeader = p
case 'c':
buf, _ := ioutil.ReadFile(p)
cmds := make(map[string]interface{})
json.Unmarshal(buf, &cmds)
cconfig.Key, cconfig.VPN = cmds["password"].(string), true
addr = fmt.Sprintf("%v:%v", cmds["server"], cmds["server_port"])

v.Verbose = 3
v.Vprint(os.Args, " config: ", cmds)
default:
addr = p
}
Expand Down
7 changes: 5 additions & 2 deletions toh/client_conn.go
Expand Up @@ -4,9 +4,11 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"math/rand"
"net"
"net/http"
"strconv"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -99,7 +101,7 @@ func (c *ClientConn) Close() error {
return nil
}

v.Vprint(c, " closing")
v.VVprint(c, " closing")
c.write.sched.Cancel()
c.read.close()
c.write.respChOnce.Do(func() {
Expand Down Expand Up @@ -237,8 +239,9 @@ func (c *ClientConn) send(f frame) (resp *http.Response, err error) {
return nil, err
}
if resp.StatusCode != http.StatusOK {
xx, _ := ioutil.ReadAll(resp.Body)
resp.Body.Close()
return nil, fmt.Errorf("remote is unavailable: %s", resp.Status)
return nil, fmt.Errorf("remote is unavailable: %s, resp: %v", resp.Status, strconv.Quote(string(xx)))
}
return resp, nil
}
Expand Down
2 changes: 1 addition & 1 deletion toh/server_conn.go
Expand Up @@ -256,7 +256,7 @@ func (c *ServerConn) Close() error {
return nil
}

v.Vprint(c, " closing")
v.VVprint(c, " closing")
c.schedPurge.Cancel()
c.read.close()
c.rev.connsmu.Lock()
Expand Down

0 comments on commit 8d439de

Please sign in to comment.