package protocol import ( "git.noahlan.cn/noahlan/nnet/core" "git.noahlan.cn/noahlan/nnet/entity" "git.noahlan.cn/noahlan/nnet/middleware" "git.noahlan.cn/noahlan/nnet/packet" "git.noahlan.cn/noahlan/ntools-go/core/nlog" "time" ) type NNetConfig struct { } func WithNNetProtocol( handshakeValidator func([]byte) error, heartbeatInterval time.Duration, ) []core.RunOption { if handshakeValidator == nil { handshakeValidator = func(bytes []byte) error { return nil } } packer := NewNNetPacker() hbd, err := packer.Pack(Handshake, nil) nlog.Must(err) return []core.RunOption{ WithNNetPipeline(handshakeValidator), core.WithRouter(NewNNetRouter()), core.WithPacker(func() packet.Packer { return NewNNetPacker() }), middleware.WithHeartbeat(heartbeatInterval, func(_ entity.NetworkEntity) []byte { return hbd }), } }