Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: using Hertz's tls configuration #8

Merged
merged 2 commits into from
Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions network/quic-go/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
errs "github.com/cloudwego/hertz/pkg/common/errors"
"github.com/cloudwego/hertz/pkg/common/hlog"
"github.com/cloudwego/hertz/pkg/network"
"github.com/hertz-contrib/http3/network/quic-go/testdata"
"github.com/quic-go/quic-go"
"github.com/quic-go/quic-go/http3"
)
Expand All @@ -52,25 +51,14 @@ func (t *transport) Shutdown(ctx context.Context) error {

func (t *transport) ListenAndServe(onData network.OnData) error {
t.handler = onData
return t.ListenAndServeTLS(testdata.GetCertificatePaths())
return t.ListenAndServeTLS()
}

// ListenAndServeTLS listens on the UDP address s.Addr and calls s.Handler to handle HTTP/3 requests on incoming connections.
//
// If s.Addr is blank, ":https" is used.
func (t *transport) ListenAndServeTLS(certFile, keyFile string) error {
var err error
certs := make([]tls.Certificate, 1)
certs[0], err = tls.LoadX509KeyPair(certFile, keyFile)
if err != nil {
return err
}
// We currently only use the cert-related stuff from tls.Config,
// so we don't need to make a full copy.
config := &tls.Config{
Certificates: certs,
}
return t.serveConn(config, nil)
func (t *transport) ListenAndServeTLS() error {
return t.serveConn(t.TLSConfig, nil)
}

func (t *transport) serveConn(tlsConf *tls.Config, conn net.PacketConn) error {
Expand Down
Loading