mirror of
https://github.com/p4gefau1t/trojan-go.git
synced 2026-10-19 16:15:38 +00:00
auto versioning
This commit is contained in:
+10
-2
@@ -31,11 +31,19 @@ wget https://github.com/v2ray/geoip/raw/release/geoip.dat -O geoip.dat
|
||||
SCRIPT_NAME=`basename "$0"`
|
||||
FAILURES=""
|
||||
|
||||
PACKAGE_NAME="github.com/p4gefau1t/trojan-go"
|
||||
VERSION=`git describe`
|
||||
COMMIT=`git rev-parse HEAD`
|
||||
|
||||
VAR_SETTING=""
|
||||
VAR_SETTING="$VAR_SETTING -X $PACKAGE_NAME/constant.Version=$VERSION"
|
||||
VAR_SETTING="$VAR_SETTING -X $PACKAGE_NAME/constant.Commit=$COMMIT"
|
||||
|
||||
for PLATFORM in $PLATFORMS; do
|
||||
GOOS=${PLATFORM%/*}
|
||||
GOARCH=${PLATFORM#*/}
|
||||
ZIP_FILENAME="trojan-go-${GOOS}-${GOARCH}.zip"
|
||||
CMD="CGO_ENABLE=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -tags \"full\" -o temp -ldflags=\"-s -w\""
|
||||
CMD="CGO_ENABLE=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -tags \"full\" -o temp -ldflags=\"-s -w ${VAR_SETTING}\""
|
||||
echo "${CMD}"
|
||||
eval $CMD || FAILURES="${FAILURES} ${PLATFORM}"
|
||||
zip -j release/$ZIP_FILENAME temp/* ./*.dat
|
||||
@@ -51,7 +59,7 @@ for GOOS in $PLATFORMS_ARM; do
|
||||
GOARCH="arm"
|
||||
for GOARM in 7 6 5; do
|
||||
ZIP_FILENAME="trojan-go-${GOOS}-${GOARCH}v${GOARM}.zip"
|
||||
CMD="CGO_ENABLE=0 GOARM=${GOARM} GOOS=${GOOS} GOARCH=${GOARCH} go build -tags \"full\" -o temp -ldflags \"-s -w\""
|
||||
CMD="CGO_ENABLE=0 GOARM=${GOARM} GOOS=${GOOS} GOARCH=${GOARCH} go build -tags \"full\" -o temp -ldflags \"-s -w ${VAR_SETTING}\""
|
||||
echo "${CMD}"
|
||||
eval "${CMD}" || FAILURES="${FAILURES} ${GOOS}/${GOARCH}v${GOARM}"
|
||||
zip -j release/$ZIP_FILENAME temp/* ./*.dat
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
CGO_ENABLE=0 go build -tags "full" -ldflags="-s -w"
|
||||
PACKAGE_NAME="github.com/p4gefau1t/trojan-go"
|
||||
VERSION=`git describe`
|
||||
COMMIT=`git rev-parse HEAD`
|
||||
|
||||
VAR_SETTING=""
|
||||
VAR_SETTING="$VAR_SETTING -X $PACKAGE_NAME/constant.Version=$VERSION"
|
||||
VAR_SETTING="$VAR_SETTING -X $PACKAGE_NAME/constant.Commit=$COMMIT"
|
||||
|
||||
CGO_ENABLE=0 go build -tags "full" -ldflags="-s -w $VAR_SETTING"
|
||||
|
||||
@@ -1,31 +1,18 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const (
|
||||
Version = "v0.7.2"
|
||||
)
|
||||
|
||||
type Runnable interface {
|
||||
Run() error
|
||||
Close() error
|
||||
}
|
||||
|
||||
func NewBufioReadWriter(rw io.ReadWriter) *bufio.ReadWriter {
|
||||
if bufrw, ok := rw.(*bufio.ReadWriter); ok {
|
||||
return bufrw
|
||||
}
|
||||
return bufio.NewReadWriter(bufio.NewReader(rw), bufio.NewWriter(rw))
|
||||
}
|
||||
|
||||
func SHA224String(password string) string {
|
||||
hash := sha256.New224()
|
||||
hash.Write([]byte(password))
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package constant
|
||||
|
||||
var (
|
||||
Version = "VERSION"
|
||||
Commit = "COMMIT"
|
||||
)
|
||||
+1
-2
@@ -14,9 +14,8 @@ enableMissingTranslationPlaceholders = false
|
||||
[params]
|
||||
|
||||
# Source Code repository section
|
||||
description = "An unidentifiable mechanism that helps you bypass GFW. "
|
||||
description = "An unidentifiable mechanism that helps you bypass GFW."
|
||||
github_repository = "https://github.com/p4gefau1t/trojan-go"
|
||||
version = "0.7.2"
|
||||
|
||||
# Documentation repository section
|
||||
# documentation repository (set edit link to documentation repository)
|
||||
|
||||
+3
-1
@@ -2,6 +2,7 @@ package proxy
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"github.com/p4gefau1t/trojan-go/constant"
|
||||
"github.com/p4gefau1t/trojan-go/log"
|
||||
"github.com/p4gefau1t/trojan-go/option"
|
||||
"io/ioutil"
|
||||
@@ -24,11 +25,12 @@ func (o *Option) Handle() error {
|
||||
isJSON := false
|
||||
if strings.HasSuffix(*o.path, ".json") {
|
||||
isJSON = true
|
||||
} else if strings.HasSuffix(*o.path, ".yaml") {
|
||||
} else if strings.HasSuffix(*o.path, ".yaml") || strings.HasSuffix(*o.path, ".yml") {
|
||||
isJSON = false
|
||||
} else {
|
||||
log.Fatal("unsupported filename suffix", *o.path, ". use .yaml or .json instead.")
|
||||
}
|
||||
log.Info("trojan-go", constant.Version, "initializing")
|
||||
proxy, err := NewProxyFromConfigData(data, isJSON)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
@@ -2,6 +2,7 @@ package memory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/p4gefau1t/trojan-go/log"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@@ -235,6 +236,7 @@ func NewAuthenticator(ctx context.Context) (statistic.Authenticator, error) {
|
||||
hash := common.SHA224String(password)
|
||||
u.AddUser(hash)
|
||||
}
|
||||
log.Debug("memory authenticator created")
|
||||
return u, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ func (a *Authenticator) updater() {
|
||||
|
||||
s, err := a.db.Exec("UPDATE `users` SET `upload`=`upload`+?, `download`=`download`+? WHERE `password`=?;", recv, sent, hash)
|
||||
if err != nil {
|
||||
log.Error(common.NewError("Failed to update data to user").Base(err))
|
||||
log.Error(common.NewError("failed to update data to user table").Base(err))
|
||||
continue
|
||||
}
|
||||
if r, err := s.RowsAffected(); err != nil {
|
||||
@@ -45,12 +45,12 @@ func (a *Authenticator) updater() {
|
||||
}
|
||||
}
|
||||
}
|
||||
log.Info("Buffered data has been written into the database")
|
||||
log.Info("buffered data has been written into the database")
|
||||
|
||||
//update memory
|
||||
rows, err := a.db.Query("SELECT password,quota,download,upload FROM users")
|
||||
if err != nil {
|
||||
log.Error(common.NewError("Failed to pull data from the database").Base(err))
|
||||
log.Error(common.NewError("failed to pull data from the database").Base(err))
|
||||
time.Sleep(a.updateDuration)
|
||||
continue
|
||||
}
|
||||
@@ -59,7 +59,7 @@ func (a *Authenticator) updater() {
|
||||
var quota, download, upload int64
|
||||
err := rows.Scan(&hash, "a, &download, &upload)
|
||||
if err != nil {
|
||||
log.Error(common.NewError("Failed to obtain data from the query result").Base(err))
|
||||
log.Error(common.NewError("failed to obtain data from the query result").Base(err))
|
||||
break
|
||||
}
|
||||
if download+upload < quota || quota < 0 {
|
||||
@@ -107,6 +107,7 @@ func NewAuthenticator(ctx context.Context) (statistic.Authenticator, error) {
|
||||
Authenticator: memoryAuth.(*memory.Authenticator),
|
||||
}
|
||||
go a.updater()
|
||||
log.Debug("mysql authenticator created")
|
||||
return a, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package statistic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/p4gefau1t/trojan-go/log"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
@@ -53,6 +54,7 @@ func RegisterAuthenticatorCreator(name string, creator Creator) {
|
||||
func NewAuthenticator(ctx context.Context, name string) (Authenticator, error) {
|
||||
// one authenticator for each context
|
||||
if auth, found := createdAuth[ctx]; found {
|
||||
log.Debug("authenticator has been created:", name)
|
||||
return auth, nil
|
||||
}
|
||||
creator, found := authCreators[strings.ToUpper(name)]
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"github.com/p4gefau1t/trojan-go/api"
|
||||
"github.com/p4gefau1t/trojan-go/config"
|
||||
"github.com/p4gefau1t/trojan-go/statistic/memory"
|
||||
"github.com/p4gefau1t/trojan-go/tunnel/mux"
|
||||
"net"
|
||||
@@ -146,7 +147,10 @@ func NewClient(ctx context.Context, client tunnel.Client) (*Client, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go api.RunService(ctx, Name+"_CLIENT", auth)
|
||||
cfg := config.FromContext(ctx, Name).(*Config)
|
||||
if cfg.API.Enabled {
|
||||
go api.RunService(ctx, Name+"_CLIENT", auth)
|
||||
}
|
||||
|
||||
var user statistic.User
|
||||
for _, u := range auth.ListUsers() {
|
||||
|
||||
@@ -8,11 +8,16 @@ type Config struct {
|
||||
RemoteHost string `json:"remote_addr" yaml:"remote-addr"`
|
||||
RemotePort int `json:"remote_port" yaml:"remote-port"`
|
||||
DisableHTTPCheck bool `json:"disable_http_check" yaml:"disable-http-check"`
|
||||
MySQL MySQLConfig `json:"mysql" yaml:"mysql"`
|
||||
MySQL MySQLConfig `json,yaml:"mysql"`
|
||||
API APIConfig `json,yaml:"api"`
|
||||
}
|
||||
|
||||
type MySQLConfig struct {
|
||||
Enabled bool `json:"enabled" yaml:"enabled"`
|
||||
Enabled bool `json,yaml:"enabled"`
|
||||
}
|
||||
|
||||
type APIConfig struct {
|
||||
Enabled bool `json,yaml:"enabled"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
+13
-5
@@ -190,19 +190,27 @@ func (s *Server) AcceptPacket(tunnel.Tunnel) (tunnel.PacketConn, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func NewServer(ctx context.Context, underlay tunnel.Server) (tunnel.Server, error) {
|
||||
func NewServer(ctx context.Context, underlay tunnel.Server) (*Server, error) {
|
||||
cfg := config.FromContext(ctx, Name).(*Config)
|
||||
|
||||
// TODO replace this dirty code
|
||||
auth, err := statistic.NewAuthenticator(ctx, memory.Name)
|
||||
var auth statistic.Authenticator
|
||||
var err error
|
||||
if cfg.MySQL.Enabled {
|
||||
log.Debug("mysql enabled")
|
||||
auth, err = statistic.NewAuthenticator(ctx, mysql.Name)
|
||||
} else {
|
||||
log.Debug("auth by config file")
|
||||
auth, err = statistic.NewAuthenticator(ctx, memory.Name)
|
||||
}
|
||||
go api.RunService(ctx, Name+"_SERVER", auth)
|
||||
|
||||
if err != nil {
|
||||
return nil, common.NewError("failed to create authenticator").Base(err)
|
||||
return nil, common.NewError("trojan failed to create authenticator")
|
||||
}
|
||||
|
||||
if cfg.API.Enabled {
|
||||
go api.RunService(ctx, Name+"_SERVER", auth)
|
||||
}
|
||||
|
||||
redirAddr := tunnel.NewAddressFromHostPort("tcp", cfg.RemoteHost, cfg.RemotePort)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
s := &Server{
|
||||
|
||||
+6
-1
@@ -3,6 +3,7 @@ package version
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/p4gefau1t/trojan-go/constant"
|
||||
"github.com/p4gefau1t/trojan-go/option"
|
||||
"runtime"
|
||||
|
||||
@@ -23,7 +24,11 @@ func (*versionOption) Priority() int {
|
||||
|
||||
func (c *versionOption) Handle() error {
|
||||
if *c.flag {
|
||||
fmt.Println("Trojan-Go", common.Version, fmt.Sprintf("(%s %s/%s)", runtime.Version(), runtime.GOOS, runtime.GOARCH))
|
||||
fmt.Println("Trojan-Go", constant.Version)
|
||||
fmt.Println("Go Version:", runtime.Version())
|
||||
fmt.Println("OS/Arch:", runtime.GOOS+"/"+runtime.GOARCH)
|
||||
fmt.Println("Git Commit:", constant.Commit)
|
||||
fmt.Println("")
|
||||
fmt.Println("Developed by PageFault (p4gefau1t)")
|
||||
fmt.Println("Licensed under GNU General Public License version 3")
|
||||
fmt.Println("GitHub Repository:\thttps://github.com/p4gefau1t/trojan-go")
|
||||
|
||||
Reference in New Issue
Block a user