Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RPRX committed Nov 25, 2020
1 parent 47d23e9 commit c7f7c08
Show file tree
Hide file tree
Showing 711 changed files with 82,154 additions and 2 deletions.
373 changes: 373 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

54 changes: 52 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,52 @@
# X-ray
X-ray, Penetrate GFWs. The best v2ray-core, with XTLS support. Automatically patch and compile by GitHub Actions, fully compatible configuration.
# Project X

[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).

## Installation

- Linux script
- [Xray-install](https://github.com/XTLS/Xray-install)

## Usage

[Xray-examples](https://github.com/XTLS/Xray-examples) / [VLESS-TCP-XTLS-WHATEVER](https://github.com/XTLS/Xray-examples/tree/main/VLESS-TCP-XTLS-WHATEVER)

## License

[Mozilla Public License Version 2.0](https://github.com/XTLS/Xray-core/main/LICENSE)

## Credits

This repo relies on the following third-party projects:

- Special thanks:
- [v2fly/v2ray-core](https://github.com/v2fly/v2ray-core)
- In production:
- [gorilla/websocket](https://github.com/gorilla/websocket)
- [lucas-clemente/quic-go](https://github.com/lucas-clemente/quic-go)
- [pires/go-proxyproto](https://github.com/pires/go-proxyproto)
- [seiflotfy/cuckoofilter](https://github.com/seiflotfy/cuckoofilter)
- [google/starlark-go](https://github.com/google/starlark-go)
- For testing only:
- [miekg/dns](https://github.com/miekg/dns)
- [h12w/socks](https://github.com/h12w/socks)

## Compilation

### Windows

```
go build -o xray.exe -trimpath -ldflags "-s -w -buildid=" ./main
```

### Linux / macOS

```
go build -o xray -trimpath -ldflags "-s -w -buildid=" ./main
```

## Telegram

[Project X](https://t.me/projectXray)

[Project X Channel](https://t.me/projectXtls)
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package app contains feature implementations of Xray. The features may be enabled during runtime.
package app
110 changes: 110 additions & 0 deletions app/commander/commander.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// +build !confonly

package commander

//go:generate go run github.com/xtls/xray-core/v1/common/errors/errorgen

import (
"context"
"net"
"sync"

"google.golang.org/grpc"

"github.com/xtls/xray-core/v1/common"
"github.com/xtls/xray-core/v1/common/signal/done"
core "github.com/xtls/xray-core/v1/core"
"github.com/xtls/xray-core/v1/features/outbound"
)

// Commander is a Xray feature that provides gRPC methods to external clients.
type Commander struct {
sync.Mutex
server *grpc.Server
services []Service
ohm outbound.Manager
tag string
}

// NewCommander creates a new Commander based on the given config.
func NewCommander(ctx context.Context, config *Config) (*Commander, error) {
c := &Commander{
tag: config.Tag,
}

common.Must(core.RequireFeatures(ctx, func(om outbound.Manager) {
c.ohm = om
}))

for _, rawConfig := range config.Service {
config, err := rawConfig.GetInstance()
if err != nil {
return nil, err
}
rawService, err := common.CreateObject(ctx, config)
if err != nil {
return nil, err
}
service, ok := rawService.(Service)
if !ok {
return nil, newError("not a Service.")
}
c.services = append(c.services, service)
}

return c, nil
}

// Type implements common.HasType.
func (c *Commander) Type() interface{} {
return (*Commander)(nil)
}

// Start implements common.Runnable.
func (c *Commander) Start() error {
c.Lock()
c.server = grpc.NewServer()
for _, service := range c.services {
service.Register(c.server)
}
c.Unlock()

listener := &OutboundListener{
buffer: make(chan net.Conn, 4),
done: done.New(),
}

go func() {
if err := c.server.Serve(listener); err != nil {
newError("failed to start grpc server").Base(err).AtError().WriteToLog()
}
}()

if err := c.ohm.RemoveHandler(context.Background(), c.tag); err != nil {
newError("failed to remove existing handler").WriteToLog()
}

return c.ohm.AddHandler(context.Background(), &Outbound{
tag: c.tag,
listener: listener,
})
}

// Close implements common.Closable.
func (c *Commander) Close() error {
c.Lock()
defer c.Unlock()

if c.server != nil {
c.server.Stop()
c.server = nil
}

return nil
}

func init() {
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, cfg interface{}) (interface{}, error) {
return NewCommander(ctx, cfg.(*Config))
}))
}
227 changes: 227 additions & 0 deletions app/commander/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c7f7c08

Please sign in to comment.