mirror of
https://github.com/nadoo/glider.git
synced 2026-11-19 07:09:42 +08:00
anytls: support anytls
This commit is contained in:
1 parent
bb439c9345
commit
cb6f2d1e1a
12 files changed
+958
-80
No files matched your search
@@ -0,0 +1,59 @@
|
||||
package anytls
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func encodeSettings(m map[string]string) []byte {
|
||||
keys := []string{"v", "client", "padding-md5"}
|
||||
lines := make([]string, 0, len(m))
|
||||
seen := map[string]bool{}
|
||||
for _, k := range keys {
|
||||
if v, ok := m[k]; ok {
|
||||
lines = append(lines, k+"="+v)
|
||||
seen[k] = true
|
||||
}
|
||||
}
|
||||
for k, v := range m {
|
||||
if !seen[k] {
|
||||
lines = append(lines, k+"="+v)
|
||||
}
|
||||
}
|
||||
return []byte(strings.Join(lines, "\n"))
|
||||
}
|
||||
|
||||
func parseSettings(data []byte) map[string]string {
|
||||
out := map[string]string{}
|
||||
for _, line := range strings.Split(string(data), "\n") {
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
k, v, ok := strings.Cut(line, "=")
|
||||
if ok {
|
||||
out[k] = v
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func settingsVersion(m map[string]string) int {
|
||||
v, err := strconv.Atoi(m["v"])
|
||||
if err != nil {
|
||||
return 1
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func clientSettings(ps paddingScheme) []byte {
|
||||
return encodeSettings(map[string]string{
|
||||
"v": fmt.Sprint(protocolVersion),
|
||||
"client": "glider-anytls",
|
||||
"padding-md5": ps.md5(),
|
||||
})
|
||||
}
|
||||
|
||||
func serverSettings() []byte {
|
||||
return encodeSettings(map[string]string{"v": fmt.Sprint(protocolVersion)})
|
||||
}
|
||||
Reference in new issue
Block a user