Compare commits
4 commits
main
...
matthew/p2
Author | SHA1 | Date | |
---|---|---|---|
85a582b834 | |||
42b1adf442 | |||
90a96c698c | |||
8a52f2afdc |
2
build.sh
2
build.sh
|
@ -1,3 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
GOBIN=$PWD/`dirname $0`/bin go install -v $PWD/`dirname $0`/cmd/...
|
||||
GOOS=js GOARCH=wasm GOBIN=$PWD/`dirname $0`/bin go build -v -o bin/dendrite.wasm $PWD/`dirname $0`/cmd/dendrite-monolith-server
|
||||
|
|
|
@ -33,6 +33,8 @@ import (
|
|||
"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/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
@ -80,17 +82,38 @@ 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))
|
||||
// }()
|
||||
|
||||
// Expose the matrix APIs via libp2p-js
|
||||
if base.P2pLocalNode != nil {
|
||||
go func() {
|
||||
logrus.Info("Listening on ", *httpBindAddr)
|
||||
logrus.Fatal(http.ListenAndServe(*httpBindAddr, nil))
|
||||
logrus.Info("Listening on libp2p-js host ID ", base.P2pLocalNode.Id)
|
||||
|
||||
listener := go_http_js_libp2p.NewP2pListener(base.P2pLocalNode)
|
||||
defer listener.Close()
|
||||
s := &http.Server{}
|
||||
s.Serve(listener)
|
||||
}()
|
||||
// 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)
|
||||
}()
|
||||
}
|
||||
}()
|
||||
|
||||
// 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))
|
||||
// }
|
||||
// }()
|
||||
|
||||
// We want to block forever to let the HTTP and HTTPS handler serve the APIs
|
||||
select {}
|
||||
|
|
|
@ -17,6 +17,7 @@ package basecomponent
|
|||
import (
|
||||
"database/sql"
|
||||
"io"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"golang.org/x/crypto/ed25519"
|
||||
|
@ -29,6 +30,8 @@ import (
|
|||
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
|
||||
"github.com/matrix-org/dendrite/common"
|
||||
|
||||
"github.com/matrix-org/go-http-js-libp2p/go_http_js_libp2p"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
sarama "gopkg.in/Shopify/sarama.v1"
|
||||
|
||||
|
@ -54,6 +57,8 @@ type BaseDendrite struct {
|
|||
Cfg *config.Dendrite
|
||||
KafkaConsumer sarama.Consumer
|
||||
KafkaProducer sarama.SyncProducer
|
||||
|
||||
P2pLocalNode *go_http_js_libp2p.P2pLocalNode
|
||||
}
|
||||
|
||||
// NewBaseDendrite creates a new instance to be used by a component.
|
||||
|
@ -70,6 +75,12 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string) *BaseDendrite {
|
|||
|
||||
kafkaConsumer, kafkaProducer := setupKafka(cfg)
|
||||
|
||||
var node *go_http_js_libp2p.P2pLocalNode
|
||||
if cfg.Matrix.ServerName == "p2p-js" {
|
||||
node = go_http_js_libp2p.NewP2pLocalNode("org.matrix.p2p.experiment", []string{"/ip4/127.0.0.1/tcp/9090/ws/p2p-websocket-star/"})
|
||||
cfg.Matrix.ServerName = gomatrixserverlib.ServerName(node.Id)
|
||||
}
|
||||
|
||||
return &BaseDendrite{
|
||||
componentName: componentName,
|
||||
tracerCloser: closer,
|
||||
|
@ -77,6 +88,7 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string) *BaseDendrite {
|
|||
APIMux: mux.NewRouter().UseEncodedPath(),
|
||||
KafkaConsumer: kafkaConsumer,
|
||||
KafkaProducer: kafkaProducer,
|
||||
P2pLocalNode: node,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,10 +169,20 @@ func (b *BaseDendrite) CreateKeyDB() keydb.Database {
|
|||
// CreateFederationClient creates a new federation client. Should only be called
|
||||
// once per component.
|
||||
func (b *BaseDendrite) CreateFederationClient() *gomatrixserverlib.FederationClient {
|
||||
if b.P2pLocalNode != nil {
|
||||
fmt.Println("Running in js-libp2p federation mode")
|
||||
fmt.Println("Warning: Federation with non-libp2p homeservers will not work in this mode yet!")
|
||||
tr := go_http_js_libp2p.NewP2pTransport(b.P2pLocalNode)
|
||||
return gomatrixserverlib.NewFederationClientWithTransport(
|
||||
b.Cfg.Matrix.ServerName, b.Cfg.Matrix.KeyID, b.Cfg.Matrix.PrivateKey, tr,
|
||||
)
|
||||
} else {
|
||||
fmt.Println("Running in regular federation mode")
|
||||
return gomatrixserverlib.NewFederationClient(
|
||||
b.Cfg.Matrix.ServerName, b.Cfg.Matrix.KeyID, b.Cfg.Matrix.PrivateKey,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// SetupAndServeHTTP sets up the HTTP server to serve endpoints registered on
|
||||
// ApiMux under /api/ and adds a prometheus handler under /metrics.
|
||||
|
|
6
go.mod
6
go.mod
|
@ -13,11 +13,11 @@ 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-20200125063821-6eb06b102bda
|
||||
github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20200124100636-0c2ec91d1df5
|
||||
github.com/matrix-org/naffka v0.0.0-20171115094957-662bfd0841d0
|
||||
github.com/matrix-org/util v0.0.0-20171127121716-2e2df66af2f5
|
||||
github.com/miekg/dns v1.1.12 // indirect
|
||||
github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5
|
||||
github.com/opentracing/opentracing-go v1.0.2
|
||||
github.com/pierrec/lz4 v0.0.0-20161206202305-5c9560bfa9ac // indirect
|
||||
|
@ -40,4 +40,8 @@ require (
|
|||
gopkg.in/yaml.v2 v2.2.2
|
||||
)
|
||||
|
||||
replace github.com/matrix-org/go-http-js-libp2p v0.0.0-20200125063821-6eb06b102bda => ../go-http-js-libp2p
|
||||
|
||||
replace github.com/matrix-org/gomatrixserverlib v0.0.0-20200124100636-0c2ec91d1df5 => ../gomatrixserverlib
|
||||
|
||||
go 1.13
|
||||
|
|
1
go.sum
1
go.sum
|
@ -63,7 +63,6 @@ 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/gomatrix v0.0.0-20190130130140-385f072fe9af h1:piaIBNQGIHnni27xRB7VKkEwoWCgAmeuYf8pxAyG0bI=
|
||||
github.com/matrix-org/gomatrix v0.0.0-20190130130140-385f072fe9af/go.mod h1:3fxX6gUjWyI/2Bt7J1OLhpCzOfO/bB3AiX0cJtEKud0=
|
||||
github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26 h1:Hr3zjRsq2bhrnp3Ky1qgx/fzCtCALOoGYylh2tpS9K4=
|
||||
github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26/go.mod h1:3fxX6gUjWyI/2Bt7J1OLhpCzOfO/bB3AiX0cJtEKud0=
|
||||
|
|
Loading…
Reference in a new issue