1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-07 17:00:24 +08:00

feat: add base14 en/decoding

This commit is contained in:
源文雨
2025-02-01 09:49:59 +08:00
parent bbe2c60aa3
commit e6298d3459
6 changed files with 16 additions and 1 deletions

View File

@@ -41,6 +41,7 @@ EndPoint: 0.0.0.0:56789
MTU: 1504
SpeedLoop: 4096
Mask: 0x1234567890abcdef
Base14: true
Peers:
-
IP: "192.168.233.2"

View File

@@ -17,7 +17,8 @@ type Config struct {
EndPoint string `yaml:"EndPoint"`
MTU int64 `yaml:"MTU"` // MTU of nic (will minus packet header len)
SpeedLoop uint16 `yaml:"SpeedLoop"`
Mask uint64 `yaml:"Mask"` // Mask 是异或报文所用掩码, 必须保证各端统一
Mask uint64 `yaml:"Mask"` // Mask 是异或报文所用掩码, 必须保证各端统一
Base14 bool `yaml:"Base14"` // Base14 是否将最终报文进行 base16384 编码后再发送
Peers []Peer `yaml:"Peers"`
}

View File

@@ -51,6 +51,8 @@ type Me struct {
srcport, dstport, mtu, speedloop uint16
// 报头掩码
mask uint64
// 是否进行 base16384 编码
base14 bool
// 本机网络端点初始化配置
networkconfigs []any
}
@@ -64,6 +66,7 @@ type MyConfig struct {
NICConfig *NICConfig
SrcPort, DstPort, MTU, SpeedLoop uint16
Mask uint64
Base14 bool
}
type NICConfig struct {
@@ -116,6 +119,7 @@ func NewMe(cfg *MyConfig) (m Me) {
)
}
m.mask = cfg.Mask
m.base14 = cfg.Base14
var buf [8]byte
binary.BigEndian.PutUint64(buf[:], m.mask)
logrus.Infoln("[me] xor mask", hex.EncodeToString(buf[:]))

View File

@@ -8,6 +8,7 @@ import (
"github.com/fumiama/WireGold/config"
"github.com/fumiama/WireGold/gold/head"
base14 "github.com/fumiama/go-base16384"
"github.com/sirupsen/logrus"
)
@@ -29,6 +30,9 @@ func (m *Me) wait(data []byte) *head.Packet {
if config.ShowDebugLog {
logrus.Debugln("[recv] data bytes", hex.EncodeToString(data[:bound]), endl)
}
if m.base14 {
data = base14.Decode(data)
}
seq, data := m.xordec(data)
if config.ShowDebugLog {
logrus.Debugln("[recv] data xored", hex.EncodeToString(data[:bound]), endl)

View File

@@ -16,6 +16,7 @@ import (
"github.com/fumiama/WireGold/config"
"github.com/fumiama/WireGold/gold/head"
"github.com/fumiama/WireGold/helper"
base14 "github.com/fumiama/go-base16384"
)
var (
@@ -147,6 +148,9 @@ func (l *Link) writeonce(p *head.Packet, teatype uint8, additional uint16, datas
logrus.Debugln("[send] data bytes", hex.EncodeToString(d[:bound]), endl)
}
d = l.me.xorenc(d, seq)
if l.me.base14 {
d = base14.Encode(d)
}
if config.ShowDebugLog {
logrus.Debugln("[send] data xored", hex.EncodeToString(d[:bound]), endl)
}

View File

@@ -113,6 +113,7 @@ func (wg *WG) init(srcport, dstport uint16) {
MTU: uint16(wg.c.MTU),
SpeedLoop: wg.c.SpeedLoop,
Mask: wg.c.Mask,
Base14: wg.c.Base14,
})
for _, peer := range wg.c.Peers {