2022-07-02 06:07:50 +00:00
|
|
|
package outbound
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/sagernet/sing-box/adapter"
|
|
|
|
C "github.com/sagernet/sing-box/constant"
|
|
|
|
"github.com/sagernet/sing-box/log"
|
|
|
|
"github.com/sagernet/sing-box/option"
|
2022-07-08 15:03:57 +00:00
|
|
|
"github.com/sagernet/sing/common"
|
|
|
|
E "github.com/sagernet/sing/common/exceptions"
|
2022-07-02 06:07:50 +00:00
|
|
|
)
|
|
|
|
|
2022-07-12 07:17:29 +00:00
|
|
|
func New(router adapter.Router, logger log.ContextLogger, options option.Outbound) (adapter.Outbound, error) {
|
2022-07-21 13:03:41 +00:00
|
|
|
if common.IsEmptyByEquals(options) {
|
2022-07-02 17:57:04 +00:00
|
|
|
return nil, E.New("empty outbound config")
|
|
|
|
}
|
2022-07-02 06:07:50 +00:00
|
|
|
switch options.Type {
|
|
|
|
case C.TypeDirect:
|
2022-07-12 07:17:29 +00:00
|
|
|
return NewDirect(router, logger, options.Tag, options.DirectOptions), nil
|
2022-07-03 15:23:18 +00:00
|
|
|
case C.TypeBlock:
|
2022-07-12 07:17:29 +00:00
|
|
|
return NewBlock(logger, options.Tag), nil
|
2022-07-23 01:15:47 +00:00
|
|
|
case C.TypeDNS:
|
|
|
|
return NewDNS(router, logger, options.Tag), nil
|
2022-07-03 05:14:49 +00:00
|
|
|
case C.TypeSocks:
|
2022-07-12 07:17:29 +00:00
|
|
|
return NewSocks(router, logger, options.Tag, options.SocksOptions)
|
2022-07-03 15:23:18 +00:00
|
|
|
case C.TypeHTTP:
|
2022-07-18 12:40:14 +00:00
|
|
|
return NewHTTP(router, logger, options.Tag, options.HTTPOptions)
|
2022-07-02 06:07:50 +00:00
|
|
|
case C.TypeShadowsocks:
|
2022-07-12 07:17:29 +00:00
|
|
|
return NewShadowsocks(router, logger, options.Tag, options.ShadowsocksOptions)
|
2022-07-18 04:32:31 +00:00
|
|
|
case C.TypeVMess:
|
|
|
|
return NewVMess(router, logger, options.Tag, options.VMessOptions)
|
2022-07-21 13:03:41 +00:00
|
|
|
case C.TypeSelector:
|
|
|
|
return NewSelector(router, logger, options.Tag, options.SelectorOptions)
|
2022-07-22 05:51:08 +00:00
|
|
|
case C.TypeURLTest:
|
|
|
|
return NewURLTest(router, logger, options.Tag, options.URLTestOptions)
|
2022-07-02 06:07:50 +00:00
|
|
|
default:
|
2022-07-02 17:57:04 +00:00
|
|
|
return nil, E.New("unknown outbound type: ", options.Type)
|
2022-07-02 06:07:50 +00:00
|
|
|
}
|
|
|
|
}
|