From 331e57d221483879ed75162330a47d49dc21ec46 Mon Sep 17 00:00:00 2001 From: fumiama Date: Sat, 1 Jan 2022 14:57:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gold/link/me.go | 7 +++++++ upper/services/wg/wg.go | 6 +----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/gold/link/me.go b/gold/link/me.go index b0242de..da3e204 100644 --- a/gold/link/me.go +++ b/gold/link/me.go @@ -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 冗余 diff --git a/upper/services/wg/wg.go b/upper/services/wg/wg.go index ccc986f..f62f142 100644 --- a/upper/services/wg/wg.go +++ b/upper/services/wg/wg.go @@ -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) {