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

优化封装

This commit is contained in:
fumiama
2022-01-01 14:57:57 +08:00
parent a904ec5973
commit 331e57d221
2 changed files with 8 additions and 5 deletions

View File

@@ -92,7 +92,14 @@ func (m *Me) MTU() uint16 {
return m.mtu
}
func (m *Me) Close() error {
m.nic.Down()
return m.nic.Close()
}
func (m *Me) ListenFromNIC() {
m.nic.Up()
// 双缓冲区
buf := make([]byte, m.MTU()+68) // 增加报头长度与 TEA 冗余
buf2 := make([]byte, m.MTU()+68) // 增加报头长度与 TEA 冗余

View File

@@ -19,7 +19,6 @@ type WG struct {
c *config.Config
key [32]byte
PublicKey string
nic lower.NICIO
me link.Me
}
@@ -49,19 +48,16 @@ func NewWireGold(c *config.Config) (wg WG, err error) {
func (wg *WG) Start(srcport, destport, mtu uint16) {
wg.init(srcport, destport, mtu)
wg.nic.Up()
go wg.me.ListenFromNIC()
}
func (wg *WG) Run(srcport, destport, mtu uint16) {
wg.init(srcport, destport, mtu)
wg.nic.Up()
wg.me.ListenFromNIC()
}
func (wg *WG) Stop() {
wg.nic.Close()
wg.nic.Down()
_ = wg.me.Close()
}
func (wg *WG) init(srcport, destport, mtu uint16) {