mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-22 11:30:31 +08:00
优化封装
This commit is contained in:
@@ -92,7 +92,14 @@ func (m *Me) MTU() uint16 {
|
|||||||
return m.mtu
|
return m.mtu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Me) Close() error {
|
||||||
|
m.nic.Down()
|
||||||
|
return m.nic.Close()
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Me) ListenFromNIC() {
|
func (m *Me) ListenFromNIC() {
|
||||||
|
m.nic.Up()
|
||||||
|
|
||||||
// 双缓冲区
|
// 双缓冲区
|
||||||
buf := make([]byte, m.MTU()+68) // 增加报头长度与 TEA 冗余
|
buf := make([]byte, m.MTU()+68) // 增加报头长度与 TEA 冗余
|
||||||
buf2 := make([]byte, m.MTU()+68) // 增加报头长度与 TEA 冗余
|
buf2 := make([]byte, m.MTU()+68) // 增加报头长度与 TEA 冗余
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ type WG struct {
|
|||||||
c *config.Config
|
c *config.Config
|
||||||
key [32]byte
|
key [32]byte
|
||||||
PublicKey string
|
PublicKey string
|
||||||
nic lower.NICIO
|
|
||||||
me link.Me
|
me link.Me
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,19 +48,16 @@ func NewWireGold(c *config.Config) (wg WG, err error) {
|
|||||||
|
|
||||||
func (wg *WG) Start(srcport, destport, mtu uint16) {
|
func (wg *WG) Start(srcport, destport, mtu uint16) {
|
||||||
wg.init(srcport, destport, mtu)
|
wg.init(srcport, destport, mtu)
|
||||||
wg.nic.Up()
|
|
||||||
go wg.me.ListenFromNIC()
|
go wg.me.ListenFromNIC()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wg *WG) Run(srcport, destport, mtu uint16) {
|
func (wg *WG) Run(srcport, destport, mtu uint16) {
|
||||||
wg.init(srcport, destport, mtu)
|
wg.init(srcport, destport, mtu)
|
||||||
wg.nic.Up()
|
|
||||||
wg.me.ListenFromNIC()
|
wg.me.ListenFromNIC()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wg *WG) Stop() {
|
func (wg *WG) Stop() {
|
||||||
wg.nic.Close()
|
_ = wg.me.Close()
|
||||||
wg.nic.Down()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wg *WG) init(srcport, destport, mtu uint16) {
|
func (wg *WG) init(srcport, destport, mtu uint16) {
|
||||||
|
|||||||
Reference in New Issue
Block a user