mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-28 06:40:26 +08:00
feat: impl. new protol design & new head
This commit is contained in:
30
gold/proto/hello.go
Normal file
30
gold/proto/hello.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package proto
|
||||
|
||||
import (
|
||||
"github.com/fumiama/orbyte/pbuf"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/fumiama/WireGold/gold/head"
|
||||
"github.com/fumiama/WireGold/gold/link"
|
||||
"github.com/fumiama/WireGold/internal/file"
|
||||
)
|
||||
|
||||
func init() {
|
||||
link.AddProto(head.ProtoHello, func(_ *head.Packet, peer *link.Link, data pbuf.Bytes) {
|
||||
onHello(data, peer)
|
||||
})
|
||||
}
|
||||
|
||||
func onHello(data pbuf.Bytes, p *link.Link) {
|
||||
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 p.WritePacket(head.ProtoHello, []byte{byte(head.HelloPong)})
|
||||
logrus.Infoln(file.Header(), "recv, send ack")
|
||||
default:
|
||||
logrus.Infoln(file.Header(), "recv ack, do nothing")
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user