Skip to content

Commit

Permalink
Optimize multi-channel selection
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed Mar 9, 2024
1 parent ab097e6 commit ff88828
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
24 changes: 21 additions & 3 deletions chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import (
"context"
"fmt"
"strings"
"time"

"github.com/wzshiming/bridge"
"github.com/wzshiming/bridge/config"
"github.com/wzshiming/bridge/internal/scheme"
"github.com/wzshiming/geario"
"github.com/wzshiming/schedialer"
"github.com/wzshiming/schedialer/plugins/flow"
"github.com/wzshiming/schedialer/plugins/probe"
"github.com/wzshiming/schedialer/plugins/random"
"github.com/wzshiming/schedialer/plugins/rate"
)

// BridgeChain is a bridger that supports multiple crossing of bridger.
Expand Down Expand Up @@ -80,10 +84,12 @@ func (b *BridgeChain) Dial(dialer bridge.Dialer, addresses []string, probeUrl st
return b.dialOne(dialer, addresses[0])
}
plugins := []schedialer.Plugin{
random.NewRandom(),
random.NewRandom(1),
flow.NewFlow(40),
rate.NewRate(40),
}
if probeUrl != "" {
plugins = append(plugins, probe.NewProbe(probeUrl))
plugins = append(plugins, probe.NewProbe(100, probeUrl))
}
return b.dialMulti(dialer, addresses, plugins)
}
Expand All @@ -99,9 +105,21 @@ func (b *BridgeChain) dialMulti(dialer bridge.Dialer, addresses []string, plugin
if err != nil {
return nil, err
}

g := geario.NewGear(1*time.Second, -1)
proxy := schedialer.Proxy{
Name: address,
Dialer: dial,
Dialer: geario.DialGear(dial, g, g),

Aver: func() uint64 {
return uint64(g.Aver())
},
MaxAver: func() uint64 {
return uint64(g.MaxAver())
},
Total: func() uint64 {
return uint64(g.Total())
},
}
plugin.AddProxy(ctx, &proxy)
}
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ require (
github.com/wzshiming/cmux v0.3.3
github.com/wzshiming/commandproxy v0.2.0
github.com/wzshiming/emux v0.2.1
github.com/wzshiming/geario v0.0.0-20240308093553-a996e3817533
github.com/wzshiming/hostmatcher v0.0.1
github.com/wzshiming/httpproxy v0.5.5
github.com/wzshiming/notify v0.1.1
github.com/wzshiming/permuteproxy v0.0.2
github.com/wzshiming/schedialer v0.2.1
github.com/wzshiming/schedialer v0.3.0
github.com/wzshiming/shadowsocks v0.4.0
github.com/wzshiming/socks4 v0.3.2
github.com/wzshiming/socks5 v0.4.3
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ github.com/wzshiming/commandproxy v0.2.0 h1:uPVhgIj2YSncRUo6g9smGR6OMzsIg7lwklcM
github.com/wzshiming/commandproxy v0.2.0/go.mod h1:wS6+aJ9KMHciqYX3xmDO0W+QVY0zvngeBvmoIFMfq8A=
github.com/wzshiming/emux v0.2.1 h1:pu0oV9PpAJ5cVO8tzkqUXcCqc8xC452vNzQK9cghUis=
github.com/wzshiming/emux v0.2.1/go.mod h1:VQF6NoR4nfm3+OrKZLx47JuxuDeWemHDc0a4qDNtFtg=
github.com/wzshiming/geario v0.0.0-20240308093553-a996e3817533 h1:mq74wxgDCz7Q6CqZYExt0DHf7Ze28lyMW/TNsfcuk8M=
github.com/wzshiming/geario v0.0.0-20240308093553-a996e3817533/go.mod h1:Fodw3HJvNUS+/MgqXCRp9iYLQfynAu/LKXGOWoX+D/Q=
github.com/wzshiming/hostmatcher v0.0.1 h1:vPrUEXsd+khvN5W7I4rJ73vYaUvnBCodvtuyCU+q1HQ=
github.com/wzshiming/hostmatcher v0.0.1/go.mod h1:3EyfIDuzQyo0tqrCtcUkD5UvAsdxOUb/RbcYOiPTh1E=
github.com/wzshiming/httpproxy v0.5.5 h1:2vEW6QGYDDtA5B97PFWVolRZs3BYEUIXnhc0vXUzrQ8=
Expand All @@ -26,8 +28,8 @@ github.com/wzshiming/notify v0.1.1 h1:rJXoszrkNglhCVyn/IfW500f5cW03q1q7YzL8hsLch
github.com/wzshiming/notify v0.1.1/go.mod h1:SFhsQKZJznzsDcj/Qfo9A65k5IRcpUrpgbLRzZEa/DI=
github.com/wzshiming/permuteproxy v0.0.2 h1:svedMueotlxJk9oJfA0gs8WzRYOdgd0DER9XvKpjwlY=
github.com/wzshiming/permuteproxy v0.0.2/go.mod h1:Ny08A1JbuljB8FeJAOiB7dfvRGCVD8PB9hwrALIvYI8=
github.com/wzshiming/schedialer v0.2.1 h1:DnAv8ta2UuWcvRy9sYwSt69rTuE3/kiCgwX6CiN5y4M=
github.com/wzshiming/schedialer v0.2.1/go.mod h1:TvVxg4QZIBTJzRfmL/G7g6CzynFQKPmtXtSeJ2c4Lus=
github.com/wzshiming/schedialer v0.3.0 h1:dVdg20s5HsRKcOM7psO0eCsXaD/w+tCXaQmm92M6/04=
github.com/wzshiming/schedialer v0.3.0/go.mod h1:TvVxg4QZIBTJzRfmL/G7g6CzynFQKPmtXtSeJ2c4Lus=
github.com/wzshiming/shadowsocks v0.4.0 h1:Yi+4J/DK15qdKlssNEMoWjtmc8wyY8ByIBbC5Ft29bQ=
github.com/wzshiming/shadowsocks v0.4.0/go.mod h1:xYRRSKR+hTihSDUOE+evavx0wkLVODTWVXEcz5vosoE=
github.com/wzshiming/socks4 v0.3.2 h1:w87nwfgRWteVwIH39nqTur8c+2dcODeLgLrWspcUkSc=
Expand Down

0 comments on commit ff88828

Please sign in to comment.