mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-18 17:00:26 +08:00
add peerwise mtu
This commit is contained in:
BIN
.github/Maria.png
vendored
Normal file
BIN
.github/Maria.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 254 KiB |
BIN
.github/rikka.png
vendored
BIN
.github/rikka.png
vendored
Binary file not shown.
|
Before Width: | Height: | Size: 209 KiB |
@@ -1,5 +1,5 @@
|
|||||||
<div align="center">
|
<div align="center">
|
||||||
<img src=".github/rikka.png" width = "360" height = "360" alt="WireGold-Rikka"><br>
|
<img src=".github/Maria.png" width = "400" alt="WireGold-Maria"><br>
|
||||||
<h1>WireGold</h1>
|
<h1>WireGold</h1>
|
||||||
Wire Golang Guard = WireGold<br><br>
|
Wire Golang Guard = WireGold<br><br>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ type Peer struct {
|
|||||||
QueryList []string `yaml:"QueryList"`
|
QueryList []string `yaml:"QueryList"`
|
||||||
QuerySeconds int64 `yaml:"QuerySeconds"`
|
QuerySeconds int64 `yaml:"QuerySeconds"`
|
||||||
AllowTrans bool `yaml:"AllowTrans"`
|
AllowTrans bool `yaml:"AllowTrans"`
|
||||||
|
MTU int64 `yaml:"MTU"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func Parse(path string) (c Config) {
|
func Parse(path string) (c Config) {
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ type Link struct {
|
|||||||
status int
|
status int
|
||||||
// 是否允许转发
|
// 是否允许转发
|
||||||
allowtrans bool
|
allowtrans bool
|
||||||
|
// udp 数据包的最大大小
|
||||||
|
mtu uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ func NewMe(cfg *MyConfig) (m Me) {
|
|||||||
EndPoint: "127.0.0.1:56789",
|
EndPoint: "127.0.0.1:56789",
|
||||||
AllowedIPs: []string{cfg.MyIPwithMask},
|
AllowedIPs: []string{cfg.MyIPwithMask},
|
||||||
NoPipe: cfg.NIC != nil,
|
NoPipe: cfg.NIC != nil,
|
||||||
|
MTU: cfg.MTU,
|
||||||
})
|
})
|
||||||
m.srcport = cfg.SrcPort
|
m.srcport = cfg.SrcPort
|
||||||
m.dstport = cfg.DstPort
|
m.dstport = cfg.DstPort
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ type PeerConfig struct {
|
|||||||
AllowedIPs, Querys []string
|
AllowedIPs, Querys []string
|
||||||
PubicKey *[32]byte
|
PubicKey *[32]byte
|
||||||
KeepAliveDur, QueryTick int64
|
KeepAliveDur, QueryTick int64
|
||||||
|
MTU uint16
|
||||||
AllowTrans, NoPipe bool
|
AllowTrans, NoPipe bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,11 +28,15 @@ func (m *Me) AddPeer(cfg *PeerConfig) (l *Link) {
|
|||||||
if ok {
|
if ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if cfg.MTU == 0 || cfg.MTU == 65535 {
|
||||||
|
panic("invalid mtu for peer " + cfg.PeerIP)
|
||||||
|
}
|
||||||
l = &Link{
|
l = &Link{
|
||||||
pubk: cfg.PubicKey,
|
pubk: cfg.PubicKey,
|
||||||
peerip: net.ParseIP(cfg.PeerIP),
|
peerip: net.ParseIP(cfg.PeerIP),
|
||||||
allowtrans: cfg.AllowTrans,
|
allowtrans: cfg.AllowTrans,
|
||||||
me: m,
|
me: m,
|
||||||
|
mtu: uint16(cfg.MTU),
|
||||||
}
|
}
|
||||||
|
|
||||||
if !cfg.NoPipe {
|
if !cfg.NoPipe {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
// WriteAndPut 向 peer 发包并将包放回缓存池
|
// WriteAndPut 向 peer 发包并将包放回缓存池
|
||||||
func (l *Link) WriteAndPut(p *head.Packet, istransfer bool) (n int, err error) {
|
func (l *Link) WriteAndPut(p *head.Packet, istransfer bool) (n int, err error) {
|
||||||
teatype := uint8(rand.Intn(16))
|
teatype := uint8(rand.Intn(16))
|
||||||
if len(p.Data) <= int(l.me.mtu) {
|
if len(p.Data) <= int(l.mtu) {
|
||||||
if !istransfer {
|
if !istransfer {
|
||||||
p.FillHash()
|
p.FillHash()
|
||||||
p.Data = l.Encode(teatype, p.Data)
|
p.Data = l.Encode(teatype, p.Data)
|
||||||
@@ -30,15 +30,15 @@ func (l *Link) WriteAndPut(p *head.Packet, istransfer bool) (n int, err error) {
|
|||||||
i := 0
|
i := 0
|
||||||
packet := head.SelectPacket()
|
packet := head.SelectPacket()
|
||||||
*packet = *p
|
*packet = *p
|
||||||
for ; int(totl)-i > int(l.me.mtu); i += int(l.me.mtu) {
|
for ; int(totl)-i > int(l.mtu); i += int(l.mtu) {
|
||||||
logrus.Debugln("[link] split frag", i, ":", i+int(l.me.mtu), ", remain:", int(totl)-i-int(l.me.mtu))
|
logrus.Debugln("[link] split frag", i, ":", i+int(l.mtu), ", remain:", int(totl)-i-int(l.mtu))
|
||||||
packet.Data = data[:int(l.me.mtu)]
|
packet.Data = data[:int(l.mtu)]
|
||||||
cnt, err := l.write(packet, teatype, totl, uint16(uint(i)>>3), istransfer, true)
|
cnt, err := l.write(packet, teatype, totl, uint16(uint(i)>>3), istransfer, true)
|
||||||
n += cnt
|
n += cnt
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
data = data[int(l.me.mtu):]
|
data = data[int(l.mtu):]
|
||||||
packet.TTL = ttl
|
packet.TTL = ttl
|
||||||
}
|
}
|
||||||
packet.Put()
|
packet.Put()
|
||||||
@@ -54,7 +54,7 @@ func (l *Link) write(p *head.Packet, teatype uint8, datasz uint32, offset uint16
|
|||||||
var d []byte
|
var d []byte
|
||||||
var cl func()
|
var cl func()
|
||||||
if istransfer {
|
if istransfer {
|
||||||
if p.Flags&0x4000 == 0x4000 && len(p.Data) > int(l.me.mtu) {
|
if p.Flags&0x4000 == 0x4000 && len(p.Data) > int(l.mtu) {
|
||||||
return len(p.Data), errors.New("drop dont fragmnet big trans packet")
|
return len(p.Data), errors.New("drop dont fragmnet big trans packet")
|
||||||
}
|
}
|
||||||
d, cl = p.Marshal(nil, teatype, 0, 0, false, false)
|
d, cl = p.Marshal(nil, teatype, 0, 0, false, false)
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ func TestTunnel(t *testing.T) {
|
|||||||
EndPoint: "127.0.0.1:1237",
|
EndPoint: "127.0.0.1:1237",
|
||||||
AllowedIPs: []string{"192.168.1.3/32"},
|
AllowedIPs: []string{"192.168.1.3/32"},
|
||||||
PubicKey: peerpk.Public(),
|
PubicKey: peerpk.Public(),
|
||||||
|
MTU: 4096,
|
||||||
})
|
})
|
||||||
p := link.NewMe(&link.MyConfig{
|
p := link.NewMe(&link.MyConfig{
|
||||||
MyIPwithMask: "192.168.1.3/32",
|
MyIPwithMask: "192.168.1.3/32",
|
||||||
@@ -55,6 +56,7 @@ func TestTunnel(t *testing.T) {
|
|||||||
EndPoint: "127.0.0.1:1236",
|
EndPoint: "127.0.0.1:1236",
|
||||||
AllowedIPs: []string{"192.168.1.2/32"},
|
AllowedIPs: []string{"192.168.1.2/32"},
|
||||||
PubicKey: selfpk.Public(),
|
PubicKey: selfpk.Public(),
|
||||||
|
MTU: 4096,
|
||||||
})
|
})
|
||||||
tunnme, err := Create(&m, "192.168.1.3")
|
tunnme, err := Create(&m, "192.168.1.3")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -117,6 +117,7 @@ func (wg *WG) init(srcport, dstport, mtu uint16) {
|
|||||||
PubicKey: &peerkey,
|
PubicKey: &peerkey,
|
||||||
KeepAliveDur: peer.KeepAliveSeconds,
|
KeepAliveDur: peer.KeepAliveSeconds,
|
||||||
QueryTick: peer.QuerySeconds,
|
QueryTick: peer.QuerySeconds,
|
||||||
|
MTU: uint16(peer.MTU),
|
||||||
AllowTrans: peer.AllowTrans,
|
AllowTrans: peer.AllowTrans,
|
||||||
NoPipe: true,
|
NoPipe: true,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user