mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-17 03:43:11 -06:00
Extract CreateFederationClient into demo
This commit is contained in:
parent
1de97144bf
commit
0aec6318c4
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
gostream "github.com/libp2p/go-libp2p-gostream"
|
gostream "github.com/libp2p/go-libp2p-gostream"
|
||||||
|
p2phttp "github.com/libp2p/go-libp2p-http"
|
||||||
p2pdisc "github.com/libp2p/go-libp2p/p2p/discovery"
|
p2pdisc "github.com/libp2p/go-libp2p/p2p/discovery"
|
||||||
"github.com/matrix-org/dendrite/appservice"
|
"github.com/matrix-org/dendrite/appservice"
|
||||||
"github.com/matrix-org/dendrite/clientapi"
|
"github.com/matrix-org/dendrite/clientapi"
|
||||||
|
|
@ -78,6 +79,21 @@ func createKeyDB(
|
||||||
return db
|
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() {
|
func main() {
|
||||||
instanceName := flag.String("name", "dendrite-p2p", "the name of this P2P demo instance")
|
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")
|
instancePort := flag.Int("port", 8080, "the port that the client API will listen on")
|
||||||
|
|
@ -128,7 +144,7 @@ func main() {
|
||||||
accountDB := base.CreateAccountsDB()
|
accountDB := base.CreateAccountsDB()
|
||||||
deviceDB := base.CreateDeviceDB()
|
deviceDB := base.CreateDeviceDB()
|
||||||
keyDB := createKeyDB(base)
|
keyDB := createKeyDB(base)
|
||||||
federation := base.CreateFederationClient()
|
federation := createFederationClient(base)
|
||||||
keyRing := keydb.CreateKeyRing(federation.Client, keyDB)
|
keyRing := keydb.CreateKeyRing(federation.Client, keyDB)
|
||||||
|
|
||||||
alias, input, query := roomserver.SetupRoomServerComponent(base)
|
alias, input, query := roomserver.SetupRoomServerComponent(base)
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ import (
|
||||||
routing "github.com/libp2p/go-libp2p-core/routing"
|
routing "github.com/libp2p/go-libp2p-core/routing"
|
||||||
|
|
||||||
host "github.com/libp2p/go-libp2p-core/host"
|
host "github.com/libp2p/go-libp2p-core/host"
|
||||||
p2phttp "github.com/libp2p/go-libp2p-http"
|
|
||||||
dht "github.com/libp2p/go-libp2p-kad-dht"
|
dht "github.com/libp2p/go-libp2p-kad-dht"
|
||||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||||
"github.com/matrix-org/dendrite/common/keydb"
|
"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
|
// 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.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(
|
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