add network for bypass

This commit is contained in:
ginuerzh
2023-09-30 17:51:55 +08:00
parent ea585fc25d
commit 836cf6eade
24 changed files with 92 additions and 160 deletions

View File

@ -139,7 +139,7 @@ func (p *chainHop) Select(ctx context.Context, opts ...hop.SelectOption) *chain.
// hop level bypass
if p.options.bypass != nil &&
p.options.bypass.Contains(ctx, options.Addr) {
p.options.bypass.Contains(ctx, options.Network, options.Addr, bypass.WithHostOpton(options.Host)) {
return nil
}
@ -186,7 +186,7 @@ func (p *chainHop) Select(ctx context.Context, opts ...hop.SelectOption) *chain.
}
// node level bypass
if node.Options().Bypass != nil &&
node.Options().Bypass.Contains(ctx, options.Addr) {
node.Options().Bypass.Contains(ctx, options.Network, options.Addr, bypass.WithHostOpton(options.Host)) {
continue
}

View File

@ -19,22 +19,22 @@ import (
)
type grpcPlugin struct {
name string
name string
conn grpc.ClientConnInterface
client proto.HopClient
log logger.Logger
}
// NewGRPCPlugin creates a Hop plugin based on gRPC.
func NewGRPCPlugin(name string, addr string, opts ...plugin.Option) hop.Hop{
func NewGRPCPlugin(name string, addr string, opts ...plugin.Option) hop.Hop {
var options plugin.Options
for _, opt := range opts {
opt(&options)
}
log := logger.Default().WithFields(map[string]any{
"kind": "hop",
"hop": name,
"kind": "hop",
"hop": name,
})
conn, err := plugin.NewGRPCConn(addr, &options)
if err != nil {
@ -64,9 +64,10 @@ func (p *grpcPlugin) Select(ctx context.Context, opts ...hop.SelectOption) *chai
r, err := p.client.Select(ctx,
&proto.SelectRequest{
Addr: options.Addr,
Host: options.Host,
Client: string(auth_util.IDFromContext(ctx)),
Network: options.Network,
Addr: options.Addr,
Host: options.Host,
Client: string(auth_util.IDFromContext(ctx)),
})
if err != nil {
p.log.Error(err)
@ -100,9 +101,9 @@ func (p *grpcPlugin) Close() error {
type httpPluginRequest struct {
Network string `json:"network"`
Addr string `json:"addr"`
Host string `json:"host"`
Client string `json:"client"`
Addr string `json:"addr"`
Host string `json:"host"`
Client string `json:"client"`
}
type httpPluginResponse struct {
@ -110,7 +111,7 @@ type httpPluginResponse struct {
}
type httpPlugin struct {
name string
name string
url string
client *http.Client
header http.Header
@ -118,20 +119,20 @@ type httpPlugin struct {
}
// NewHTTPPlugin creates an Hop plugin based on HTTP.
func NewHTTPPlugin(name string, url string, opts ...plugin.Option) hop.Hop{
func NewHTTPPlugin(name string, url string, opts ...plugin.Option) hop.Hop {
var options plugin.Options
for _, opt := range opts {
opt(&options)
}
return &httpPlugin{
name: name,
name: name,
url: url,
client: plugin.NewHTTPClient(&options),
header: options.Header,
log: logger.Default().WithFields(map[string]any{
"kind": "hop",
"hop": name,
"kind": "hop",
"hop": name,
}),
}
}
@ -147,9 +148,10 @@ func (p *httpPlugin) Select(ctx context.Context, opts ...hop.SelectOption) *chai
}
rb := httpPluginRequest{
Addr: options.Addr,
Host: options.Host,
Client: string(auth_util.IDFromContext(ctx)),
Network: options.Network,
Addr: options.Addr,
Host: options.Host,
Client: string(auth_util.IDFromContext(ctx)),
}
v, err := json.Marshal(&rb)
if err != nil {