57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package network
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"net"
|
|
|
|
"git.hpds.cc/Component/network/auth"
|
|
"github.com/lucas-clemente/quic-go"
|
|
)
|
|
|
|
// ServerOptions are the options for HPDS Network server.
|
|
type ServerOptions struct {
|
|
QuicConfig *quic.Config
|
|
TLSConfig *tls.Config
|
|
Addr string
|
|
Auths []auth.Authentication
|
|
Conn net.PacketConn
|
|
}
|
|
|
|
// WithAddr sets the server address.
|
|
func WithAddr(addr string) ServerOption {
|
|
return func(o *ServerOptions) {
|
|
o.Addr = addr
|
|
}
|
|
}
|
|
|
|
// WithAuth sets the server authentication method.
|
|
func WithAuth(name string, args ...string) ServerOption {
|
|
return func(o *ServerOptions) {
|
|
if auth, ok := auth.GetAuth(name); ok {
|
|
auth.Init(args...)
|
|
o.Auths = append(o.Auths, auth)
|
|
}
|
|
}
|
|
}
|
|
|
|
// WithServerTLSConfig sets the TLS configuration for the server.
|
|
func WithServerTLSConfig(tc *tls.Config) ServerOption {
|
|
return func(o *ServerOptions) {
|
|
o.TLSConfig = tc
|
|
}
|
|
}
|
|
|
|
// WithServerQuicConfig sets the QUIC configuration for the server.
|
|
func WithServerQuicConfig(qc *quic.Config) ServerOption {
|
|
return func(o *ServerOptions) {
|
|
o.QuicConfig = qc
|
|
}
|
|
}
|
|
|
|
// WithConn sets the connection for the server.
|
|
func WithConn(conn net.PacketConn) ServerOption {
|
|
return func(o *ServerOptions) {
|
|
o.Conn = conn
|
|
}
|
|
}
|