Documentation ¶
Index ¶
- Constants
- Variables
- func CreateUdpAddr(ip string, port int) (*net.UDPAddr, error)
- func CreateUdpConn(host string, port int) *net.UDPConn
- func ParseRecord(rec *[]byte) (gudp_protos.GudpMessageType, error)
- type AnyMessage
- type AuthClient
- type Client
- type ClientEvent
- type ClientEventName
- type DefaultAuthClient
- type HandlerFunc
- type Option
- func WithAsymmetricCrypto(ac crypto.Asymmetric) Option
- func WithAuthClient(ac AuthClient) Option
- func WithHeartbeatExpiration(t time.Duration) Option
- func WithLogger(l *log.Logger) Option
- func WithMinimumPayloadSize(i int) Option
- func WithProtosolVersion(major, minor uint8) Option
- func WithReadBufferSize(i int) Option
- func WithSymmetricCrypto(sc crypto.Symmetric) Option
- func WithTranscoder(t encoding.Transcoder) Option
- type PacketData
- type PacketQueue
- type ReliabilitySystem
- func (rs *ReliabilitySystem) AckedBandwidth() float64
- func (rs *ReliabilitySystem) AckedPackets() uint32
- func (rs *ReliabilitySystem) Acks() []uint32
- func (rs *ReliabilitySystem) GenerateAckBits() uint32
- func (rs *ReliabilitySystem) HeaderSize() int
- func (rs *ReliabilitySystem) LocalSequence() uint32
- func (rs *ReliabilitySystem) LostPackets() uint32
- func (rs *ReliabilitySystem) MaxSequence() uint32
- func (rs *ReliabilitySystem) PacketReceived(sequence uint32, size int)
- func (rs *ReliabilitySystem) PacketSent(size int)
- func (rs *ReliabilitySystem) ProcessAck(ack, ackBits uint32)
- func (rs *ReliabilitySystem) ReceivedPackets() uint32
- func (rs *ReliabilitySystem) RemoteSequence() uint32
- func (rs *ReliabilitySystem) Reset()
- func (rs *ReliabilitySystem) RoundTripTime() time.Duration
- func (rs *ReliabilitySystem) SentBandwidth() float64
- func (rs *ReliabilitySystem) SentPackets() uint32
- func (rs *ReliabilitySystem) Update(deltaTime time.Duration)
- type Rpc
- type Server
- func (s *Server) FindClientByAddr(addr *net.UDPAddr) (*Client, bool)
- func (s *Server) RegisterEvent(eventFunc func(*ClientEvent))
- func (s *Server) RegisterRpc(rcvr any)
- func (s *Server) SendClientMessage(cli *Client, bytes []byte, reliability bool) error
- func (s *Server) SendMessage(addr *net.UDPAddr, bytes []byte, reliability bool) error
- func (s *Server) Serve()
- func (s *Server) SetHandler(f HandlerFunc)
Constants ¶
const ( HandshakeClientHelloRecordType byte = 1 << iota HandshakeHelloVerifyRecordType HandshakeServerHelloRecordType PingRecordType PongRecordType UnAuthenticated )
Variables ¶
var ( ErrInvalidRecordType = errors.New("invalid record type") ErrInsecureEncryptionKeySize = errors.New("insecure encryption key size") ErrClientSessionNotFound = errors.New("client session not found") ErrClientAddressIsNotRegistered = errors.New("client address is not registered") ErrClientNotFound = errors.New("client not found") ErrMinimumPayloadSizeLimit = errors.New("minimum payload size limit") ErrClientCookieIsInvalid = errors.New("client cookie is invalid") ErrInvalidPayloadBodySize = errors.New("payload body size is invalid") )
custom error types
Functions ¶
func ParseRecord ¶
func ParseRecord(rec *[]byte) (gudp_protos.GudpMessageType, error)
parseRecord 解析消息返回对应的类型
Types ¶
type AnyMessage ¶
type AnyMessage struct { protoiface.MessageV1 ReliableMessage *gudp_protos.ReliableMessage UnreliableMessage *gudp_protos.UnreliableMessage }
type AuthClient ¶
An interface for authenticating the client token
type Client ¶
func (*Client) ValidateSessionID ¶
ValidateSessionID compares the client session ID with the given one
type ClientEvent ¶
type ClientEvent struct { Name ClientEventName `json:"name"` Client *Client `json:"client"` }
type ClientEventName ¶
type ClientEventName int
const ( ClientEventName_Client_Join ClientEventName = iota ClientEventName_Client_Leave )
type DefaultAuthClient ¶
type DefaultAuthClient struct{}
A simple implementation of auth client if no authentication is required
func (*DefaultAuthClient) Authenticate ¶
Only generates a new UUID for the user without any authentication
type HandlerFunc ¶
HandlerFunc is called when a custom message type is received from the client
type Option ¶
type Option func(*Server)
func WithAsymmetricCrypto ¶
func WithAsymmetricCrypto(ac crypto.Asymmetric) Option
WithAsymmetricCrypto sets the asymmetric cryptography implementation
func WithAuthClient ¶
func WithAuthClient(ac AuthClient) Option
WithAuthClient sets the auth client implementation
func WithHeartbeatExpiration ¶
WithHeartbeatExpiration sets the server heartbeat expiration option
func WithMinimumPayloadSize ¶
WithMinimumPayloadSize sets the minimum payload size option
func WithProtosolVersion ¶
WithProtosolVersion sets the server protosol version
func WithReadBufferSize ¶
WithReadBufferSize sets the read buffer size option
func WithSymmetricCrypto ¶
WithSymmetricCrypto sets the symmetric cryptography implementation
func WithTranscoder ¶
func WithTranscoder(t encoding.Transcoder) Option
WithTranscoder sets the transcoder implementation
type PacketData ¶
type PacketData struct {
// contains filtered or unexported fields
}
type PacketQueue ¶
type PacketQueue []PacketData
TODO: check if its better to have a slice of pointers to PacketData
func (*PacketQueue) Exists ¶
func (pq *PacketQueue) Exists(sequence uint32) bool
func (*PacketQueue) InsertSorted ¶
func (pq *PacketQueue) InsertSorted(p PacketData, maxSequence uint32)
type ReliabilitySystem ¶
type ReliabilitySystem struct {
// contains filtered or unexported fields
}
这些参数共同构成了可靠传输系统的核心部分,实现了数据包的确认、重传、丢失恢复和统计信息收集等功能。通过综合运用这些参数,系统能够保障数据包的可靠传输和相关的传输状态跟踪。 reliability system to support reliable connection
- manages sent, received, pending ack and acked packet queues
- separated out from reliable connection so they can be unit-tested
func NewReliabilitySystem ¶
func NewReliabilitySystem(maxSequence uint32) *ReliabilitySystem
func (*ReliabilitySystem) AckedBandwidth ¶
func (rs *ReliabilitySystem) AckedBandwidth() float64
func (*ReliabilitySystem) AckedPackets ¶
func (rs *ReliabilitySystem) AckedPackets() uint32
func (*ReliabilitySystem) Acks ¶
func (rs *ReliabilitySystem) Acks() []uint32
func (*ReliabilitySystem) GenerateAckBits ¶
func (rs *ReliabilitySystem) GenerateAckBits() uint32
func (*ReliabilitySystem) HeaderSize ¶
func (rs *ReliabilitySystem) HeaderSize() int
func (*ReliabilitySystem) LocalSequence ¶
func (rs *ReliabilitySystem) LocalSequence() uint32
func (*ReliabilitySystem) LostPackets ¶
func (rs *ReliabilitySystem) LostPackets() uint32
func (*ReliabilitySystem) MaxSequence ¶
func (rs *ReliabilitySystem) MaxSequence() uint32
func (*ReliabilitySystem) PacketReceived ¶
func (rs *ReliabilitySystem) PacketReceived(sequence uint32, size int)
func (*ReliabilitySystem) ProcessAck ¶
func (rs *ReliabilitySystem) ProcessAck(ack, ackBits uint32)
func (*ReliabilitySystem) ReceivedPackets ¶
func (rs *ReliabilitySystem) ReceivedPackets() uint32
func (*ReliabilitySystem) RemoteSequence ¶
func (rs *ReliabilitySystem) RemoteSequence() uint32
func (*ReliabilitySystem) Reset ¶
func (rs *ReliabilitySystem) Reset()
func (*ReliabilitySystem) RoundTripTime ¶
func (rs *ReliabilitySystem) RoundTripTime() time.Duration
func (*ReliabilitySystem) SentBandwidth ¶
func (rs *ReliabilitySystem) SentBandwidth() float64
func (*ReliabilitySystem) SentPackets ¶
func (rs *ReliabilitySystem) SentPackets() uint32
func (*ReliabilitySystem) Update ¶
func (rs *ReliabilitySystem) Update(deltaTime time.Duration)
type Rpc ¶
type Rpc struct {
// contains filtered or unexported fields
}
func (*Rpc) ParseRequestRpc ¶
func (s *Rpc) ParseRequestRpc(req *gudp_protos.RpcMessage) (*methodType, reflect.Value, reflect.Value, error)
通过rpc消息解析调用引用类型
type Server ¶
type Server struct { Error chan error // 当服务出现错误 // contains filtered or unexported fields }
func NewServerManager ¶
func (*Server) FindClientByAddr ¶
returns the Client by IP & Port
func (*Server) RegisterEvent ¶
func (s *Server) RegisterEvent(eventFunc func(*ClientEvent))
func (*Server) SendClientMessage ¶
将消息发送到指定地址
func (*Server) SendMessage ¶
将消息发送到指定地址
func (*Server) Serve ¶
func (s *Server) Serve()
Serve starts listening to the UDP port for incoming bytes & then sends payload and sender address into the rawRecords channel if no error is found
func (*Server) SetHandler ¶
func (s *Server) SetHandler(f HandlerFunc)
SetHandler sets the handler function as a callback to call when a custom record type is received from the client