Эх сурвалжийг харах

add nat sign in host info struct

Joyit 1 сар өмнө
parent
commit
04442448f4
1 өөрчлөгдсөн 18 нэмэгдсэн , 11 устгасан
  1. 18 11
      type.go

+ 18 - 11
type.go

@@ -120,17 +120,18 @@ type GetMsg struct {
 
 // 连接服务结构
 type HostInfo struct {
-	Proto    string    `json:"proto" yaml:"proto"`       // 协议
-	Version  uint8     `json:"version" yaml:"version"`   // 版本
-	Host     string    `json:"host" yaml:"host"`         // 连接的IP地址或者域名
-	Bind     string    `json:"bind" yaml:"bind"`         // 绑定的地址
-	Port     uint16    `json:"port" yaml:"port"`         // 连接的端口
-	Path     string    `json:"path" yaml:"path"`         // 连接的路径
-	Hash     string    `json:"hash" yaml:"hash"`         // 连接验证使用,格式 method:key
-	Proxy    bool      `json:"proxy" yaml:"proxy"`       // 是否代理
-	Priority int16     `json:"priority" yaml:"priority"` // 优先级,-1 表示不可用,0 表示最高优先级(为了兼容没有优先级的节点),1-100 表示优先级别,数值越高优先级越高
-	Errors   uint16    `json:"errors" yaml:"errors"`     // 连接失败计数,如果成功了则重置为0
-	Updated  time.Time `json:"updated" yaml:"updated"`   // 节点信息刷新时间
+	Proto    string    `json:"proto" yaml:"proto"`                 // 协议
+	Version  uint8     `json:"version" yaml:"version"`             // 版本
+	Host     string    `json:"host" yaml:"host"`                   // 连接的IP地址或者域名
+	Bind     string    `json:"bind,omitempty" yaml:"bind"`         // 绑定的地址
+	Port     uint16    `json:"port,omitempty" yaml:"port"`         // 连接的端口
+	Path     string    `json:"path,omitempty" yaml:"path"`         // 连接的路径
+	Hash     string    `json:"hash,omitempty" yaml:"hash"`         // 连接验证使用,格式 method:key
+	Proxy    bool      `json:"proxy,omitempty" yaml:"proxy"`       // 是否代理
+	Nat      bool      `json:"nat,omitempty" yaml:"nat"`           // 是否是前端nat的方式处理
+	Priority int16     `json:"priority,omitempty" yaml:"priority"` // 优先级,-1 表示不可用,0 表示最高优先级(为了兼容没有优先级的节点),1-100 表示优先级别,数值越高优先级越高
+	Errors   uint16    `json:"errors,omitempty" yaml:"errors"`     // 连接失败计数,如果成功了则重置为0
+	Updated  time.Time `json:"updated,omitempty" yaml:"updated"`   // 节点信息刷新时间
 }
 
 // 从 url 中解析信息
@@ -190,6 +191,9 @@ func ParseUrl(url string) (hostInfo *HostInfo, err error) {
 	if regexp.MustCompile(`[\?&]proxy=1`).MatchString(url) {
 		hostInfo.Proxy = true
 	}
+	if regexp.MustCompile(`[\?&]nat=1`).MatchString(url) {
+		hostInfo.Nat = true
+	}
 	priorityM := regexp.MustCompile(`[\?&]priority=(-?\d+)`).FindStringSubmatch(url)
 	if priorityM != nil {
 		priority, err := strconv.Atoi(priorityM[1])
@@ -224,6 +228,9 @@ func (h *HostInfo) Url() string {
 	if h.Proxy {
 		param = append(param, "proxy=1")
 	}
+	if h.Nat {
+		param = append(param, "nat=1")
+	}
 	if h.Priority != 0 {
 		param = append(param, fmt.Sprintf("priority=%d", h.Priority))
 	}