mirror of https://github.com/cbeuw/Cloak
Server side UDP to proxy server
This commit is contained in:
parent
c36ec04ce5
commit
c19c43f6e8
|
|
@ -167,7 +167,8 @@ func dispatchConnection(conn net.Conn, sta *server.State) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
localConn, err := net.Dial("tcp", sta.ProxyBook[ci.ProxyMethod])
|
proxyAddr := sta.ProxyBook[ci.ProxyMethod]
|
||||||
|
localConn, err := net.Dial(proxyAddr.Network(), proxyAddr.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Failed to connect to %v: %v", ci.ProxyMethod, err)
|
log.Errorf("Failed to connect to %v: %v", ci.ProxyMethod, err)
|
||||||
user.DeleteSession(ci.SessionId, "Failed to connect to proxy server")
|
user.DeleteSession(ci.SessionId, "Failed to connect to proxy server")
|
||||||
|
|
@ -254,7 +255,10 @@ func main() {
|
||||||
if net.ParseIP(ssLocalHost).To4() == nil {
|
if net.ParseIP(ssLocalHost).To4() == nil {
|
||||||
ssLocalHost = "[" + ssLocalHost + "]"
|
ssLocalHost = "[" + ssLocalHost + "]"
|
||||||
}
|
}
|
||||||
sta.ProxyBook["shadowsocks"] = ssLocalHost + ":" + ssLocalPort
|
sta.ProxyBook["shadowsocks"], err = net.ResolveTCPAddr("tcp", ssLocalHost+":"+ssLocalPort)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
listen := func(addr, port string) {
|
listen := func(addr, port string) {
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,7 @@ func MakeSession(id uint32, config *SessionConfig) *Session {
|
||||||
Valve: config.Valve,
|
Valve: config.Valve,
|
||||||
}
|
}
|
||||||
if config.Unordered {
|
if config.Unordered {
|
||||||
|
log.Debug("Connection is unordered")
|
||||||
sbConfig.strategy = UNIFORM_SPREAD
|
sbConfig.strategy = UNIFORM_SPREAD
|
||||||
} else {
|
} else {
|
||||||
sbConfig.strategy = FIXED_CONN_MAPPING
|
sbConfig.strategy = FIXED_CONN_MAPPING
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,11 @@ import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"github.com/cbeuw/Cloak/internal/server/usermanager"
|
"github.com/cbeuw/Cloak/internal/server/usermanager"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -14,7 +17,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type rawConfig struct {
|
type rawConfig struct {
|
||||||
ProxyBook map[string]string
|
ProxyBook map[string][]string
|
||||||
BypassUID [][]byte
|
BypassUID [][]byte
|
||||||
RedirAddr string
|
RedirAddr string
|
||||||
PrivateKey string
|
PrivateKey string
|
||||||
|
|
@ -25,7 +28,7 @@ type rawConfig struct {
|
||||||
|
|
||||||
// State type stores the global state of the program
|
// State type stores the global state of the program
|
||||||
type State struct {
|
type State struct {
|
||||||
ProxyBook map[string]string
|
ProxyBook map[string]net.Addr
|
||||||
|
|
||||||
BindHost string
|
BindHost string
|
||||||
BindPort string
|
BindPort string
|
||||||
|
|
@ -51,8 +54,9 @@ func InitState(bindHost, bindPort string, nowFunc func() time.Time) (*State, err
|
||||||
BindPort: bindPort,
|
BindPort: bindPort,
|
||||||
Now: nowFunc,
|
Now: nowFunc,
|
||||||
BypassUID: make(map[[16]byte]struct{}),
|
BypassUID: make(map[[16]byte]struct{}),
|
||||||
|
ProxyBook: map[string]net.Addr{},
|
||||||
|
usedRandom: map[[32]byte]int64{},
|
||||||
}
|
}
|
||||||
ret.usedRandom = make(map[[32]byte]int64)
|
|
||||||
go ret.UsedRandomCleaner()
|
go ret.UsedRandomCleaner()
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
@ -88,7 +92,29 @@ func (sta *State) ParseConfig(conf string) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sta.RedirAddr = preParse.RedirAddr
|
sta.RedirAddr = preParse.RedirAddr
|
||||||
sta.ProxyBook = preParse.ProxyBook
|
|
||||||
|
for name, pair := range preParse.ProxyBook {
|
||||||
|
if len(pair) != 2 {
|
||||||
|
return fmt.Errorf("invalid protocol and address pair for %v: %v", name, pair)
|
||||||
|
}
|
||||||
|
network := strings.ToLower(pair[0])
|
||||||
|
switch network {
|
||||||
|
case "tcp":
|
||||||
|
addr, err := net.ResolveTCPAddr("tcp", pair[1])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
sta.ProxyBook[name] = addr
|
||||||
|
continue
|
||||||
|
case "udp":
|
||||||
|
addr, err := net.ResolveUDPAddr("udp", pair[1])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
sta.ProxyBook[name] = addr
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pvBytes, err := base64.StdEncoding.DecodeString(preParse.PrivateKey)
|
pvBytes, err := base64.StdEncoding.DecodeString(preParse.PrivateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue