mirror of
https://github.com/e1732a364fed/v2ray_simple.git
synced 2025-10-08 10:10:27 +08:00
修订代码;将addr的赋值从各个proxy自己的方法中提出来
This commit is contained in:
@@ -37,13 +37,38 @@ type CommonConf struct {
|
||||
Extra map[string]interface{} `toml:"extra"` //用于包含任意其它数据.虽然本包自己定义的协议肯定都是已知的,但是如果其他人使用了本包的话,那就有可能添加一些 新协议 特定的数据.
|
||||
}
|
||||
|
||||
func (cc *CommonConf) GetAddr() string {
|
||||
func (cc *CommonConf) GetAddrStr() string {
|
||||
switch cc.Network {
|
||||
case "unix":
|
||||
return cc.Host
|
||||
|
||||
default:
|
||||
if cc.Host != "" {
|
||||
|
||||
return cc.Host + ":" + strconv.Itoa(cc.Port)
|
||||
} else {
|
||||
return cc.IP + ":" + strconv.Itoa(cc.Port)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//和 GetAddr的区别是,它优先使用ip,其次再使用host
|
||||
func (cc *CommonConf) GetAddrStrForListenOrDial() string {
|
||||
switch cc.Network {
|
||||
case "unix":
|
||||
return cc.Host
|
||||
|
||||
default:
|
||||
if cc.IP != "" {
|
||||
return cc.IP + ":" + strconv.Itoa(cc.Port)
|
||||
|
||||
} else {
|
||||
return cc.Host + ":" + strconv.Itoa(cc.Port)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -231,13 +231,17 @@ func configCommon(ser ProxyCommon, cc *CommonConf) {
|
||||
|
||||
}
|
||||
|
||||
//setNetwork, setIsDial(true),setDialConf(dc), call configCommon
|
||||
//SetAddrStr, setNetwork, setIsDial(true),setDialConf(dc), call configCommon
|
||||
func configCommonForClient(cli ProxyCommon, dc *DialConf) {
|
||||
cli.setNetwork(dc.Network)
|
||||
cli.setIsDial(true)
|
||||
cli.setDialConf(dc)
|
||||
cli.setTag(dc.Tag)
|
||||
|
||||
if cli.Name() != "direct" {
|
||||
cli.SetAddrStr(dc.GetAddrStrForListenOrDial())
|
||||
}
|
||||
|
||||
configCommon(cli, &dc.CommonConf)
|
||||
|
||||
if dc.AdvancedLayer == "ws" {
|
||||
@@ -245,8 +249,9 @@ func configCommonForClient(cli ProxyCommon, dc *DialConf) {
|
||||
}
|
||||
}
|
||||
|
||||
//setNetwork, setTag, setCantRoute,setListenConf(lc), call configCommon
|
||||
//SetAddrStr,setNetwork, setTag, setCantRoute,setListenConf(lc), call configCommon
|
||||
func configCommonForServer(ser ProxyCommon, lc *ListenConf) {
|
||||
ser.SetAddrStr(lc.GetAddrStrForListenOrDial())
|
||||
ser.setNetwork(lc.Network)
|
||||
ser.setListenConf(lc)
|
||||
ser.setTag(lc.Tag)
|
||||
|
@@ -65,7 +65,6 @@ func (_ ServerCreator) NewServer(lc *proxy.ListenConf) (proxy.Server, error) {
|
||||
return nil, e
|
||||
}
|
||||
s := &Server{
|
||||
ProxyCommonStruct: proxy.ProxyCommonStruct{Addr: lc.GetAddr()}, //监听地址,不要与TargetAddr混淆
|
||||
targetAddr: ta,
|
||||
}
|
||||
return s, nil
|
||||
|
@@ -19,9 +19,9 @@ func init() {
|
||||
proxy.RegisterServer(name, &ServerCreator{})
|
||||
}
|
||||
|
||||
//只有地址和port需要配置,非常简单
|
||||
type ServerCreator struct{}
|
||||
|
||||
//只有地址和port需要配置,非常简单
|
||||
func (_ ServerCreator) NewServerFromURL(u *url.URL) (proxy.Server, error) {
|
||||
addr := u.Host //若不给出port,那就只有host名,这样不好,我们“默认”, 配置里肯定给了port
|
||||
|
||||
@@ -36,9 +36,7 @@ func (_ ServerCreator) NewServerFromURL(u *url.URL) (proxy.Server, error) {
|
||||
|
||||
func (_ ServerCreator) NewServer(dc *proxy.ListenConf) (proxy.Server, error) {
|
||||
|
||||
s := &Server{
|
||||
ProxyCommonStruct: proxy.ProxyCommonStruct{Addr: dc.GetAddr()},
|
||||
}
|
||||
s := &Server{}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
|
@@ -121,7 +121,7 @@ func prepareTLS_forClient(com ProxyCommon, dc *DialConf) error {
|
||||
func prepareTLS_forServer(com ProxyCommon, lc *ListenConf) error {
|
||||
// 这里直接不检查 字符串就直接传给 tlsLayer.NewServer
|
||||
// 所以要求 cert和 key 不在程序本身目录 的话,就要给出完整路径
|
||||
tlsserver, err := tlsLayer.NewServer(lc.GetAddr(), lc.Host, lc.TLSCert, lc.TLSKey, lc.Insecure)
|
||||
tlsserver, err := tlsLayer.NewServer(lc.Host, lc.TLSCert, lc.TLSKey, lc.Insecure)
|
||||
if err == nil {
|
||||
com.setTLS_Server(tlsserver)
|
||||
} else {
|
||||
@@ -150,7 +150,7 @@ func prepareTLS_forProxyCommon_withURL(u *url.URL, isclient bool, com ProxyCommo
|
||||
hostAndPort := u.Host
|
||||
sni, _, _ := net.SplitHostPort(hostAndPort)
|
||||
|
||||
tlsserver, err := tlsLayer.NewServer(hostAndPort, sni, certFile, keyFile, insecure)
|
||||
tlsserver, err := tlsLayer.NewServer(sni, certFile, keyFile, insecure)
|
||||
if err == nil {
|
||||
com.setTLS_Server(tlsserver)
|
||||
} else {
|
||||
@@ -317,7 +317,7 @@ func (s *ProxyCommonStruct) initWS_client() {
|
||||
}
|
||||
}
|
||||
|
||||
c, e := ws.NewClient(s.dialConf.GetAddr(), path)
|
||||
c, e := ws.NewClient(s.dialConf.GetAddrStr(), path)
|
||||
if e != nil {
|
||||
log.Fatal("initWS_client failed", e)
|
||||
}
|
||||
|
@@ -27,7 +27,6 @@ type Server struct {
|
||||
//password string
|
||||
}
|
||||
|
||||
//只有地址和port需要配置,非常简单
|
||||
type ServerCreator struct{}
|
||||
|
||||
func (_ ServerCreator) NewServerFromURL(u *url.URL) (proxy.Server, error) {
|
||||
@@ -36,12 +35,11 @@ func (_ ServerCreator) NewServerFromURL(u *url.URL) (proxy.Server, error) {
|
||||
|
||||
func (_ ServerCreator) NewServer(dc *proxy.ListenConf) (proxy.Server, error) {
|
||||
|
||||
s := &Server{
|
||||
ProxyCommonStruct: proxy.ProxyCommonStruct{Addr: dc.GetAddr()},
|
||||
}
|
||||
s := &Server{}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
//只有地址和port需要配置,非常简单
|
||||
func NewServer(url *url.URL) (proxy.Server, error) {
|
||||
addr := url.Host //若不给出port,那就只有host名,这样不好,我们默认配置里肯定给了port
|
||||
|
||||
|
@@ -53,7 +53,6 @@ func (_ ClientCreator) NewClient(dc *proxy.DialConf) (proxy.Client, error) {
|
||||
}
|
||||
|
||||
c := &Client{
|
||||
ProxyCommonStruct: proxy.ProxyCommonStruct{Addr: dc.GetAddr()},
|
||||
user: id,
|
||||
}
|
||||
v := dc.Version
|
||||
|
@@ -42,7 +42,6 @@ func (_ ServerCreator) NewServer(lc *proxy.ListenConf) (proxy.Server, error) {
|
||||
return nil, err
|
||||
}
|
||||
s := &Server{
|
||||
ProxyCommonStruct: proxy.ProxyCommonStruct{Addr: lc.GetAddr()},
|
||||
userHashes: make(map[[16]byte]*proxy.V2rayUser),
|
||||
userCRUMFURS: make(map[[16]byte]*CRUMFURS),
|
||||
}
|
||||
|
@@ -8,18 +8,16 @@ import (
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
addr string
|
||||
tlsConfig *tls.Config
|
||||
}
|
||||
|
||||
func NewServer(hostAndPort, host, certFile, keyFile string, isInsecure bool) (*Server, error) {
|
||||
func NewServer(host, certFile, keyFile string, isInsecure bool) (*Server, error) {
|
||||
|
||||
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s := &Server{
|
||||
addr: hostAndPort,
|
||||
tlsConfig: &tls.Config{
|
||||
InsecureSkipVerify: isInsecure,
|
||||
ServerName: host,
|
||||
|
Reference in New Issue
Block a user