Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add custom user-agent #199

Open
wants to merge 14 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func StartCmd() *cobra.Command {
return err
}

return n.Start()
return n.Start(home)
},
}

Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ require (
github.com/spf13/viper v1.18.2
github.com/tendermint/tendermint v0.34.27
github.com/v2fly/v2ray-core/v5 v5.13.0
golang.org/x/crypto v0.17.0
google.golang.org/grpc v1.60.0
google.golang.org/protobuf v1.31.0
golang.org/x/crypto v0.18.0
google.golang.org/grpc v1.61.0
google.golang.org/protobuf v1.32.0
gorm.io/driver/sqlite v1.5.4
gorm.io/gorm v1.25.5
)
Expand Down Expand Up @@ -68,7 +68,7 @@ require (
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/dgryski/go-metro v0.0.0-20211217172704-adc40b04c140 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dvsekhvalnov/jose2go v1.5.0 // indirect
github.com/dvsekhvalnov/jose2go v1.6.0 // indirect
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
Expand Down Expand Up @@ -165,8 +165,8 @@ require (
golang.org/x/arch v0.6.0 // indirect
golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto v0.0.0-20231211222908-989df2bf70f3 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231120223509-83a465c0220f // indirect
Expand Down
24 changes: 12 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:Htrtb
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/dvsekhvalnov/jose2go v1.5.0 h1:3j8ya4Z4kMCwT5nXIKFSV84YS+HdqSSO0VsTQxaLAeM=
github.com/dvsekhvalnov/jose2go v1.5.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU=
github.com/dvsekhvalnov/jose2go v1.6.0 h1:Y9gnSnP4qEI0+/uQkHvFXeD2PLPJeXEL+ySMEA2EjTY=
github.com/dvsekhvalnov/jose2go v1.6.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
Expand Down Expand Up @@ -1187,8 +1187,8 @@ golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWP
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -1354,12 +1354,12 @@ golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE=
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
Expand Down Expand Up @@ -1495,8 +1495,8 @@ google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3Iji
google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
google.golang.org/grpc v1.60.0 h1:6FQAR0kM31P6MRdeluor2w2gPaS4SVNrD/DNTxrQ15k=
google.golang.org/grpc v1.60.0/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM=
google.golang.org/grpc v1.61.0 h1:TOvOcuXn30kRao+gfcvsebNEa5iZIiLkisYEkf7R7o0=
google.golang.org/grpc v1.61.0/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand All @@ -1509,8 +1509,8 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
30 changes: 30 additions & 0 deletions lite/client.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
package lite

import (
"fmt"

"io"
"net/http"
"sync"
"time"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/version"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
tmlog "github.com/tendermint/tendermint/libs/log"
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
jsonrpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
)

type Client struct {
Expand Down Expand Up @@ -151,3 +158,26 @@ func (c *Client) FromAddress() sdk.AccAddress { return c.ctx.FromAddress }
func (c *Client) FromName() string { return c.ctx.FromName }
func (c *Client) SimulateAndExecute() bool { return c.txf.SimulateAndExecute() }
func (c *Client) TxConfig() client.TxConfig { return c.ctx.TxConfig }

type AddHeaderTransport struct {
T http.RoundTripper
}

func (adt *AddHeaderTransport) RoundTrip(req *http.Request) (*http.Response, error) {
verInfo := version.NewInfo()

req.Header.Add("User-Agent", fmt.Sprintf("sentinel-dvpn-node/v%s", verInfo.Version))
return adt.T.RoundTrip(req)
}

func (c *Client) GetHttpClient(remote string, timeout uint) (*rpchttp.HTTP, error) {
httpClient, err := jsonrpcclient.DefaultHTTPClient(remote)
if err != nil {
return nil, err
}

httpClient.Timeout = time.Duration(timeout) * time.Second
httpClient.Transport = &AddHeaderTransport{T: httpClient.Transport}

return rpchttp.NewWithClient(remote, "/websocket", httpClient)
}
13 changes: 6 additions & 7 deletions lite/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ import (
sessiontypes "github.com/sentinel-official/hub/x/session/types"
subscriptiontypes "github.com/sentinel-official/hub/x/subscription/types"
vpntypes "github.com/sentinel-official/hub/x/vpn/types"
rpchttp "github.com/tendermint/tendermint/rpc/client/http"

"github.com/sentinel-official/dvpn-node/types"
)

func (c *Client) queryAccount(remote string, accAddr sdk.AccAddress) (authtypes.AccountI, error) {
c.log.Debug("Querying the account", "remote", remote, "address", accAddr)

client, err := rpchttp.NewWithTimeout(remote, "/websocket", c.queryTimeout)
client, err := c.GetHttpClient(remote, c.queryTimeout)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -64,7 +63,7 @@ func (c *Client) QueryAccount(accAddr sdk.AccAddress) (result authtypes.AccountI
func (c *Client) queryNode(remote string, nodeAddr hubtypes.NodeAddress) (*nodetypes.Node, error) {
c.log.Debug("Querying the node", "remote", remote, "address", nodeAddr)

client, err := rpchttp.NewWithTimeout(remote, "/websocket", c.queryTimeout)
client, err := c.GetHttpClient(remote, c.queryTimeout)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -103,7 +102,7 @@ func (c *Client) QueryNode(nodeAddr hubtypes.NodeAddress) (result *nodetypes.Nod
func (c *Client) querySubscription(remote string, id uint64) (subscriptiontypes.Subscription, error) {
c.log.Debug("Querying the subscription", "remote", remote, "id", id)

client, err := rpchttp.NewWithTimeout(remote, "/websocket", c.queryTimeout)
client, err := c.GetHttpClient(remote, c.queryTimeout)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -147,7 +146,7 @@ func (c *Client) QuerySubscription(id uint64) (result subscriptiontypes.Subscrip
func (c *Client) queryAllocation(remote string, id uint64, accAddr sdk.AccAddress) (*subscriptiontypes.Allocation, error) {
c.log.Debug("Querying the allocation", "remote", remote, "id", id, "address", accAddr)

client, err := rpchttp.NewWithTimeout(remote, "/websocket", c.queryTimeout)
client, err := c.GetHttpClient(remote, c.queryTimeout)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -186,7 +185,7 @@ func (c *Client) QueryAllocation(id uint64, accAddr sdk.AccAddress) (result *sub
func (c *Client) querySession(remote string, id uint64) (*sessiontypes.Session, error) {
c.log.Debug("Querying the session", "remote", remote, "id", id)

client, err := rpchttp.NewWithTimeout(remote, "/websocket", c.queryTimeout)
client, err := c.GetHttpClient(remote, c.queryTimeout)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -223,7 +222,7 @@ func (c *Client) QuerySession(id uint64) (result *sessiontypes.Session, err erro
}

func (c *Client) hasNodeForPlan(remote string, id uint64, nodeAddr hubtypes.NodeAddress) (bool, error) {
client, err := rpchttp.NewWithTimeout(remote, "/websocket", c.queryTimeout)
client, err := c.GetHttpClient(remote, c.queryTimeout)
if err != nil {
return false, err
}
Expand Down
5 changes: 2 additions & 3 deletions lite/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/pkg/errors"
abcitypes "github.com/tendermint/tendermint/abci/types"
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
)

func (c *Client) broadcastTx(remote string, txBytes []byte) (*sdk.TxResponse, error) {
c.log.Debug("Broadcasting the transaction", "remote", remote, "size", len(txBytes))

client, err := rpchttp.NewWithTimeout(remote, "/websocket", c.txTimeout)
client, err := c.GetHttpClient(remote, c.txTimeout)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -58,7 +57,7 @@ func (c *Client) BroadcastTx(txBytes []byte) (res *sdk.TxResponse, err error) {
func (c *Client) calculateGas(remote string, txf tx.Factory, messages ...sdk.Msg) (uint64, error) {
c.log.Debug("Calculating the gas", "remote", remote, "messages", len(messages))

client, err := rpchttp.NewWithTimeout(remote, "/websocket", c.txTimeout)
client, err := c.GetHttpClient(remote, c.txTimeout)
if err != nil {
return 0, err
}
Expand Down
9 changes: 3 additions & 6 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package node
import (
"path"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/viper"

"github.com/sentinel-official/dvpn-node/context"
"github.com/sentinel-official/dvpn-node/utils"
)
Expand Down Expand Up @@ -33,7 +30,7 @@ func (n *Node) Initialize() error {
return n.UpdateNodeInfo()
}

func (n *Node) Start() error {
func (n *Node) Start(home string) error {
go func() {
if err := n.jobSetSessions(); err != nil {
panic(err)
Expand All @@ -53,8 +50,8 @@ func (n *Node) Start() error {
}()

var (
certFile = path.Join(viper.GetString(flags.FlagHome), "tls.crt")
keyFile = path.Join(viper.GetString(flags.FlagHome), "tls.key")
certFile = path.Join(home, "tls.crt")
keyFile = path.Join(home, "tls.key")
)

return utils.ListenAndServeTLS(
Expand Down
12 changes: 11 additions & 1 deletion services/v2ray/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@ var (
"port": "{{ .VMess.ListenPort }}",
"protocol": "vmess",
"streamSettings": {
"network": "{{ .VMess.Transport }}"
"network": "{{ .VMess.Transport }}",
"security": "{{ .VMess.Security }}",
"tlsSettings": {
"allowInsecure": true,
"certificates": [
{
"certificateFile": "{{ .VMess.TLSCertPath }}",
"keyFile": "{{ .VMess.TLSKeyPath }}"
}
]
}
},
"tag": "vmess"
}
Expand Down
12 changes: 11 additions & 1 deletion services/v2ray/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
"bytes"
"fmt"
"os"
"strings"
"text/template"
Expand All @@ -18,6 +19,9 @@ var (
# Port number to accept the incoming connections
listen_port = {{ .VMess.ListenPort }}

# Enable or disable TLS for secure connections
tls = {{ .VMess.TLS }}

# Name of the transport protocol
transport = "{{ .VMess.Transport }}"
`)
Expand All @@ -33,7 +37,12 @@ transport = "{{ .VMess.Transport }}"
)

type VMessConfig struct {
Security string `json:"security"`
TLSCertPath string `json:"tls_cert_path"`
TLSKeyPath string `json:"tls_key_path"`

ListenPort uint16 `json:"listen_port" mapstructure:"listen_port"`
TLS bool `json:"tls" mapstructure:"tls"`
Transport string `json:"transport" mapstructure:"transport"`
}

Expand All @@ -43,6 +52,7 @@ func NewVMessConfig() *VMessConfig {

func (c *VMessConfig) WithDefaultValues() *VMessConfig {
c.ListenPort = utils.RandomPort()
c.TLS = false
c.Transport = "grpc"

return c
Expand All @@ -58,7 +68,7 @@ func (c *VMessConfig) Validate() error {

t := NewTransportFromString(c.Transport)
if !t.IsValid() {
return errors.New("invalid transport")
return fmt.Errorf("invalid transport %s", c.Transport)
}

return nil
Expand Down
14 changes: 13 additions & 1 deletion services/v2ray/v2ray.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ import (

v2raytypes "github.com/sentinel-official/dvpn-node/services/v2ray/types"
"github.com/sentinel-official/dvpn-node/types"
"github.com/sentinel-official/dvpn-node/utils"
)

const (
InfoLen = 2 + 1
InfoLen = 2 + 1 + 1
)

var (
Expand Down Expand Up @@ -74,6 +75,12 @@ func (s *V2Ray) Init(home string) (err error) {
return err
}

if s.config.VMess.TLS {
s.config.VMess.Security = "tls"
}
s.config.VMess.TLSCertPath = filepath.Join(home, "tls.crt")
s.config.VMess.TLSKeyPath = filepath.Join(home, "tls.key")

t, err := template.New("v2ray_json").Parse(configTemplate)
if err != nil {
return err
Expand All @@ -90,13 +97,18 @@ func (s *V2Ray) Init(home string) (err error) {
binary.BigEndian.PutUint16(s.info[0:], s.config.VMess.ListenPort)
transport := v2raytypes.NewTransportFromString(s.config.VMess.Transport)
s.info[2] = transport.Byte()
s.info[3] = utils.ByteFromBool(s.config.VMess.TLS)

return nil
}

func (s *V2Ray) Start() error {
s.cmd = exec.Command("v2ray", strings.Split(
fmt.Sprintf("run --config %s", s.configFilePath()), " ")...)

s.cmd.Env = os.Environ()
s.cmd.Env = append(s.cmd.Env, "V2RAY_VMESS_AEAD_FORCED=false")

s.cmd.Stdout = os.Stdout
s.cmd.Stderr = os.Stderr

Expand Down
9 changes: 9 additions & 0 deletions utils/cast.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package utils

func ByteFromBool(v bool) byte {
if v {
return 0x01
}

return 0x00
}