Skip to content

Commit

Permalink
add more detail info for routing
Browse files Browse the repository at this point in the history
  • Loading branch information
ginuerzh committed Dec 6, 2018
1 parent 0bb52bc commit 7686a4b
Show file tree
Hide file tree
Showing 26 changed files with 592 additions and 561 deletions.
2 changes: 1 addition & 1 deletion bypass.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func NewBypassPatterns(reversed bool, patterns ...string) *Bypass {

// Contains reports whether the bypass includes addr.
func (bp *Bypass) Contains(addr string) bool {
if bp == nil {
if bp == nil || addr == "" {
return false
}
// try to strip the port
Expand Down
58 changes: 9 additions & 49 deletions chain.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package gost

import (
"bytes"
"errors"
"fmt"
"net"
"time"

Expand All @@ -20,6 +18,7 @@ type Chain struct {
isRoute bool
Retries int
nodeGroups []*NodeGroup
route []Node // nodes in the selected route
}

// NewChain creates a proxy chain with a list of proxy nodes.
Expand Down Expand Up @@ -197,18 +196,14 @@ func (c *Chain) Conn(opts ...ChainOption) (conn net.Conn, err error) {
continue
}
conn, err = route.getConn()
if err != nil {
log.Log(err)
continue
if err == nil {
break
}

break
}
return
}

// getConn obtains a connection to the last node of the chain.
// It does not handshake with the last node.
func (c *Chain) getConn() (conn net.Conn, err error) {
if c.IsEmpty() {
err = ErrEmptyChain
Expand Down Expand Up @@ -256,35 +251,7 @@ func (c *Chain) getConn() (conn net.Conn, err error) {
}

func (c *Chain) selectRoute() (route *Chain, err error) {
if c.IsEmpty() || c.isRoute {
return c, nil
}

buf := bytes.Buffer{}
route = newRoute()

for _, group := range c.nodeGroups {
node, err := group.Next()
if err != nil {
return nil, err
}
buf.WriteString(fmt.Sprintf("%s -> ", node.String()))

if node.Client.Transporter.Multiplex() {
node.DialOptions = append(node.DialOptions,
ChainDialOption(route),
)
route = newRoute() // cutoff the chain for multiplex.
}

route.AddNode(node)
}
route.Retries = c.Retries

if Debug {
log.Log("select route:", buf.String())
}
return
return c.selectRouteFor("")
}

// selectRouteFor selects route with bypass testing.
Expand All @@ -293,8 +260,8 @@ func (c *Chain) selectRouteFor(addr string) (route *Chain, err error) {
return c, nil
}

buf := bytes.Buffer{}
route = newRoute()
var nl []Node

for _, group := range c.nodeGroups {
var node Node
Expand All @@ -304,28 +271,21 @@ func (c *Chain) selectRouteFor(addr string) (route *Chain, err error) {
}

if node.Bypass.Contains(addr) {
if Debug {
buf.WriteString(fmt.Sprintf("[bypass]%s -> %s", node.String(), addr))
log.Log("[route]", buf.String())
}
return
break
}

buf.WriteString(fmt.Sprintf("%s -> ", node.String()))

if node.Client.Transporter.Multiplex() {
node.DialOptions = append(node.DialOptions,
ChainDialOption(route),
)
route = newRoute() // cutoff the chain for multiplex.
route = newRoute() // cutoff the chain for multiplex node.
}

route.AddNode(node)
nl = append(nl, node)
}
route.Retries = c.Retries

buf.WriteString(addr)
log.Log("[route]", buf.String())
route.route = nl

return
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions cmd/gost/.config/probe_resist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World!
File renamed without changes.
21 changes: 0 additions & 21 deletions cmd/gost/kcp.json

This file was deleted.

8 changes: 5 additions & 3 deletions cmd/gost/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ func (r *route) GenRouters() ([]router, error) {
hosts := parseHosts(node.Get("hosts"))

handler.Init(
gost.AddrHandlerOption(node.Addr),
// gost.AddrHandlerOption(node.Addr),
gost.AddrHandlerOption(ln.Addr().String()),
gost.ChainHandlerOption(chain),
gost.UsersHandlerOption(users...),
gost.TLSConfigHandlerOption(tlsCfg),
Expand All @@ -417,9 +418,10 @@ func (r *route) GenRouters() ([]router, error) {
gost.BypassHandlerOption(node.Bypass),
gost.ResolverHandlerOption(resolver),
gost.HostsHandlerOption(hosts),
gost.RetryHandlerOption(node.GetInt("retry")),
gost.RetryHandlerOption(node.GetInt("retry")), // override the global retry option.
gost.TimeoutHandlerOption(time.Duration(node.GetInt("timeout"))*time.Second),
gost.ProbeResistHandlerOption(node.Get("probe_resist")),
gost.NodeHandlerOption(node),
)

rt := router{
Expand All @@ -446,7 +448,7 @@ type router struct {
}

func (r *router) Serve() error {
log.Logf("[route] start %s on %s", r.node.String(), r.server.Addr())
log.Logf("%s on %s", r.node.String(), r.server.Addr())
return r.server.Serve(r.handler)
}

Expand Down
48 changes: 0 additions & 48 deletions cmd/gost/ssl/README.md

This file was deleted.

23 changes: 0 additions & 23 deletions cmd/gost/ssl/localhost.crt

This file was deleted.

16 changes: 0 additions & 16 deletions cmd/gost/ssl/localhost.csr

This file was deleted.

27 changes: 0 additions & 27 deletions cmd/gost/ssl/localhost.key

This file was deleted.

27 changes: 0 additions & 27 deletions cmd/gost/ssl/rootCA.crt

This file was deleted.

51 changes: 0 additions & 51 deletions cmd/gost/ssl/rootCA.key

This file was deleted.

1 change: 0 additions & 1 deletion cmd/gost/ssl/rootCA.srl

This file was deleted.

Loading

0 comments on commit 7686a4b

Please sign in to comment.