You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.4 KiB

package network
import (
"crypto/tls"
"git.hpds.cc/Component/network/frame"
"github.com/quic-go/quic-go"
"time"
"git.hpds.cc/Component/network/auth"
pkgtls "git.hpds.cc/Component/network/tls"
)
// clientOptions are the options for YoMo client.
type clientOptions struct {
observeDataTags []frame.Tag
quicConfig *quic.Config
tlsConfig *tls.Config
credential *auth.Credential
}
func defaultClientOption() *clientOptions {
defaultQuicConfig := &quic.Config{
Versions: []quic.VersionNumber{quic.VersionDraft29, quic.Version1, quic.Version2},
MaxIdleTimeout: time.Second * 40,
KeepAlivePeriod: time.Second * 20,
MaxIncomingStreams: 1000,
MaxIncomingUniStreams: 1000,
HandshakeIdleTimeout: time.Second * 3,
InitialStreamReceiveWindow: 1024 * 1024 * 2,
InitialConnectionReceiveWindow: 1024 * 1024 * 2,
TokenStore: quic.NewLRUTokenStore(10, 5),
}
opts := &clientOptions{
observeDataTags: make([]frame.Tag, 0),
quicConfig: defaultQuicConfig,
tlsConfig: pkgtls.MustCreateClientTLSConfig(),
credential: auth.NewCredential(""),
}
return opts
}
// WithObserveDataTags sets data tag list for the client.
func WithObserveDataTags(tags ...frame.Tag) ClientOption {
return func(o *clientOptions) {
o.observeDataTags = tags
}
}
// WithCredential sets the client credential method (used by client).
func WithCredential(payload string) ClientOption {
return func(o *clientOptions) {
o.credential = auth.NewCredential(payload)
}
}
// WithClientTLSConfig sets tls config for the client.
func WithClientTLSConfig(tc *tls.Config) ClientOption {
return func(o *clientOptions) {
if tc != nil {
o.tlsConfig = tc
}
}
}
// WithClientQuicConfig sets quic config for the client.
func WithClientQuicConfig(qc *quic.Config) ClientOption {
return func(o *clientOptions) {
o.quicConfig = qc
}
}
// ClientType is equal to StreamType.
type ClientType = StreamType
const (
// ClientTypeSource is equal to StreamTypeSource.
ClientTypeSource ClientType = StreamTypeSource
// ClientTypeUpstreamEmitter is equal to StreamTypeUpstreamEmitter.
ClientTypeUpstreamEmitter ClientType = StreamTypeUpstreamEmitter
// ClientTypeStreamFunction is equal to StreamTypeStreamFunction.
ClientTypeStreamFunction ClientType = StreamTypeStreamFunction
)