update chain route

This commit is contained in:
ginuerzh
2022-09-20 11:48:51 +08:00
parent 01d7dc77c6
commit 1a1c038fd7
27 changed files with 565 additions and 113 deletions

View File

@ -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(ctx)
target := h.hop.Select(ctx)
if target == nil {
resp.Status = relay.StatusServiceUnavailable
resp.WriteTo(conn)

View File

@ -24,7 +24,7 @@ func init() {
}
type relayHandler struct {
group *chain.NodeGroup
hop chain.Hop
router *chain.Router
md metadata
options handler.Options
@ -48,15 +48,15 @@ func (h *relayHandler) Init(md md.Metadata) (err error) {
h.router = h.options.Router
if h.router == nil {
h.router = (&chain.Router{}).WithLogger(h.options.Logger)
h.router = chain.NewRouter(chain.LoggerRouterOption(h.options.Logger))
}
return nil
}
// Forward implements handler.Forwarder.
func (h *relayHandler) Forward(group *chain.NodeGroup) {
h.group = group
func (h *relayHandler) Forward(hop chain.Hop) {
h.hop = hop
}
func (h *relayHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler.HandleOption) error {
@ -130,7 +130,7 @@ func (h *relayHandler) Handle(ctx context.Context, conn net.Conn, opts ...handle
network = "udp"
}
if h.group != nil {
if h.hop != nil {
if address != "" {
resp.Status = relay.StatusForbidden
log.Error("forward mode, connect is forbidden")