Skip to content

Commit c7f7c08

Browse files
committed
v1.0.0
1 parent 47d23e9 commit c7f7c08

File tree

711 files changed

+82154
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

711 files changed

+82154
-2
lines changed

LICENSE

+373
Large diffs are not rendered by default.

README.md

+52-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,52 @@
1-
# X-ray
2-
X-ray, Penetrate GFWs. The best v2ray-core, with XTLS support. Automatically patch and compile by GitHub Actions, fully compatible configuration.
1+
# Project X
2+
3+
[Project X](https://github.com/XTLS) originates from XTLS protocol, provides a set of network tools such as [Xray-core](https://github.com/XTLS/Xray-core) and [Xray-flutter](https://github.com/XTLS/Xray-flutter).
4+
5+
## Installation
6+
7+
- Linux script
8+
- [Xray-install](https://github.com/XTLS/Xray-install)
9+
10+
## Usage
11+
12+
[Xray-examples](https://github.com/XTLS/Xray-examples) / [VLESS-TCP-XTLS-WHATEVER](https://github.com/XTLS/Xray-examples/tree/main/VLESS-TCP-XTLS-WHATEVER)
13+
14+
## License
15+
16+
[Mozilla Public License Version 2.0](https://github.com/XTLS/Xray-core/main/LICENSE)
17+
18+
## Credits
19+
20+
This repo relies on the following third-party projects:
21+
22+
- Special thanks:
23+
- [v2fly/v2ray-core](https://github.com/v2fly/v2ray-core)
24+
- In production:
25+
- [gorilla/websocket](https://github.com/gorilla/websocket)
26+
- [lucas-clemente/quic-go](https://github.com/lucas-clemente/quic-go)
27+
- [pires/go-proxyproto](https://github.com/pires/go-proxyproto)
28+
- [seiflotfy/cuckoofilter](https://github.com/seiflotfy/cuckoofilter)
29+
- [google/starlark-go](https://github.com/google/starlark-go)
30+
- For testing only:
31+
- [miekg/dns](https://github.com/miekg/dns)
32+
- [h12w/socks](https://github.com/h12w/socks)
33+
34+
## Compilation
35+
36+
### Windows
37+
38+
```
39+
go build -o xray.exe -trimpath -ldflags "-s -w -buildid=" ./main
40+
```
41+
42+
### Linux / macOS
43+
44+
```
45+
go build -o xray -trimpath -ldflags "-s -w -buildid=" ./main
46+
```
47+
48+
## Telegram
49+
50+
[Project X](https://t.me/projectXray)
51+
52+
[Project X Channel](https://t.me/projectXtls)

app/app.go

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package app contains feature implementations of Xray. The features may be enabled during runtime.
2+
package app

app/commander/commander.go

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// +build !confonly
2+
3+
package commander
4+
5+
//go:generate go run github.com/xtls/xray-core/v1/common/errors/errorgen
6+
7+
import (
8+
"context"
9+
"net"
10+
"sync"
11+
12+
"google.golang.org/grpc"
13+
14+
"github.com/xtls/xray-core/v1/common"
15+
"github.com/xtls/xray-core/v1/common/signal/done"
16+
core "github.com/xtls/xray-core/v1/core"
17+
"github.com/xtls/xray-core/v1/features/outbound"
18+
)
19+
20+
// Commander is a Xray feature that provides gRPC methods to external clients.
21+
type Commander struct {
22+
sync.Mutex
23+
server *grpc.Server
24+
services []Service
25+
ohm outbound.Manager
26+
tag string
27+
}
28+
29+
// NewCommander creates a new Commander based on the given config.
30+
func NewCommander(ctx context.Context, config *Config) (*Commander, error) {
31+
c := &Commander{
32+
tag: config.Tag,
33+
}
34+
35+
common.Must(core.RequireFeatures(ctx, func(om outbound.Manager) {
36+
c.ohm = om
37+
}))
38+
39+
for _, rawConfig := range config.Service {
40+
config, err := rawConfig.GetInstance()
41+
if err != nil {
42+
return nil, err
43+
}
44+
rawService, err := common.CreateObject(ctx, config)
45+
if err != nil {
46+
return nil, err
47+
}
48+
service, ok := rawService.(Service)
49+
if !ok {
50+
return nil, newError("not a Service.")
51+
}
52+
c.services = append(c.services, service)
53+
}
54+
55+
return c, nil
56+
}
57+
58+
// Type implements common.HasType.
59+
func (c *Commander) Type() interface{} {
60+
return (*Commander)(nil)
61+
}
62+
63+
// Start implements common.Runnable.
64+
func (c *Commander) Start() error {
65+
c.Lock()
66+
c.server = grpc.NewServer()
67+
for _, service := range c.services {
68+
service.Register(c.server)
69+
}
70+
c.Unlock()
71+
72+
listener := &OutboundListener{
73+
buffer: make(chan net.Conn, 4),
74+
done: done.New(),
75+
}
76+
77+
go func() {
78+
if err := c.server.Serve(listener); err != nil {
79+
newError("failed to start grpc server").Base(err).AtError().WriteToLog()
80+
}
81+
}()
82+
83+
if err := c.ohm.RemoveHandler(context.Background(), c.tag); err != nil {
84+
newError("failed to remove existing handler").WriteToLog()
85+
}
86+
87+
return c.ohm.AddHandler(context.Background(), &Outbound{
88+
tag: c.tag,
89+
listener: listener,
90+
})
91+
}
92+
93+
// Close implements common.Closable.
94+
func (c *Commander) Close() error {
95+
c.Lock()
96+
defer c.Unlock()
97+
98+
if c.server != nil {
99+
c.server.Stop()
100+
c.server = nil
101+
}
102+
103+
return nil
104+
}
105+
106+
func init() {
107+
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, cfg interface{}) (interface{}, error) {
108+
return NewCommander(ctx, cfg.(*Config))
109+
}))
110+
}

app/commander/config.pb.go

+227
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)