add weight for selector
This commit is contained in:
@ -221,7 +221,7 @@ func (h *dnsHandler) exchange(ctx context.Context, msg []byte, log logger.Logger
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ex := h.selectExchanger(strings.Trim(mq.Question[0].Name, "."))
|
||||
ex := h.selectExchanger(ctx, strings.Trim(mq.Question[0].Name, "."))
|
||||
if ex == nil {
|
||||
err := fmt.Errorf("exchange not found for %s", mq.Question[0].Name)
|
||||
log.Error(err)
|
||||
@ -293,11 +293,11 @@ func (h *dnsHandler) lookupHosts(r *dns.Msg, log logger.Logger) (m *dns.Msg) {
|
||||
return
|
||||
}
|
||||
|
||||
func (h *dnsHandler) selectExchanger(addr string) exchanger.Exchanger {
|
||||
func (h *dnsHandler) selectExchanger(ctx context.Context, addr string) exchanger.Exchanger {
|
||||
if h.group == nil {
|
||||
return nil
|
||||
}
|
||||
node := h.group.FilterAddr(addr).Next()
|
||||
node := h.group.FilterAddr(addr).Next(ctx)
|
||||
if node == nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn, opts ...hand
|
||||
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||
}()
|
||||
|
||||
target := h.group.Next()
|
||||
target := h.group.Next(ctx)
|
||||
if target == nil {
|
||||
err := errors.New("target not available")
|
||||
log.Error(err)
|
||||
|
@ -71,7 +71,7 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn, opts ...hand
|
||||
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||
}()
|
||||
|
||||
target := h.group.Next()
|
||||
target := h.group.Next(ctx)
|
||||
if target == nil {
|
||||
err := errors.New("target not available")
|
||||
log.Error(err)
|
||||
|
@ -17,7 +17,7 @@ func (h *relayHandler) handleForward(ctx context.Context, conn net.Conn, network
|
||||
Version: relay.Version1,
|
||||
Status: relay.StatusOK,
|
||||
}
|
||||
target := h.group.Next()
|
||||
target := h.group.Next(ctx)
|
||||
if target == nil {
|
||||
resp.Status = relay.StatusServiceUnavailable
|
||||
resp.WriteTo(conn)
|
||||
|
@ -105,7 +105,7 @@ func (h *tapHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler.
|
||||
var raddr net.Addr
|
||||
var err error
|
||||
|
||||
target := h.group.Next()
|
||||
target := h.group.Next(ctx)
|
||||
if target != nil {
|
||||
raddr, err = net.ResolveUDPAddr(network, target.Addr)
|
||||
if err != nil {
|
||||
|
@ -87,7 +87,7 @@ func (h *tunHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler.
|
||||
var raddr net.Addr
|
||||
var err error
|
||||
|
||||
target := h.group.Next()
|
||||
target := h.group.Next(ctx)
|
||||
if target != nil {
|
||||
raddr, err = net.ResolveUDPAddr(network, target.Addr)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user