xray.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. package conf
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "log"
  7. "os"
  8. "path/filepath"
  9. "strings"
  10. "github.com/xtls/xray-core/app/dispatcher"
  11. "github.com/xtls/xray-core/app/proxyman"
  12. "github.com/xtls/xray-core/app/stats"
  13. "github.com/xtls/xray-core/common/errors"
  14. "github.com/xtls/xray-core/common/net"
  15. "github.com/xtls/xray-core/common/serial"
  16. core "github.com/xtls/xray-core/core"
  17. "github.com/xtls/xray-core/transport/internet"
  18. )
  19. var (
  20. inboundConfigLoader = NewJSONConfigLoader(ConfigCreatorCache{
  21. "dokodemo-door": func() interface{} { return new(DokodemoConfig) },
  22. "http": func() interface{} { return new(HTTPServerConfig) },
  23. "shadowsocks": func() interface{} { return new(ShadowsocksServerConfig) },
  24. "socks": func() interface{} { return new(SocksServerConfig) },
  25. "vless": func() interface{} { return new(VLessInboundConfig) },
  26. "vmess": func() interface{} { return new(VMessInboundConfig) },
  27. "trojan": func() interface{} { return new(TrojanServerConfig) },
  28. "wireguard": func() interface{} { return &WireGuardConfig{IsClient: false} },
  29. }, "protocol", "settings")
  30. outboundConfigLoader = NewJSONConfigLoader(ConfigCreatorCache{
  31. "blackhole": func() interface{} { return new(BlackholeConfig) },
  32. "loopback": func() interface{} { return new(LoopbackConfig) },
  33. "freedom": func() interface{} { return new(FreedomConfig) },
  34. "http": func() interface{} { return new(HTTPClientConfig) },
  35. "shadowsocks": func() interface{} { return new(ShadowsocksClientConfig) },
  36. "socks": func() interface{} { return new(SocksClientConfig) },
  37. "vless": func() interface{} { return new(VLessOutboundConfig) },
  38. "vmess": func() interface{} { return new(VMessOutboundConfig) },
  39. "trojan": func() interface{} { return new(TrojanClientConfig) },
  40. "dns": func() interface{} { return new(DNSOutboundConfig) },
  41. "wireguard": func() interface{} { return &WireGuardConfig{IsClient: true} },
  42. }, "protocol", "settings")
  43. ctllog = log.New(os.Stderr, "xctl> ", 0)
  44. )
  45. type SniffingConfig struct {
  46. Enabled bool `json:"enabled"`
  47. DestOverride *StringList `json:"destOverride"`
  48. DomainsExcluded *StringList `json:"domainsExcluded"`
  49. MetadataOnly bool `json:"metadataOnly"`
  50. RouteOnly bool `json:"routeOnly"`
  51. }
  52. // Build implements Buildable.
  53. func (c *SniffingConfig) Build() (*proxyman.SniffingConfig, error) {
  54. var p []string
  55. if c.DestOverride != nil {
  56. for _, protocol := range *c.DestOverride {
  57. switch strings.ToLower(protocol) {
  58. case "http":
  59. p = append(p, "http")
  60. case "tls", "https", "ssl":
  61. p = append(p, "tls")
  62. case "quic":
  63. p = append(p, "quic")
  64. case "fakedns":
  65. p = append(p, "fakedns")
  66. case "fakedns+others":
  67. p = append(p, "fakedns+others")
  68. default:
  69. return nil, errors.New("unknown protocol: ", protocol)
  70. }
  71. }
  72. }
  73. var d []string
  74. if c.DomainsExcluded != nil {
  75. for _, domain := range *c.DomainsExcluded {
  76. d = append(d, strings.ToLower(domain))
  77. }
  78. }
  79. return &proxyman.SniffingConfig{
  80. Enabled: c.Enabled,
  81. DestinationOverride: p,
  82. DomainsExcluded: d,
  83. MetadataOnly: c.MetadataOnly,
  84. RouteOnly: c.RouteOnly,
  85. }, nil
  86. }
  87. type MuxConfig struct {
  88. Enabled bool `json:"enabled"`
  89. Concurrency int16 `json:"concurrency"`
  90. XudpConcurrency int16 `json:"xudpConcurrency"`
  91. XudpProxyUDP443 string `json:"xudpProxyUDP443"`
  92. }
  93. // Build creates MultiplexingConfig, Concurrency < 0 completely disables mux.
  94. func (m *MuxConfig) Build() (*proxyman.MultiplexingConfig, error) {
  95. switch m.XudpProxyUDP443 {
  96. case "":
  97. m.XudpProxyUDP443 = "reject"
  98. case "reject", "allow", "skip":
  99. default:
  100. return nil, errors.New(`unknown "xudpProxyUDP443": `, m.XudpProxyUDP443)
  101. }
  102. return &proxyman.MultiplexingConfig{
  103. Enabled: m.Enabled,
  104. Concurrency: int32(m.Concurrency),
  105. XudpConcurrency: int32(m.XudpConcurrency),
  106. XudpProxyUDP443: m.XudpProxyUDP443,
  107. }, nil
  108. }
  109. type InboundDetourAllocationConfig struct {
  110. Strategy string `json:"strategy"`
  111. Concurrency *uint32 `json:"concurrency"`
  112. RefreshMin *uint32 `json:"refresh"`
  113. }
  114. // Build implements Buildable.
  115. func (c *InboundDetourAllocationConfig) Build() (*proxyman.AllocationStrategy, error) {
  116. config := new(proxyman.AllocationStrategy)
  117. switch strings.ToLower(c.Strategy) {
  118. case "always":
  119. config.Type = proxyman.AllocationStrategy_Always
  120. case "random":
  121. config.Type = proxyman.AllocationStrategy_Random
  122. case "external":
  123. config.Type = proxyman.AllocationStrategy_External
  124. default:
  125. return nil, errors.New("unknown allocation strategy: ", c.Strategy)
  126. }
  127. if c.Concurrency != nil {
  128. config.Concurrency = &proxyman.AllocationStrategy_AllocationStrategyConcurrency{
  129. Value: *c.Concurrency,
  130. }
  131. }
  132. if c.RefreshMin != nil {
  133. config.Refresh = &proxyman.AllocationStrategy_AllocationStrategyRefresh{
  134. Value: *c.RefreshMin,
  135. }
  136. }
  137. return config, nil
  138. }
  139. type InboundDetourConfig struct {
  140. Protocol string `json:"protocol"`
  141. PortList *PortList `json:"port"`
  142. ListenOn *Address `json:"listen"`
  143. Settings *json.RawMessage `json:"settings"`
  144. Tag string `json:"tag"`
  145. Allocation *InboundDetourAllocationConfig `json:"allocate"`
  146. StreamSetting *StreamConfig `json:"streamSettings"`
  147. SniffingConfig *SniffingConfig `json:"sniffing"`
  148. }
  149. // Build implements Buildable.
  150. func (c *InboundDetourConfig) Build() (*core.InboundHandlerConfig, error) {
  151. receiverSettings := &proxyman.ReceiverConfig{}
  152. if c.ListenOn == nil {
  153. // Listen on anyip, must set PortList
  154. if c.PortList == nil {
  155. return nil, errors.New("Listen on AnyIP but no Port(s) set in InboundDetour.")
  156. }
  157. receiverSettings.PortList = c.PortList.Build()
  158. } else {
  159. // Listen on specific IP or Unix Domain Socket
  160. receiverSettings.Listen = c.ListenOn.Build()
  161. listenDS := c.ListenOn.Family().IsDomain() && (filepath.IsAbs(c.ListenOn.Domain()) || c.ListenOn.Domain()[0] == '@')
  162. listenIP := c.ListenOn.Family().IsIP() || (c.ListenOn.Family().IsDomain() && c.ListenOn.Domain() == "localhost")
  163. if listenIP {
  164. // Listen on specific IP, must set PortList
  165. if c.PortList == nil {
  166. return nil, errors.New("Listen on specific ip without port in InboundDetour.")
  167. }
  168. // Listen on IP:Port
  169. receiverSettings.PortList = c.PortList.Build()
  170. } else if listenDS {
  171. if c.PortList != nil {
  172. // Listen on Unix Domain Socket, PortList should be nil
  173. receiverSettings.PortList = nil
  174. }
  175. } else {
  176. return nil, errors.New("unable to listen on domain address: ", c.ListenOn.Domain())
  177. }
  178. }
  179. if c.Allocation != nil {
  180. concurrency := -1
  181. if c.Allocation.Concurrency != nil && c.Allocation.Strategy == "random" {
  182. concurrency = int(*c.Allocation.Concurrency)
  183. }
  184. portRange := 0
  185. for _, pr := range c.PortList.Range {
  186. portRange += int(pr.To - pr.From + 1)
  187. }
  188. if concurrency >= 0 && concurrency >= portRange {
  189. var ports strings.Builder
  190. for _, pr := range c.PortList.Range {
  191. fmt.Fprintf(&ports, "%d-%d ", pr.From, pr.To)
  192. }
  193. return nil, errors.New("not enough ports. concurrency = ", concurrency, " ports: ", ports.String())
  194. }
  195. as, err := c.Allocation.Build()
  196. if err != nil {
  197. return nil, err
  198. }
  199. receiverSettings.AllocationStrategy = as
  200. }
  201. if c.StreamSetting != nil {
  202. ss, err := c.StreamSetting.Build()
  203. if err != nil {
  204. return nil, err
  205. }
  206. receiverSettings.StreamSettings = ss
  207. }
  208. if c.SniffingConfig != nil {
  209. s, err := c.SniffingConfig.Build()
  210. if err != nil {
  211. return nil, errors.New("failed to build sniffing config").Base(err)
  212. }
  213. receiverSettings.SniffingSettings = s
  214. }
  215. settings := []byte("{}")
  216. if c.Settings != nil {
  217. settings = ([]byte)(*c.Settings)
  218. }
  219. rawConfig, err := inboundConfigLoader.LoadWithID(settings, c.Protocol)
  220. if err != nil {
  221. return nil, errors.New("failed to load inbound detour config.").Base(err)
  222. }
  223. if dokodemoConfig, ok := rawConfig.(*DokodemoConfig); ok {
  224. receiverSettings.ReceiveOriginalDestination = dokodemoConfig.Redirect
  225. }
  226. ts, err := rawConfig.(Buildable).Build()
  227. if err != nil {
  228. return nil, err
  229. }
  230. return &core.InboundHandlerConfig{
  231. Tag: c.Tag,
  232. ReceiverSettings: serial.ToTypedMessage(receiverSettings),
  233. ProxySettings: serial.ToTypedMessage(ts),
  234. }, nil
  235. }
  236. type OutboundDetourConfig struct {
  237. Protocol string `json:"protocol"`
  238. SendThrough *string `json:"sendThrough"`
  239. Tag string `json:"tag"`
  240. Settings *json.RawMessage `json:"settings"`
  241. StreamSetting *StreamConfig `json:"streamSettings"`
  242. ProxySettings *ProxyConfig `json:"proxySettings"`
  243. MuxSettings *MuxConfig `json:"mux"`
  244. }
  245. func (c *OutboundDetourConfig) checkChainProxyConfig() error {
  246. if c.StreamSetting == nil || c.ProxySettings == nil || c.StreamSetting.SocketSettings == nil {
  247. return nil
  248. }
  249. if len(c.ProxySettings.Tag) > 0 && len(c.StreamSetting.SocketSettings.DialerProxy) > 0 {
  250. return errors.New("proxySettings.tag is conflicted with sockopt.dialerProxy").AtWarning()
  251. }
  252. return nil
  253. }
  254. // Build implements Buildable.
  255. func (c *OutboundDetourConfig) Build() (*core.OutboundHandlerConfig, error) {
  256. senderSettings := &proxyman.SenderConfig{}
  257. if err := c.checkChainProxyConfig(); err != nil {
  258. return nil, err
  259. }
  260. if c.SendThrough != nil {
  261. address := ParseSendThough(c.SendThrough)
  262. //Check if CIDR exists
  263. if strings.Contains(*c.SendThrough, "/") {
  264. senderSettings.ViaCidr = strings.Split(*c.SendThrough, "/")[1]
  265. } else {
  266. if address.Family().IsDomain() {
  267. return nil, errors.New("unable to send through: " + address.String())
  268. }
  269. }
  270. senderSettings.Via = address.Build()
  271. }
  272. if c.StreamSetting != nil {
  273. ss, err := c.StreamSetting.Build()
  274. if err != nil {
  275. return nil, err
  276. }
  277. senderSettings.StreamSettings = ss
  278. }
  279. if c.ProxySettings != nil {
  280. ps, err := c.ProxySettings.Build()
  281. if err != nil {
  282. return nil, errors.New("invalid outbound detour proxy settings.").Base(err)
  283. }
  284. if ps.TransportLayerProxy {
  285. if senderSettings.StreamSettings != nil {
  286. if senderSettings.StreamSettings.SocketSettings != nil {
  287. senderSettings.StreamSettings.SocketSettings.DialerProxy = ps.Tag
  288. } else {
  289. senderSettings.StreamSettings.SocketSettings = &internet.SocketConfig{DialerProxy: ps.Tag}
  290. }
  291. } else {
  292. senderSettings.StreamSettings = &internet.StreamConfig{SocketSettings: &internet.SocketConfig{DialerProxy: ps.Tag}}
  293. }
  294. ps = nil
  295. }
  296. senderSettings.ProxySettings = ps
  297. }
  298. if c.MuxSettings != nil {
  299. ms, err := c.MuxSettings.Build()
  300. if err != nil {
  301. return nil, errors.New("failed to build Mux config.").Base(err)
  302. }
  303. senderSettings.MultiplexSettings = ms
  304. }
  305. settings := []byte("{}")
  306. if c.Settings != nil {
  307. settings = ([]byte)(*c.Settings)
  308. }
  309. rawConfig, err := outboundConfigLoader.LoadWithID(settings, c.Protocol)
  310. if err != nil {
  311. return nil, errors.New("failed to parse to outbound detour config.").Base(err)
  312. }
  313. ts, err := rawConfig.(Buildable).Build()
  314. if err != nil {
  315. return nil, err
  316. }
  317. return &core.OutboundHandlerConfig{
  318. SenderSettings: serial.ToTypedMessage(senderSettings),
  319. Tag: c.Tag,
  320. ProxySettings: serial.ToTypedMessage(ts),
  321. }, nil
  322. }
  323. type StatsConfig struct{}
  324. // Build implements Buildable.
  325. func (c *StatsConfig) Build() (*stats.Config, error) {
  326. return &stats.Config{}, nil
  327. }
  328. type Config struct {
  329. // Deprecated: Global transport config is no longer used
  330. // left for returning error
  331. Transport map[string]json.RawMessage `json:"transport"`
  332. LogConfig *LogConfig `json:"log"`
  333. RouterConfig *RouterConfig `json:"routing"`
  334. DNSConfig *DNSConfig `json:"dns"`
  335. InboundConfigs []InboundDetourConfig `json:"inbounds"`
  336. OutboundConfigs []OutboundDetourConfig `json:"outbounds"`
  337. Policy *PolicyConfig `json:"policy"`
  338. API *APIConfig `json:"api"`
  339. Metrics *MetricsConfig `json:"metrics"`
  340. Stats *StatsConfig `json:"stats"`
  341. Reverse *ReverseConfig `json:"reverse"`
  342. FakeDNS *FakeDNSConfig `json:"fakeDns"`
  343. Observatory *ObservatoryConfig `json:"observatory"`
  344. BurstObservatory *BurstObservatoryConfig `json:"burstObservatory"`
  345. }
  346. func (c *Config) findInboundTag(tag string) int {
  347. found := -1
  348. for idx, ib := range c.InboundConfigs {
  349. if ib.Tag == tag {
  350. found = idx
  351. break
  352. }
  353. }
  354. return found
  355. }
  356. func (c *Config) findOutboundTag(tag string) int {
  357. found := -1
  358. for idx, ob := range c.OutboundConfigs {
  359. if ob.Tag == tag {
  360. found = idx
  361. break
  362. }
  363. }
  364. return found
  365. }
  366. // Override method accepts another Config overrides the current attribute
  367. func (c *Config) Override(o *Config, fn string) {
  368. // only process the non-deprecated members
  369. if o.LogConfig != nil {
  370. c.LogConfig = o.LogConfig
  371. }
  372. if o.RouterConfig != nil {
  373. c.RouterConfig = o.RouterConfig
  374. }
  375. if o.DNSConfig != nil {
  376. c.DNSConfig = o.DNSConfig
  377. }
  378. if o.Transport != nil {
  379. c.Transport = o.Transport
  380. }
  381. if o.Policy != nil {
  382. c.Policy = o.Policy
  383. }
  384. if o.API != nil {
  385. c.API = o.API
  386. }
  387. if o.Metrics != nil {
  388. c.Metrics = o.Metrics
  389. }
  390. if o.Stats != nil {
  391. c.Stats = o.Stats
  392. }
  393. if o.Reverse != nil {
  394. c.Reverse = o.Reverse
  395. }
  396. if o.FakeDNS != nil {
  397. c.FakeDNS = o.FakeDNS
  398. }
  399. if o.Observatory != nil {
  400. c.Observatory = o.Observatory
  401. }
  402. if o.BurstObservatory != nil {
  403. c.BurstObservatory = o.BurstObservatory
  404. }
  405. // update the Inbound in slice if the only one in override config has same tag
  406. if len(o.InboundConfigs) > 0 {
  407. for i := range o.InboundConfigs {
  408. if idx := c.findInboundTag(o.InboundConfigs[i].Tag); idx > -1 {
  409. c.InboundConfigs[idx] = o.InboundConfigs[i]
  410. errors.LogInfo(context.Background(), "[", fn, "] updated inbound with tag: ", o.InboundConfigs[i].Tag)
  411. } else {
  412. c.InboundConfigs = append(c.InboundConfigs, o.InboundConfigs[i])
  413. errors.LogInfo(context.Background(), "[", fn, "] appended inbound with tag: ", o.InboundConfigs[i].Tag)
  414. }
  415. }
  416. }
  417. // update the Outbound in slice if the only one in override config has same tag
  418. if len(o.OutboundConfigs) > 0 {
  419. outboundPrepends := []OutboundDetourConfig{}
  420. for i := range o.OutboundConfigs {
  421. if idx := c.findOutboundTag(o.OutboundConfigs[i].Tag); idx > -1 {
  422. c.OutboundConfigs[idx] = o.OutboundConfigs[i]
  423. errors.LogInfo(context.Background(), "[", fn, "] updated outbound with tag: ", o.OutboundConfigs[i].Tag)
  424. } else {
  425. if strings.Contains(strings.ToLower(fn), "tail") {
  426. c.OutboundConfigs = append(c.OutboundConfigs, o.OutboundConfigs[i])
  427. errors.LogInfo(context.Background(), "[", fn, "] appended outbound with tag: ", o.OutboundConfigs[i].Tag)
  428. } else {
  429. outboundPrepends = append(outboundPrepends, o.OutboundConfigs[i])
  430. errors.LogInfo(context.Background(), "[", fn, "] prepend outbound with tag: ", o.OutboundConfigs[i].Tag)
  431. }
  432. }
  433. }
  434. if !strings.Contains(strings.ToLower(fn), "tail") && len(outboundPrepends) > 0 {
  435. c.OutboundConfigs = append(outboundPrepends, c.OutboundConfigs...)
  436. }
  437. }
  438. }
  439. // Build implements Buildable.
  440. func (c *Config) Build() (*core.Config, error) {
  441. if err := PostProcessConfigureFile(c); err != nil {
  442. return nil, err
  443. }
  444. config := &core.Config{
  445. App: []*serial.TypedMessage{
  446. serial.ToTypedMessage(&dispatcher.Config{}),
  447. serial.ToTypedMessage(&proxyman.InboundConfig{}),
  448. serial.ToTypedMessage(&proxyman.OutboundConfig{}),
  449. },
  450. }
  451. if c.API != nil {
  452. apiConf, err := c.API.Build()
  453. if err != nil {
  454. return nil, err
  455. }
  456. config.App = append(config.App, serial.ToTypedMessage(apiConf))
  457. }
  458. if c.Metrics != nil {
  459. metricsConf, err := c.Metrics.Build()
  460. if err != nil {
  461. return nil, err
  462. }
  463. config.App = append(config.App, serial.ToTypedMessage(metricsConf))
  464. }
  465. if c.Stats != nil {
  466. statsConf, err := c.Stats.Build()
  467. if err != nil {
  468. return nil, err
  469. }
  470. config.App = append(config.App, serial.ToTypedMessage(statsConf))
  471. }
  472. var logConfMsg *serial.TypedMessage
  473. if c.LogConfig != nil {
  474. logConfMsg = serial.ToTypedMessage(c.LogConfig.Build())
  475. } else {
  476. logConfMsg = serial.ToTypedMessage(DefaultLogConfig())
  477. }
  478. // let logger module be the first App to start,
  479. // so that other modules could print log during initiating
  480. config.App = append([]*serial.TypedMessage{logConfMsg}, config.App...)
  481. if c.RouterConfig != nil {
  482. routerConfig, err := c.RouterConfig.Build()
  483. if err != nil {
  484. return nil, err
  485. }
  486. config.App = append(config.App, serial.ToTypedMessage(routerConfig))
  487. }
  488. if c.DNSConfig != nil {
  489. dnsApp, err := c.DNSConfig.Build()
  490. if err != nil {
  491. return nil, errors.New("failed to parse DNS config").Base(err)
  492. }
  493. config.App = append(config.App, serial.ToTypedMessage(dnsApp))
  494. }
  495. if c.Policy != nil {
  496. pc, err := c.Policy.Build()
  497. if err != nil {
  498. return nil, err
  499. }
  500. config.App = append(config.App, serial.ToTypedMessage(pc))
  501. }
  502. if c.Reverse != nil {
  503. r, err := c.Reverse.Build()
  504. if err != nil {
  505. return nil, err
  506. }
  507. config.App = append(config.App, serial.ToTypedMessage(r))
  508. }
  509. if c.FakeDNS != nil {
  510. r, err := c.FakeDNS.Build()
  511. if err != nil {
  512. return nil, err
  513. }
  514. config.App = append([]*serial.TypedMessage{serial.ToTypedMessage(r)}, config.App...)
  515. }
  516. if c.Observatory != nil {
  517. r, err := c.Observatory.Build()
  518. if err != nil {
  519. return nil, err
  520. }
  521. config.App = append(config.App, serial.ToTypedMessage(r))
  522. }
  523. if c.BurstObservatory != nil {
  524. r, err := c.BurstObservatory.Build()
  525. if err != nil {
  526. return nil, err
  527. }
  528. config.App = append(config.App, serial.ToTypedMessage(r))
  529. }
  530. var inbounds []InboundDetourConfig
  531. if len(c.InboundConfigs) > 0 {
  532. inbounds = append(inbounds, c.InboundConfigs...)
  533. }
  534. if len(c.Transport) > 0 {
  535. return nil, errors.PrintRemovedFeatureError("Global transport config", "streamSettings in inbounds and outbounds")
  536. }
  537. for _, rawInboundConfig := range inbounds {
  538. ic, err := rawInboundConfig.Build()
  539. if err != nil {
  540. return nil, err
  541. }
  542. config.Inbound = append(config.Inbound, ic)
  543. }
  544. var outbounds []OutboundDetourConfig
  545. if len(c.OutboundConfigs) > 0 {
  546. outbounds = append(outbounds, c.OutboundConfigs...)
  547. }
  548. for _, rawOutboundConfig := range outbounds {
  549. oc, err := rawOutboundConfig.Build()
  550. if err != nil {
  551. return nil, err
  552. }
  553. config.Outbound = append(config.Outbound, oc)
  554. }
  555. return config, nil
  556. }
  557. // Convert string to Address.
  558. func ParseSendThough(Addr *string) *Address {
  559. var addr Address
  560. addr.Address = net.ParseAddress(strings.Split(*Addr, "/")[0])
  561. return &addr
  562. }