When my QUIC client trying to communicate with QUIC server i got this kind of error
it’s related to go-quic(HTTP over QUIC protocol). please help
When my QUIC client trying to communicate with QUIC server i got this kind of error
it’s related to go-quic(HTTP over QUIC protocol). please help
Can you show us the source code?
`package main
import (
"net/http"
//"os"
//"crypto/md5"
"errors"
"flag"
"fmt"
// "io/ioutil"
"log"
// "mime/multipart"
// "net/http"
"os"
"strings"
"sync"
c "pack/config"
Error "pack/errors"
"pack/mutations"
"pack/queries"
"github.com/gorilla/mux"
"github.com/graphql-go/graphql"
"github.com/graphql-go/handler"
"github.com/spf13/viper"
_ "net/http/pprof"
"github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/http3"
"github.com/lucas-clemente/quic-go/quictrace"
// quic "github.com/lucas-clemente/quic-go"
)
func homeLink(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, “GraphQL APIs using graphql-go!”)
}
// CorsMiddleware handles CORS
func CorsMiddleware(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r http.Request) {
// allow cross domain AJAX requests
w.Header().Set(“Access-Control-Allow-Origin”, "")
w.Header().Set(“Access-Control-Allow-Headers”, “Origin, X-Requested-With, Content-Type, Accept”)
h.ServeHTTP(w, r)
})
}
type binds []string
func (b binds) String() string {
return strings.Join(b, “,”)
}
func (b *binds) Set(v string) error {
*b = strings.Split(v, “,”)
return nil
}
// Size is needed by the /demo/upload handler to determine the size of the uploaded file
type Size interface {
Size() int64
}
// See https://en.wikipedia.org/wiki/Lehmer_random_number_generator
func generatePRData(l int) []byte {
res := make([]byte, l)
seed := uint64(1)
for i := 0; i < l; i++ {
seed = seed * 48271 % 2147483647
res[i] = byte(seed)
}
return res
}
var tracer quictrace.Tracer
func init() {
tracer = quictrace.NewTracer()
}
func exportTraces() error {
traces := tracer.GetAllTraces()
if len(traces) != 1 {
return errors.New(“expected exactly one trace”)
}
for _, trace := range traces {
f, err := os.Create(“trace.qtr”)
if err != nil {
return err
}
if _, err := f.Write(trace); err != nil {
return err
}
f.Close()
fmt.Println(“Wrote trace to”, f.Name())
}
return nil
}
type tracingHandler struct {
handler http.Handler
}
var _ http.Handler = &tracingHandler{}
func (h *tracingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.handler.ServeHTTP(w, r)
if err := exportTraces(); err != nil {
log.Fatal(err)
}
}
func setupHandler(www string, trace bool) http.Handler {
// mux := http.NewServeMux()
schemaConfig := graphql.SchemaConfig{
Query: graphql.NewObject(graphql.ObjectConfig{
Name: “RootQuery”,
Fields: queries.GetRootFields(),
}),
Mutation: graphql.NewObject(graphql.ObjectConfig{
Name: “RootMutation”,
Fields: mutations.GetRootFields(),
}),
}
schema, err := graphql.NewSchema(schemaConfig)
if err != nil {
log.Fatalf("Failed to create new schema, error: %v", err)
}
httpHandler := handler.New(&handler.Config{
Schema: &schema,
Pretty: true,
})
router := mux.NewRouter().StrictSlash(true)
if len(www) > 0 {
router.Handle("/", http.FileServer(http.Dir(www)))
} else {
// router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// fmt.Fprintf(w, "GraphQL APIs using graphql-go!")
// })
router.Handle("/v1", CorsMiddleware(httpHandler))
router.HandleFunc("/", homeLink)
log.New(os.Stdout, "product-api", log.LstdFlags)
if _, err := c.Client.Ping().Result(); err != nil {
e := Error.Wrap(err, ",Redis server down,", http.StatusBadGateway)
log.Println(e)
}
}
if !trace {
return router
}
return &tracingHandler{handler: router}
}
func main() {
// // Set the file name of the configurations file
viper.SetConfigName("config")
// Set the path to look for the configurations file
viper.AddConfigPath("./config")
viper.SetConfigType("yml")
// Enable VIPER to read Environment Variables
viper.AutomaticEnv()
var configuration c.Configurations
if err := viper.ReadInConfig(); err != nil {
fmt.Printf("Error reading config file, %s", err)
}
err := viper.Unmarshal(&configuration)
if err != nil {
fmt.Printf("Unable to decode into struct, %v", err)
}
// //log.Printf(" Server started on http://localhost:8080/\n")
// // GraphQl schema configuration
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
// runtime.SetBlockProfileRate(1)
// verbose := flag.Bool("v", false, "verbose")
bs := binds{}
flag.Var(&bs, "bind", "bind to")
www := flag.String("www", "", "www data")
tcp := flag.Bool("tcp", true, "also listen on TCP")
trace := flag.Bool("trace", false, "enable quic-trace")
// qlog := flag.Bool("qlog", false, "output a qlog (in the same directory)")
flag.Parse()
// logger := utils.DefaultLogger
// if *verbose {
// logger.SetLogLevel(utils.LogLevelDebug)
// } else {
// logger.SetLogLevel(utils.LogLevelInfo)
// }
// logger.SetLogTimeFormat("")
if len(bs) == 0 {
bs = binds{"localhost:8080"}
}
handler := setupHandler(*www, *trace)
quicConf := &quic.Config{}
if *trace {
quicConf.QuicTracer = tracer
}
// if *qlog {
// quicConf.GetLogWriter = func(connID []byte) io.WriteCloser {
// filename := fmt.Sprintf("server_%x.qlog", connID)
// f, err := os.Create(filename)
// if err != nil {
// log.Fatal(err)
// }
// log.Printf("Creating qlog file %s.\n", filename)
// return utils.NewBufferedWriteCloser(bufio.NewWriter(f), f)
// }
// }
var certFile = "/home/vishnu/Documents/quic-go/internal/testdata/cert.pem"
var keyFile = "/home/vishnu/Documents/quic-go/internal/testdata/priv.key"
var wg sync.WaitGroup
wg.Add(len(bs))
for _, b := range bs {
bCap := b
go func() {
var err error
if *tcp {
log.Println("Server started on tcp")
err = http3.ListenAndServe(bCap, certFile, keyFile, handler)
} else {
log.Println("Server started")
server := http3.Server{
Server: &http.Server{Handler: handler, Addr: bCap},
QuicConfig: quicConf,
}
err = server.ListenAndServeTLS(certFile, keyFile)
}
if err != nil {
fmt.Println(err)
}
wg.Done()
}()
}
wg.Wait()
}`
When I try to build, I’m missing packages, so I ran go get
and I got these errors:
$ go get
package pack/config: unrecognized import path "pack/config" (import path does not begin with hostname)
package pack/errors: unrecognized import path "pack/errors" (import path does not begin with hostname)
package pack/mutations: unrecognized import path "pack/mutations" (import path does not begin with hostname)
package pack/queries: unrecognized import path "pack/queries" (import path does not begin with hostname)
Is your source code available on github or gitlab, etc.?
Thanks for you replay @skillian
in that code , you can get rid of that this code
schemaConfig := graphql.SchemaConfig{
Query: graphql.NewObject(graphql.ObjectConfig{
Name: "RootQuery",
Fields: queries.GetRootFields(),
}),
Mutation: graphql.NewObject(graphql.ObjectConfig{
Name: "RootMutation",
Fields: mutations.GetRootFields(),
}),
}
schema, err := graphql.NewSchema(schemaConfig)
if err != nil {
log.Fatalf("Failed to create new schema, error: %v", err)
}
httpHandler := handler.New(&handler.Config{
Schema: &schema,
Pretty: true,
}) and router.Handle("/v1", CorsMiddleware(httpHandler))
if _, err := c.Client.Ping().Result(); err != nil {
e := Error.Wrap(err, ",Redis server down,", http.StatusBadGateway)
log.Println(e)
}
and you can test router.HandleFunc("/", homeLink), only, then you doesn’t need those packages
anyone…?
Hi, @vishnutm, I’m still not able to build it after removing the block that you posted in your previous post. I’m now getting these errors:
# forum.golangbridge.org/client-destroying-session-with-error-no-compatible-quic-version-found_19304
/home/sean/gopath/src/forum.golangbridge.org/client-destroying-session-with-error-no-compatible-quic-version-found_19304/main.go:37:25: cannot convert func literal (type func(http.ResponseWriter, http.Request)) to type http.HandlerFunc
/home/sean/gopath/src/forum.golangbridge.org/client-destroying-session-with-error-no-compatible-quic-version-found_19304/main.go:41:14: cannot use r (type http.Request) as type *http.Request in argument to h.ServeHTTP
/home/sean/gopath/src/forum.golangbridge.org/client-destroying-session-with-error-no-compatible-quic-version-found_19304/main.go:143:39: undefined: httpHandler
/home/sean/gopath/src/forum.golangbridge.org/client-destroying-session-with-error-no-compatible-quic-version-found_19304/main.go:147:16: undefined: c
/home/sean/gopath/src/forum.golangbridge.org/client-destroying-session-with-error-no-compatible-quic-version-found_19304/main.go:149:9: undefined: Error
/home/sean/gopath/src/forum.golangbridge.org/client-destroying-session-with-error-no-compatible-quic-version-found_19304/main.go:173:20: undefined: c
Can you try making a smaller example?
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.