From bf6aa8cfd566ee33c41f1d0bc0ab7b38fed77e70 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Tue, 25 Feb 2020 18:07:36 +0000 Subject: [PATCH] Listen for fetch traffic rather than HTTP --- clientapi/routing/register.go | 4 ++-- cmd/dendritejs/main.go | 16 ++++++---------- go.mod | 1 + go.sum | 2 ++ 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/clientapi/routing/register.go b/clientapi/routing/register.go index 9d67d9982..18ece4755 100644 --- a/clientapi/routing/register.go +++ b/clientapi/routing/register.go @@ -444,7 +444,8 @@ func Register( deviceDB devices.Database, cfg *config.Dendrite, ) util.JSONResponse { - + logger := util.GetLogger(req.Context()) + logger.Info("Incoming request info: " + fmt.Sprintf("%+v", req)) var r registerRequest resErr := httputil.UnmarshalJSONRequest(req, &r) if resErr != nil { @@ -499,7 +500,6 @@ func Register( } } - logger := util.GetLogger(req.Context()) logger.WithFields(log.Fields{ "username": r.Username, "auth.type": r.Auth.Type, diff --git a/cmd/dendritejs/main.go b/cmd/dendritejs/main.go index 44579df04..3b6f59547 100644 --- a/cmd/dendritejs/main.go +++ b/cmd/dendritejs/main.go @@ -35,6 +35,7 @@ import ( "github.com/matrix-org/dendrite/syncapi" "github.com/matrix-org/dendrite/typingserver" "github.com/matrix-org/dendrite/typingserver/cache" + "github.com/matrix-org/go-http-js-libp2p/go_http_js_libp2p" "github.com/sirupsen/logrus" @@ -109,17 +110,12 @@ func main() { http.Handle("/", httpHandler) - // Expose the matrix APIs directly rather than putting them under a /api path. go func() { - logrus.Info("Listening on ", *httpBindAddr) - logrus.Fatal(http.ListenAndServe(*httpBindAddr, nil)) - }() - // Handle HTTPS if certificate and key are provided - go func() { - if *certFile != "" && *keyFile != "" { - logrus.Info("Listening on ", *httpsBindAddr) - logrus.Fatal(http.ListenAndServeTLS(*httpsBindAddr, *certFile, *keyFile, nil)) - } + logrus.Info("Listening for service-worker fetch traffic") + + listener := go_http_js_libp2p.NewFetchListener() + s := &http.Server{} + go s.Serve(listener) }() // We want to block forever to let the HTTP and HTTPS handler serve the APIs diff --git a/go.mod b/go.mod index 128b7578f..861ffd7a2 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect github.com/lib/pq v1.2.0 github.com/matrix-org/dugong v0.0.0-20171220115018-ea0a4690a0d5 + github.com/matrix-org/go-http-js-libp2p v0.0.0-20200126031050-234d7bbbff9a github.com/matrix-org/go-sqlite3-js v0.0.0-20200225115056-c0aef2609ba2 github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26 github.com/matrix-org/gomatrixserverlib v0.0.0-20200124100636-0c2ec91d1df5 diff --git a/go.sum b/go.sum index 1cec04c87..04621a153 100644 --- a/go.sum +++ b/go.sum @@ -65,6 +65,8 @@ github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0= github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/matrix-org/dugong v0.0.0-20171220115018-ea0a4690a0d5 h1:nMX2t7hbGF0NYDYySx0pCqEKGKAeZIiSqlWSspetlhY= github.com/matrix-org/dugong v0.0.0-20171220115018-ea0a4690a0d5/go.mod h1:NgPCr+UavRGH6n5jmdX8DuqFZ4JiCWIJoZiuhTRLSUg= +github.com/matrix-org/go-http-js-libp2p v0.0.0-20200126031050-234d7bbbff9a h1:ZsaauiZcUC8lCE0iZ/Oc/LYMEZDkJLSWTpzleAD662I= +github.com/matrix-org/go-http-js-libp2p v0.0.0-20200126031050-234d7bbbff9a/go.mod h1:3WluEZ9QXSwU30tWYqktnpC1x9mwZKx1r8uAv8Iq+a4= github.com/matrix-org/go-sqlite3-js v0.0.0-20200220181445-d8f0009820f1 h1:vFk1IC6gbT+1p+/BgtSwzy5rpI1KGskOvMZxLKSGeho= github.com/matrix-org/go-sqlite3-js v0.0.0-20200220181445-d8f0009820f1/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo= github.com/matrix-org/go-sqlite3-js v0.0.0-20200222210301-d686541685d3 h1:pV+1GBKVN4dLkpavy9LXwlemTX2FN4Zw7pSEpbVoPdw=