mirror of
https://github.com/fumiama/WireGold.git
synced 2026-07-02 08:30:25 +08:00
优化代码结构
This commit is contained in:
@@ -92,7 +92,10 @@ func NewMe(cfg *MyConfig) (m Me) {
|
|||||||
m.srcport = cfg.SrcPort
|
m.srcport = cfg.SrcPort
|
||||||
m.dstport = cfg.DstPort
|
m.dstport = cfg.DstPort
|
||||||
m.mtu = cfg.MTU & 0xfff8
|
m.mtu = cfg.MTU & 0xfff8
|
||||||
m.initrecvpool()
|
if m.writer == nil {
|
||||||
|
m.writer = helper.SelectWriter()
|
||||||
|
}
|
||||||
|
m.recving = ttl.NewCache[[32]byte, *head.Packet](time.Second * 128)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,10 @@ package link
|
|||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"time"
|
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/fumiama/WireGold/gold/head"
|
"github.com/fumiama/WireGold/gold/head"
|
||||||
"github.com/fumiama/WireGold/helper"
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/wdvxdr1123/ZeroBot/extension/ttl"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Read 从 peer 收包
|
// Read 从 peer 收包
|
||||||
@@ -17,13 +14,6 @@ func (l *Link) Read() *head.Packet {
|
|||||||
return <-l.pipe
|
return <-l.pipe
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Me) initrecvpool() {
|
|
||||||
if m.writer == nil {
|
|
||||||
m.writer = helper.SelectWriter()
|
|
||||||
}
|
|
||||||
m.recving = ttl.NewCache[[32]byte, *head.Packet](time.Second * 128)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Me) wait(data []byte) *head.Packet {
|
func (m *Me) wait(data []byte) *head.Packet {
|
||||||
flags := binary.LittleEndian.Uint16(data[10:12])
|
flags := binary.LittleEndian.Uint16(data[10:12])
|
||||||
logrus.Debugln("[recv]", len(data), "bytes data with flag", hex.EncodeToString(data[10:12]))
|
logrus.Debugln("[recv]", len(data), "bytes data with flag", hex.EncodeToString(data[10:12]))
|
||||||
|
|||||||
Reference in New Issue
Block a user