diff --git a/cmd/dendrite-p2p-demo/main.go b/cmd/dendrite-p2p-demo/main.go index 0cd0fd46e..b5593d3b8 100644 --- a/cmd/dendrite-p2p-demo/main.go +++ b/cmd/dendrite-p2p-demo/main.go @@ -24,6 +24,7 @@ import ( "time" gostream "github.com/libp2p/go-libp2p-gostream" + p2phttp "github.com/libp2p/go-libp2p-http" p2pdisc "github.com/libp2p/go-libp2p/p2p/discovery" "github.com/matrix-org/dendrite/appservice" "github.com/matrix-org/dendrite/clientapi" @@ -78,6 +79,21 @@ func createKeyDB( return db } +func createFederationClient( + base *basecomponent.BaseDendrite, +) *gomatrixserverlib.FederationClient { + fmt.Println("Running in libp2p federation mode") + fmt.Println("Warning: Federation with non-libp2p homeservers will not work in this mode yet!") + tr := &http.Transport{} + tr.RegisterProtocol( + "matrix", + p2phttp.NewTransport(base.LibP2P, p2phttp.ProtocolOption("/matrix")), + ) + return gomatrixserverlib.NewFederationClientWithTransport( + base.Cfg.Matrix.ServerName, base.Cfg.Matrix.KeyID, base.Cfg.Matrix.PrivateKey, tr, + ) +} + func main() { instanceName := flag.String("name", "dendrite-p2p", "the name of this P2P demo instance") instancePort := flag.Int("port", 8080, "the port that the client API will listen on") @@ -128,7 +144,7 @@ func main() { accountDB := base.CreateAccountsDB() deviceDB := base.CreateDeviceDB() keyDB := createKeyDB(base) - federation := base.CreateFederationClient() + federation := createFederationClient(base) keyRing := keydb.CreateKeyRing(federation.Client, keyDB) alias, input, query := roomserver.SetupRoomServerComponent(base) diff --git a/common/basecomponent/base.go b/common/basecomponent/base.go index 9a398d853..a7cf820b7 100644 --- a/common/basecomponent/base.go +++ b/common/basecomponent/base.go @@ -30,7 +30,6 @@ import ( routing "github.com/libp2p/go-libp2p-core/routing" host "github.com/libp2p/go-libp2p-core/host" - p2phttp "github.com/libp2p/go-libp2p-http" dht "github.com/libp2p/go-libp2p-kad-dht" pubsub "github.com/libp2p/go-libp2p-pubsub" "github.com/matrix-org/dendrite/common/keydb" @@ -259,23 +258,9 @@ 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.LibP2P != nil { - fmt.Println("Running in libp2p federation mode") - fmt.Println("Warning: Federation with non-libp2p homeservers will not work in this mode yet!") - tr := &http.Transport{} - tr.RegisterProtocol( - "matrix", - p2phttp.NewTransport(b.LibP2P, p2phttp.ProtocolOption("/matrix")), - ) - 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, - ) - } + 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