mirror of https://github.com/ehang-io/nps
style: fmt
parent
5fcbeb60aa
commit
b0d16d3b3d
|
@ -4,6 +4,15 @@ import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego"
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
"github.com/cnlh/nps/lib/common"
|
"github.com/cnlh/nps/lib/common"
|
||||||
"github.com/cnlh/nps/lib/conn"
|
"github.com/cnlh/nps/lib/conn"
|
||||||
"github.com/cnlh/nps/lib/crypt"
|
"github.com/cnlh/nps/lib/crypt"
|
||||||
|
@ -12,14 +21,6 @@ import (
|
||||||
"github.com/cnlh/nps/lib/version"
|
"github.com/cnlh/nps/lib/version"
|
||||||
"github.com/cnlh/nps/server/connection"
|
"github.com/cnlh/nps/server/connection"
|
||||||
"github.com/cnlh/nps/server/tool"
|
"github.com/cnlh/nps/server/tool"
|
||||||
"github.com/astaxie/beego"
|
|
||||||
"github.com/astaxie/beego/logs"
|
|
||||||
"net"
|
|
||||||
"os"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
|
@ -146,7 +147,7 @@ func (s *Bridge) GetHealthFromClient(id int, c *conn.Conn) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s.DelClient(id, )
|
s.DelClient(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
//验证失败,返回错误验证flag,并且关闭连接
|
//验证失败,返回错误验证flag,并且关闭连接
|
||||||
|
|
|
@ -2,17 +2,18 @@ package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
"github.com/cnlh/nps/lib/common"
|
"github.com/cnlh/nps/lib/common"
|
||||||
"github.com/cnlh/nps/lib/config"
|
"github.com/cnlh/nps/lib/config"
|
||||||
"github.com/cnlh/nps/lib/conn"
|
"github.com/cnlh/nps/lib/conn"
|
||||||
"github.com/cnlh/nps/lib/crypt"
|
"github.com/cnlh/nps/lib/crypt"
|
||||||
"github.com/cnlh/nps/lib/mux"
|
"github.com/cnlh/nps/lib/mux"
|
||||||
"github.com/astaxie/beego/logs"
|
|
||||||
"github.com/xtaci/kcp-go"
|
"github.com/xtaci/kcp-go"
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type TRPClient struct {
|
type TRPClient struct {
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cnlh/nps/lib/common"
|
|
||||||
conn2 "github.com/cnlh/nps/lib/conn"
|
|
||||||
"github.com/cnlh/nps/lib/file"
|
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/cnlh/nps/lib/common"
|
||||||
|
conn2 "github.com/cnlh/nps/lib/conn"
|
||||||
|
"github.com/cnlh/nps/lib/file"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConfig(t *testing.T) {
|
func TestConfig(t *testing.T) {
|
||||||
|
|
|
@ -5,14 +5,6 @@ import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/cnlh/nps/lib/common"
|
|
||||||
"github.com/cnlh/nps/lib/config"
|
|
||||||
"github.com/cnlh/nps/lib/conn"
|
|
||||||
"github.com/cnlh/nps/lib/crypt"
|
|
||||||
"github.com/cnlh/nps/lib/version"
|
|
||||||
"github.com/astaxie/beego/logs"
|
|
||||||
"github.com/xtaci/kcp-go"
|
|
||||||
"golang.org/x/net/proxy"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
|
@ -26,6 +18,15 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
|
"github.com/cnlh/nps/lib/common"
|
||||||
|
"github.com/cnlh/nps/lib/config"
|
||||||
|
"github.com/cnlh/nps/lib/conn"
|
||||||
|
"github.com/cnlh/nps/lib/crypt"
|
||||||
|
"github.com/cnlh/nps/lib/version"
|
||||||
|
"github.com/xtaci/kcp-go"
|
||||||
|
"golang.org/x/net/proxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetTaskStatus(path string) {
|
func GetTaskStatus(path string) {
|
||||||
|
@ -379,7 +380,7 @@ func sendP2PTestMsg(localConn *net.UDPConn, remoteAddr1, remoteAddr2, remoteAddr
|
||||||
ip := common.GetIpByAddr(remoteAddr2)
|
ip := common.GetIpByAddr(remoteAddr2)
|
||||||
go func() {
|
go func() {
|
||||||
ports := getRandomPortArr(common.GetPortByAddr(remoteAddr3), common.GetPortByAddr(remoteAddr3)+interval*50)
|
ports := getRandomPortArr(common.GetPortByAddr(remoteAddr3), common.GetPortByAddr(remoteAddr3)+interval*50)
|
||||||
for i := 0; i <= 50; i ++ {
|
for i := 0; i <= 50; i++ {
|
||||||
go func(port int) {
|
go func(port int) {
|
||||||
trueAddress := ip + ":" + strconv.Itoa(port)
|
trueAddress := ip + ":" + strconv.Itoa(port)
|
||||||
logs.Trace("try send test packet to target %s", trueAddress)
|
logs.Trace("try send test packet to target %s", trueAddress)
|
||||||
|
|
|
@ -2,15 +2,16 @@ package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"container/heap"
|
"container/heap"
|
||||||
"github.com/cnlh/nps/lib/conn"
|
|
||||||
"github.com/cnlh/nps/lib/file"
|
|
||||||
"github.com/cnlh/nps/lib/sheap"
|
|
||||||
"github.com/astaxie/beego/logs"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
|
"github.com/cnlh/nps/lib/conn"
|
||||||
|
"github.com/cnlh/nps/lib/file"
|
||||||
|
"github.com/cnlh/nps/lib/sheap"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
var isStart bool
|
var isStart bool
|
||||||
|
@ -70,7 +71,7 @@ func check(t *file.Health) {
|
||||||
var rs *http.Response
|
var rs *http.Response
|
||||||
for _, v := range arr {
|
for _, v := range arr {
|
||||||
if t.HealthCheckType == "tcp" {
|
if t.HealthCheckType == "tcp" {
|
||||||
_, err = net.DialTimeout("tcp", v, time.Duration(t.HealthCheckTimeout)*time.Second);
|
_, err = net.DialTimeout("tcp", v, time.Duration(t.HealthCheckTimeout)*time.Second)
|
||||||
} else {
|
} else {
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
client.Timeout = time.Duration(t.HealthCheckTimeout) * time.Second
|
client.Timeout = time.Duration(t.HealthCheckTimeout) * time.Second
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
"github.com/cnlh/nps/lib/common"
|
"github.com/cnlh/nps/lib/common"
|
||||||
"github.com/cnlh/nps/lib/config"
|
"github.com/cnlh/nps/lib/config"
|
||||||
"github.com/cnlh/nps/lib/conn"
|
"github.com/cnlh/nps/lib/conn"
|
||||||
|
@ -8,12 +14,7 @@ import (
|
||||||
"github.com/cnlh/nps/lib/file"
|
"github.com/cnlh/nps/lib/file"
|
||||||
"github.com/cnlh/nps/lib/mux"
|
"github.com/cnlh/nps/lib/mux"
|
||||||
"github.com/cnlh/nps/server/proxy"
|
"github.com/cnlh/nps/server/proxy"
|
||||||
"github.com/astaxie/beego/logs"
|
|
||||||
"github.com/xtaci/kcp-go"
|
"github.com/xtaci/kcp-go"
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -116,7 +117,7 @@ func StartLocalServer(l *config.LocalServer, config *config.CommonConfig) error
|
||||||
|
|
||||||
func handleUdpMonitor(config *config.CommonConfig, l *config.LocalServer) {
|
func handleUdpMonitor(config *config.CommonConfig, l *config.LocalServer) {
|
||||||
ticker := time.NewTicker(time.Second * 1)
|
ticker := time.NewTicker(time.Second * 1)
|
||||||
for{
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
if !udpConnStatus {
|
if !udpConnStatus {
|
||||||
|
|
|
@ -2,9 +2,10 @@ package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"github.com/cnlh/nps/lib/common"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/cnlh/nps/lib/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RegisterLocalIp(server string, vKey string, tp string, proxyUrl string, hour int) {
|
func RegisterLocalIp(server string, vKey string, tp string, proxyUrl string, hour int) {
|
||||||
|
|
|
@ -3,17 +3,18 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
|
"github.com/ccding/go-stun/stun"
|
||||||
"github.com/cnlh/nps/client"
|
"github.com/cnlh/nps/client"
|
||||||
"github.com/cnlh/nps/lib/common"
|
"github.com/cnlh/nps/lib/common"
|
||||||
"github.com/cnlh/nps/lib/config"
|
"github.com/cnlh/nps/lib/config"
|
||||||
"github.com/cnlh/nps/lib/daemon"
|
"github.com/cnlh/nps/lib/daemon"
|
||||||
"github.com/cnlh/nps/lib/file"
|
"github.com/cnlh/nps/lib/file"
|
||||||
"github.com/cnlh/nps/lib/version"
|
"github.com/cnlh/nps/lib/version"
|
||||||
"github.com/astaxie/beego/logs"
|
|
||||||
"github.com/ccding/go-stun/stun"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -2,6 +2,12 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego"
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
"github.com/cnlh/nps/lib/common"
|
"github.com/cnlh/nps/lib/common"
|
||||||
"github.com/cnlh/nps/lib/crypt"
|
"github.com/cnlh/nps/lib/crypt"
|
||||||
"github.com/cnlh/nps/lib/daemon"
|
"github.com/cnlh/nps/lib/daemon"
|
||||||
|
@ -12,12 +18,7 @@ import (
|
||||||
"github.com/cnlh/nps/server/connection"
|
"github.com/cnlh/nps/server/connection"
|
||||||
"github.com/cnlh/nps/server/test"
|
"github.com/cnlh/nps/server/test"
|
||||||
"github.com/cnlh/nps/server/tool"
|
"github.com/cnlh/nps/server/tool"
|
||||||
"github.com/astaxie/beego"
|
|
||||||
"github.com/astaxie/beego/logs"
|
|
||||||
_ "github.com/cnlh/nps/web/routers"
|
_ "github.com/cnlh/nps/web/routers"
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -4,8 +4,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"github.com/cnlh/nps/lib/crypt"
|
|
||||||
"github.com/cnlh/nps/lib/pool"
|
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -16,6 +14,9 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/cnlh/nps/lib/crypt"
|
||||||
|
"github.com/cnlh/nps/lib/pool"
|
||||||
)
|
)
|
||||||
|
|
||||||
//Get the corresponding IP address through domain name
|
//Get the corresponding IP address through domain name
|
||||||
|
|
|
@ -3,10 +3,11 @@ package config
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/cnlh/nps/lib/common"
|
|
||||||
"github.com/cnlh/nps/lib/file"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/cnlh/nps/lib/common"
|
||||||
|
"github.com/cnlh/nps/lib/file"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CommonConfig struct {
|
type CommonConfig struct {
|
||||||
|
|
|
@ -6,13 +6,6 @@ import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/cnlh/nps/lib/common"
|
|
||||||
"github.com/cnlh/nps/lib/crypt"
|
|
||||||
"github.com/cnlh/nps/lib/file"
|
|
||||||
"github.com/cnlh/nps/lib/mux"
|
|
||||||
"github.com/cnlh/nps/lib/pool"
|
|
||||||
"github.com/cnlh/nps/lib/rate"
|
|
||||||
"github.com/xtaci/kcp-go"
|
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -21,6 +14,14 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/cnlh/nps/lib/common"
|
||||||
|
"github.com/cnlh/nps/lib/crypt"
|
||||||
|
"github.com/cnlh/nps/lib/file"
|
||||||
|
"github.com/cnlh/nps/lib/mux"
|
||||||
|
"github.com/cnlh/nps/lib/pool"
|
||||||
|
"github.com/cnlh/nps/lib/rate"
|
||||||
|
"github.com/xtaci/kcp-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Conn struct {
|
type Conn struct {
|
||||||
|
@ -373,7 +374,7 @@ func CopyWaitGroup(conn1, conn2 net.Conn, crypt bool, snappy bool, rate *rate.Ra
|
||||||
}
|
}
|
||||||
|
|
||||||
//get crypt or snappy conn
|
//get crypt or snappy conn
|
||||||
func GetConn(conn net.Conn, cpt, snappy bool, rt *rate.Rate, isServer bool) (io.ReadWriteCloser) {
|
func GetConn(conn net.Conn, cpt, snappy bool, rt *rate.Rate, isServer bool) io.ReadWriteCloser {
|
||||||
if cpt {
|
if cpt {
|
||||||
if isServer {
|
if isServer {
|
||||||
return rate.NewRateConn(crypt.NewTlsServerConn(conn), rt)
|
return rate.NewRateConn(crypt.NewTlsServerConn(conn), rt)
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
package conn
|
package conn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/astaxie/beego/logs"
|
|
||||||
"github.com/xtaci/kcp-go"
|
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
|
"github.com/xtaci/kcp-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewTcpListenerAndProcess(addr string, f func(c net.Conn), listener *net.Listener) error {
|
func NewTcpListenerAndProcess(addr string, f func(c net.Conn), listener *net.Listener) error {
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package conn
|
package conn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
|
|
||||||
"github.com/cnlh/nps/lib/pool"
|
"github.com/cnlh/nps/lib/pool"
|
||||||
"github.com/golang/snappy"
|
"github.com/golang/snappy"
|
||||||
"io"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type SnappyConn struct {
|
type SnappyConn struct {
|
||||||
|
|
|
@ -2,9 +2,10 @@ package crypt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"github.com/astaxie/beego/logs"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
)
|
)
|
||||||
|
|
||||||
var pemPath, keyPath string
|
var pemPath, keyPath string
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package daemon
|
package daemon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cnlh/nps/lib/common"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
@ -9,6 +8,8 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/cnlh/nps/lib/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitDaemon(f string, runPath string, pidPath string) {
|
func InitDaemon(f string, runPath string, pidPath string) {
|
||||||
|
|
|
@ -3,12 +3,13 @@
|
||||||
package daemon
|
package daemon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cnlh/nps/lib/common"
|
|
||||||
"github.com/astaxie/beego"
|
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego"
|
||||||
|
"github.com/cnlh/nps/lib/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
@ -3,14 +3,15 @@ package file
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/cnlh/nps/lib/common"
|
|
||||||
"github.com/cnlh/nps/lib/crypt"
|
|
||||||
"github.com/cnlh/nps/lib/rate"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/cnlh/nps/lib/common"
|
||||||
|
"github.com/cnlh/nps/lib/crypt"
|
||||||
|
"github.com/cnlh/nps/lib/rate"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DbUtils struct {
|
type DbUtils struct {
|
||||||
|
|
|
@ -3,13 +3,14 @@ package file
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/cnlh/nps/lib/common"
|
|
||||||
"github.com/cnlh/nps/lib/rate"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
|
"github.com/cnlh/nps/lib/common"
|
||||||
|
"github.com/cnlh/nps/lib/rate"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewJsonDb(runPath string) *JsonDb {
|
func NewJsonDb(runPath string) *JsonDb {
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package file
|
package file
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cnlh/nps/lib/rate"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/cnlh/nps/lib/rate"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Flow struct {
|
type Flow struct {
|
||||||
|
|
|
@ -3,12 +3,13 @@ package install
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/cnlh/nps/lib/common"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/cnlh/nps/lib/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InstallNps() {
|
func InstallNps() {
|
||||||
|
|
|
@ -2,11 +2,12 @@ package mux
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/cnlh/nps/lib/pool"
|
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/cnlh/nps/lib/pool"
|
||||||
)
|
)
|
||||||
|
|
||||||
type conn struct {
|
type conn struct {
|
||||||
|
|
|
@ -4,12 +4,13 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/cnlh/nps/lib/pool"
|
|
||||||
"math"
|
"math"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/cnlh/nps/lib/pool"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -174,7 +175,7 @@ func (s *Mux) readSession() {
|
||||||
case conn.getStatusCh <- struct{}{}:
|
case conn.getStatusCh <- struct{}{}:
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
conn.hasWrite --
|
conn.hasWrite--
|
||||||
case MUX_NEW_CONN_OK: //conn ok
|
case MUX_NEW_CONN_OK: //conn ok
|
||||||
conn.connStatusOkCh <- struct{}{}
|
conn.connStatusOkCh <- struct{}{}
|
||||||
case MUX_NEW_CONN_Fail:
|
case MUX_NEW_CONN_Fail:
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
package mux
|
package mux
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cnlh/nps/lib/common"
|
|
||||||
"github.com/cnlh/nps/lib/pool"
|
|
||||||
"github.com/astaxie/beego/logs"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
|
"github.com/cnlh/nps/lib/common"
|
||||||
|
"github.com/cnlh/nps/lib/pool"
|
||||||
)
|
)
|
||||||
|
|
||||||
var conn1 net.Conn
|
var conn1 net.Conn
|
||||||
|
|
|
@ -5,15 +5,16 @@ package mux
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"github.com/cnlh/nps/lib/common"
|
|
||||||
"github.com/astaxie/beego/logs"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
|
"github.com/cnlh/nps/lib/common"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package mux
|
package mux
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/astaxie/beego/logs"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPortMux_Close(t *testing.T) {
|
func TestPortMux_Close(t *testing.T) {
|
||||||
|
@ -11,7 +12,7 @@ func TestPortMux_Close(t *testing.T) {
|
||||||
logs.EnableFuncCallDepth(true)
|
logs.EnableFuncCallDepth(true)
|
||||||
logs.SetLogFuncCallDepth(3)
|
logs.SetLogFuncCallDepth(3)
|
||||||
|
|
||||||
pMux := NewPortMux(8888,"Ds")
|
pMux := NewPortMux(8888, "Ds")
|
||||||
go func() {
|
go func() {
|
||||||
if pMux.Start() != nil {
|
if pMux.Start() != nil {
|
||||||
logs.Warn("Error")
|
logs.Warn("Error")
|
||||||
|
|
|
@ -2,8 +2,9 @@ package mux
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/cnlh/nps/lib/pool"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/cnlh/nps/lib/pool"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Element *bufNode
|
type Element *bufNode
|
||||||
|
|
|
@ -36,6 +36,7 @@ var BufPoolCopy = sync.Pool{
|
||||||
return &buf
|
return &buf
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func PutBufPoolUdp(buf []byte) {
|
func PutBufPoolUdp(buf []byte) {
|
||||||
if cap(buf) == PoolSizeUdp {
|
if cap(buf) == PoolSizeUdp {
|
||||||
BufPoolUdp.Put(buf[:PoolSizeUdp])
|
BufPoolUdp.Put(buf[:PoolSizeUdp])
|
||||||
|
@ -48,7 +49,7 @@ func PutBufPoolCopy(buf []byte) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBufPoolCopy() ([]byte) {
|
func GetBufPoolCopy() []byte {
|
||||||
return (*BufPoolCopy.Get().(*[]byte))[:PoolSizeCopy]
|
return (*BufPoolCopy.Get().(*[]byte))[:PoolSizeCopy]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package connection
|
package connection
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cnlh/nps/lib/mux"
|
|
||||||
"github.com/astaxie/beego"
|
|
||||||
"github.com/astaxie/beego/logs"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego"
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
|
"github.com/cnlh/nps/lib/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
var pMux *mux.PortMux
|
var pMux *mux.PortMux
|
||||||
|
|
|
@ -2,14 +2,15 @@ package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
"github.com/cnlh/nps/bridge"
|
"github.com/cnlh/nps/bridge"
|
||||||
"github.com/cnlh/nps/lib/common"
|
"github.com/cnlh/nps/lib/common"
|
||||||
"github.com/cnlh/nps/lib/conn"
|
"github.com/cnlh/nps/lib/conn"
|
||||||
"github.com/cnlh/nps/lib/file"
|
"github.com/cnlh/nps/lib/file"
|
||||||
"github.com/astaxie/beego/logs"
|
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Service interface {
|
type Service interface {
|
||||||
|
|
|
@ -3,13 +3,6 @@ package proxy
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"github.com/cnlh/nps/bridge"
|
|
||||||
"github.com/cnlh/nps/lib/cache"
|
|
||||||
"github.com/cnlh/nps/lib/common"
|
|
||||||
"github.com/cnlh/nps/lib/conn"
|
|
||||||
"github.com/cnlh/nps/lib/file"
|
|
||||||
"github.com/cnlh/nps/server/connection"
|
|
||||||
"github.com/astaxie/beego/logs"
|
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -19,6 +12,14 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
|
"github.com/cnlh/nps/bridge"
|
||||||
|
"github.com/cnlh/nps/lib/cache"
|
||||||
|
"github.com/cnlh/nps/lib/common"
|
||||||
|
"github.com/cnlh/nps/lib/conn"
|
||||||
|
"github.com/cnlh/nps/lib/file"
|
||||||
|
"github.com/cnlh/nps/server/connection"
|
||||||
)
|
)
|
||||||
|
|
||||||
type httpServer struct {
|
type httpServer struct {
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
package proxy
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego"
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
"github.com/cnlh/nps/lib/cache"
|
"github.com/cnlh/nps/lib/cache"
|
||||||
"github.com/cnlh/nps/lib/common"
|
"github.com/cnlh/nps/lib/common"
|
||||||
"github.com/cnlh/nps/lib/conn"
|
"github.com/cnlh/nps/lib/conn"
|
||||||
"github.com/cnlh/nps/lib/crypt"
|
"github.com/cnlh/nps/lib/crypt"
|
||||||
"github.com/cnlh/nps/lib/file"
|
"github.com/cnlh/nps/lib/file"
|
||||||
"github.com/astaxie/beego"
|
|
||||||
"github.com/astaxie/beego/logs"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"net/url"
|
|
||||||
"sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type HttpsServer struct {
|
type HttpsServer struct {
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package proxy
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cnlh/nps/lib/common"
|
|
||||||
"github.com/cnlh/nps/lib/pool"
|
|
||||||
"github.com/astaxie/beego/logs"
|
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
|
"github.com/cnlh/nps/lib/common"
|
||||||
|
"github.com/cnlh/nps/lib/pool"
|
||||||
)
|
)
|
||||||
|
|
||||||
type P2PServer struct {
|
type P2PServer struct {
|
||||||
|
|
|
@ -3,13 +3,14 @@ package proxy
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/cnlh/nps/lib/common"
|
|
||||||
"github.com/cnlh/nps/lib/conn"
|
|
||||||
"github.com/cnlh/nps/lib/file"
|
|
||||||
"github.com/astaxie/beego/logs"
|
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
|
"github.com/cnlh/nps/lib/common"
|
||||||
|
"github.com/cnlh/nps/lib/conn"
|
||||||
|
"github.com/cnlh/nps/lib/file"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -3,11 +3,12 @@
|
||||||
package proxy
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cnlh/nps/lib/common"
|
|
||||||
"github.com/cnlh/nps/lib/conn"
|
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/cnlh/nps/lib/common"
|
||||||
|
"github.com/cnlh/nps/lib/conn"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HandleTrans(c *conn.Conn, s *TunnelModeServer) error {
|
func HandleTrans(c *conn.Conn, s *TunnelModeServer) error {
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
package proxy
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
"github.com/cnlh/nps/bridge"
|
"github.com/cnlh/nps/bridge"
|
||||||
"github.com/cnlh/nps/lib/common"
|
"github.com/cnlh/nps/lib/common"
|
||||||
"github.com/cnlh/nps/lib/conn"
|
"github.com/cnlh/nps/lib/conn"
|
||||||
"github.com/cnlh/nps/lib/file"
|
"github.com/cnlh/nps/lib/file"
|
||||||
"github.com/cnlh/nps/lib/pool"
|
"github.com/cnlh/nps/lib/pool"
|
||||||
"github.com/astaxie/beego/logs"
|
|
||||||
"net"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type UdpModeServer struct {
|
type UdpModeServer struct {
|
||||||
|
|
|
@ -8,13 +8,13 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego"
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
"github.com/cnlh/nps/bridge"
|
"github.com/cnlh/nps/bridge"
|
||||||
"github.com/cnlh/nps/lib/common"
|
"github.com/cnlh/nps/lib/common"
|
||||||
"github.com/cnlh/nps/lib/file"
|
"github.com/cnlh/nps/lib/file"
|
||||||
"github.com/cnlh/nps/server/proxy"
|
"github.com/cnlh/nps/server/proxy"
|
||||||
"github.com/cnlh/nps/server/tool"
|
"github.com/cnlh/nps/server/tool"
|
||||||
"github.com/astaxie/beego"
|
|
||||||
"github.com/astaxie/beego/logs"
|
|
||||||
"github.com/shirou/gopsutil/cpu"
|
"github.com/shirou/gopsutil/cpu"
|
||||||
"github.com/shirou/gopsutil/load"
|
"github.com/shirou/gopsutil/load"
|
||||||
"github.com/shirou/gopsutil/mem"
|
"github.com/shirou/gopsutil/mem"
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package test
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cnlh/nps/lib/common"
|
|
||||||
"github.com/cnlh/nps/lib/file"
|
|
||||||
"github.com/astaxie/beego"
|
|
||||||
"log"
|
"log"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego"
|
||||||
|
"github.com/cnlh/nps/lib/common"
|
||||||
|
"github.com/cnlh/nps/lib/file"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestServerConfig() {
|
func TestServerConfig() {
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
package tool
|
package tool
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cnlh/nps/lib/common"
|
"math"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
|
"github.com/cnlh/nps/lib/common"
|
||||||
"github.com/shirou/gopsutil/cpu"
|
"github.com/shirou/gopsutil/cpu"
|
||||||
"github.com/shirou/gopsutil/load"
|
"github.com/shirou/gopsutil/load"
|
||||||
"github.com/shirou/gopsutil/mem"
|
"github.com/shirou/gopsutil/mem"
|
||||||
"github.com/shirou/gopsutil/net"
|
"github.com/shirou/gopsutil/net"
|
||||||
"math"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -2,9 +2,10 @@ package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"github.com/cnlh/nps/lib/crypt"
|
|
||||||
"github.com/astaxie/beego"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego"
|
||||||
|
"github.com/cnlh/nps/lib/crypt"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AuthController struct {
|
type AuthController struct {
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cnlh/nps/lib/common"
|
|
||||||
"github.com/cnlh/nps/lib/crypt"
|
|
||||||
"github.com/cnlh/nps/lib/file"
|
|
||||||
"github.com/cnlh/nps/server"
|
|
||||||
"github.com/astaxie/beego"
|
|
||||||
"html"
|
"html"
|
||||||
"math"
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego"
|
||||||
|
"github.com/cnlh/nps/lib/common"
|
||||||
|
"github.com/cnlh/nps/lib/crypt"
|
||||||
|
"github.com/cnlh/nps/lib/file"
|
||||||
|
"github.com/cnlh/nps/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BaseController struct {
|
type BaseController struct {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/astaxie/beego"
|
||||||
"github.com/cnlh/nps/lib/common"
|
"github.com/cnlh/nps/lib/common"
|
||||||
"github.com/cnlh/nps/lib/file"
|
"github.com/cnlh/nps/lib/file"
|
||||||
"github.com/cnlh/nps/lib/rate"
|
"github.com/cnlh/nps/lib/rate"
|
||||||
"github.com/cnlh/nps/server"
|
"github.com/cnlh/nps/server"
|
||||||
"github.com/astaxie/beego"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ClientController struct {
|
type ClientController struct {
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego"
|
||||||
"github.com/cnlh/nps/lib/common"
|
"github.com/cnlh/nps/lib/common"
|
||||||
"github.com/cnlh/nps/lib/file"
|
"github.com/cnlh/nps/lib/file"
|
||||||
"github.com/cnlh/nps/server"
|
"github.com/cnlh/nps/server"
|
||||||
"github.com/astaxie/beego"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type LoginController struct {
|
type LoginController struct {
|
||||||
|
|
Loading…
Reference in New Issue