You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
846 B
Go
35 lines
846 B
Go
2 years ago
|
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
|
||
|
}),
|
||
|
}
|
||
|
}
|