mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-18 17:00:26 +08:00
feat: impl. trans & ttl
This commit is contained in:
26
gold/proto/hello/hello.go
Normal file
26
gold/proto/hello/hello.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package hello
|
||||
|
||||
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.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")
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user