1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-21 19:13:20 +08:00

optimize: memory consumption

This commit is contained in:
源文雨
2025-05-13 00:59:05 +09:00
parent d65fc4dd71
commit df8f6affa3
19 changed files with 204 additions and 242 deletions

View File

@@ -1,7 +1,6 @@
package hello
import (
"github.com/fumiama/orbyte/pbuf"
"github.com/sirupsen/logrus"
"github.com/fumiama/WireGold/gold/head"
@@ -10,17 +9,15 @@ import (
)
func init() {
link.RegisterDispacher(head.ProtoHello, func(_ *head.Packet, peer *link.Link, data pbuf.Bytes) {
data.V(func(b []byte) {
switch {
case len(b) == 0:
logrus.Warnln(file.Header(), "recv old packet, do nothing")
case b[0] == byte(head.HelloPing):
go peer.WritePacket(head.ProtoHello, []byte{byte(head.HelloPong)}, peer.Me().TTL())
logrus.Infoln(file.Header(), "recv, send ack")
default:
logrus.Infoln(file.Header(), "recv ack, do nothing")
}
})
link.RegisterDispacher(head.ProtoHello, func(_ *head.Packet, peer *link.Link, data []byte) {
switch {
case len(data) == 0:
logrus.Warnln(file.Header(), "recv old packet, do nothing")
case data[0] == byte(head.HelloPing):
go peer.WritePacket(head.ProtoHello, []byte{byte(head.HelloPong)}, peer.Me().TTL())
logrus.Infoln(file.Header(), "recv, send ack")
default:
logrus.Infoln(file.Header(), "recv ack, do nothing")
}
})
}