2017-01-03 08:21:59 -05:00
|
|
|
// Package proxyman defines applications for manageing inbound and outbound proxies.
|
2016-01-31 11:01:28 -05:00
|
|
|
package proxyman
|
|
|
|
|
2017-12-02 19:04:57 -05:00
|
|
|
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg proxyman -path App,Proxyman
|
2017-04-08 19:43:25 -04:00
|
|
|
|
2016-01-31 11:01:28 -05:00
|
|
|
import (
|
2017-01-14 18:48:37 -05:00
|
|
|
"context"
|
|
|
|
|
2016-08-20 14:55:45 -04:00
|
|
|
"v2ray.com/core/app"
|
2017-01-14 18:48:37 -05:00
|
|
|
"v2ray.com/core/common/net"
|
2016-08-20 14:55:45 -04:00
|
|
|
"v2ray.com/core/proxy"
|
2017-01-14 18:48:37 -05:00
|
|
|
"v2ray.com/core/transport/ray"
|
2016-01-31 11:01:28 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type InboundHandlerManager interface {
|
2017-01-26 14:46:44 -05:00
|
|
|
GetHandler(ctx context.Context, tag string) (InboundHandler, error)
|
|
|
|
AddHandler(ctx context.Context, config *InboundHandlerConfig) error
|
2016-01-31 11:01:28 -05:00
|
|
|
}
|
|
|
|
|
2017-01-14 18:17:06 -05:00
|
|
|
type InboundHandler interface {
|
2017-01-26 14:46:44 -05:00
|
|
|
Start() error
|
|
|
|
Close()
|
|
|
|
|
|
|
|
// For migration
|
2017-01-26 14:57:18 -05:00
|
|
|
GetRandomInboundProxy() (proxy.Inbound, net.Port, int)
|
2017-01-14 18:17:06 -05:00
|
|
|
}
|
|
|
|
|
2016-05-18 02:05:52 -04:00
|
|
|
type OutboundHandlerManager interface {
|
2017-01-26 14:46:44 -05:00
|
|
|
GetHandler(tag string) OutboundHandler
|
|
|
|
GetDefaultHandler() OutboundHandler
|
|
|
|
AddHandler(ctx context.Context, config *OutboundHandlerConfig) error
|
2016-01-31 11:01:28 -05:00
|
|
|
}
|
2017-01-06 09:32:36 -05:00
|
|
|
|
2017-01-14 18:48:37 -05:00
|
|
|
type OutboundHandler interface {
|
2017-01-26 14:46:44 -05:00
|
|
|
Dispatch(ctx context.Context, outboundRay ray.OutboundRay)
|
2017-01-14 18:48:37 -05:00
|
|
|
}
|
|
|
|
|
2017-01-06 09:32:36 -05:00
|
|
|
func InboundHandlerManagerFromSpace(space app.Space) InboundHandlerManager {
|
2017-01-13 07:41:40 -05:00
|
|
|
app := space.GetApplication((*InboundHandlerManager)(nil))
|
2017-01-06 09:32:36 -05:00
|
|
|
if app == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return app.(InboundHandlerManager)
|
|
|
|
}
|
|
|
|
|
|
|
|
func OutboundHandlerManagerFromSpace(space app.Space) OutboundHandlerManager {
|
2017-01-13 07:41:40 -05:00
|
|
|
app := space.GetApplication((*OutboundHandlerManager)(nil))
|
2017-01-06 09:32:36 -05:00
|
|
|
if app == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return app.(OutboundHandlerManager)
|
|
|
|
}
|
2017-04-24 18:19:22 -04:00
|
|
|
|
|
|
|
type key int
|
|
|
|
|
|
|
|
const (
|
|
|
|
protocolsKey key = iota
|
|
|
|
)
|
|
|
|
|
|
|
|
func ContextWithProtocolSniffers(ctx context.Context, list []KnownProtocols) context.Context {
|
|
|
|
return context.WithValue(ctx, protocolsKey, list)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ProtocoSniffersFromContext(ctx context.Context) []KnownProtocols {
|
|
|
|
if list, ok := ctx.Value(protocolsKey).([]KnownProtocols); ok {
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|