mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-16 19:33:09 -06:00
libp2p support
This commit is contained in:
parent
dacbae001d
commit
658ae48ed3
|
|
@ -16,6 +16,7 @@ package basecomponent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
@ -39,6 +40,8 @@ import (
|
||||||
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
||||||
typingServerAPI "github.com/matrix-org/dendrite/typingserver/api"
|
typingServerAPI "github.com/matrix-org/dendrite/typingserver/api"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
"github.com/matrix-org/go-http-js-libp2p/go_http_js_libp2p"
|
||||||
)
|
)
|
||||||
|
|
||||||
// BaseDendrite is a base for creating new instances of dendrite. It parses
|
// BaseDendrite is a base for creating new instances of dendrite. It parses
|
||||||
|
|
@ -55,6 +58,8 @@ type BaseDendrite struct {
|
||||||
Cfg *config.Dendrite
|
Cfg *config.Dendrite
|
||||||
KafkaConsumer sarama.Consumer
|
KafkaConsumer sarama.Consumer
|
||||||
KafkaProducer sarama.SyncProducer
|
KafkaProducer sarama.SyncProducer
|
||||||
|
|
||||||
|
P2pLocalNode *go_http_js_libp2p.P2pLocalNode
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBaseDendrite creates a new instance to be used by a component.
|
// NewBaseDendrite creates a new instance to be used by a component.
|
||||||
|
|
@ -78,6 +83,14 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string) *BaseDendrite {
|
||||||
kafkaConsumer, kafkaProducer = setupKafka(cfg)
|
kafkaConsumer, kafkaProducer = setupKafka(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var node *go_http_js_libp2p.P2pLocalNode
|
||||||
|
if cfg.Matrix.ServerName == "p2p-js" {
|
||||||
|
fmt.Println("NewP2pLocalNode")
|
||||||
|
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)
|
||||||
|
fmt.Println("ServerName: ", node.Id)
|
||||||
|
}
|
||||||
|
|
||||||
return &BaseDendrite{
|
return &BaseDendrite{
|
||||||
componentName: componentName,
|
componentName: componentName,
|
||||||
//tracerCloser: closer,
|
//tracerCloser: closer,
|
||||||
|
|
@ -85,6 +98,8 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string) *BaseDendrite {
|
||||||
APIMux: mux.NewRouter().UseEncodedPath(),
|
APIMux: mux.NewRouter().UseEncodedPath(),
|
||||||
KafkaConsumer: kafkaConsumer,
|
KafkaConsumer: kafkaConsumer,
|
||||||
KafkaProducer: kafkaProducer,
|
KafkaProducer: kafkaProducer,
|
||||||
|
|
||||||
|
P2pLocalNode: node,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,9 +181,23 @@ func (b *BaseDendrite) CreateKeyDB() keydb.Database {
|
||||||
// CreateFederationClient creates a new federation client. Should only be called
|
// CreateFederationClient creates a new federation client. Should only be called
|
||||||
// once per component.
|
// once per component.
|
||||||
func (b *BaseDendrite) CreateFederationClient() *gomatrixserverlib.FederationClient {
|
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)
|
||||||
|
|
||||||
|
fed := gomatrixserverlib.NewFederationClient(
|
||||||
|
b.Cfg.Matrix.ServerName, b.Cfg.Matrix.KeyID, b.Cfg.Matrix.PrivateKey,
|
||||||
|
)
|
||||||
|
fed.Client = *gomatrixserverlib.NewClientWithTransport(tr)
|
||||||
|
|
||||||
|
return fed
|
||||||
|
} else {
|
||||||
|
fmt.Println("Running in regular federation mode")
|
||||||
return gomatrixserverlib.NewFederationClient(
|
return gomatrixserverlib.NewFederationClient(
|
||||||
b.Cfg.Matrix.ServerName, b.Cfg.Matrix.KeyID, b.Cfg.Matrix.PrivateKey,
|
b.Cfg.Matrix.ServerName, b.Cfg.Matrix.KeyID, b.Cfg.Matrix.PrivateKey,
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetupAndServeHTTP sets up the HTTP server to serve endpoints registered on
|
// SetupAndServeHTTP sets up the HTTP server to serve endpoints registered on
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue