aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2022-04-08 13:55:46 +0100
committerNeil Alexander <neilalexander@users.noreply.github.com>2022-04-08 13:55:46 +0100
commit6907e421674e9c06f43da96c0819ff778ffcae60 (patch)
tree12aea59e2965c9271a4682135e5ac890c94a3761 /cmd
parent4312b87ab014699f1d1cb3ae61b1af36f6b82657 (diff)
Use connection manager in Pinecone demos
Diffstat (limited to 'cmd')
-rw-r--r--cmd/dendrite-demo-pinecone/main.go40
-rw-r--r--cmd/dendritejs-pinecone/main.go20
2 files changed, 11 insertions, 49 deletions
diff --git a/cmd/dendrite-demo-pinecone/main.go b/cmd/dendrite-demo-pinecone/main.go
index a3d3ed17..dd1ab369 100644
--- a/cmd/dendrite-demo-pinecone/main.go
+++ b/cmd/dendrite-demo-pinecone/main.go
@@ -25,7 +25,6 @@ import (
"net"
"net/http"
"os"
- "strings"
"time"
"github.com/gorilla/mux"
@@ -47,6 +46,7 @@ import (
"github.com/matrix-org/dendrite/userapi"
"github.com/matrix-org/gomatrixserverlib"
+ pineconeConnections "github.com/matrix-org/pinecone/connections"
pineconeMulticast "github.com/matrix-org/pinecone/multicast"
pineconeRouter "github.com/matrix-org/pinecone/router"
pineconeSessions "github.com/matrix-org/pinecone/sessions"
@@ -90,6 +90,13 @@ func main() {
}
pRouter := pineconeRouter.NewRouter(logrus.WithField("pinecone", "router"), sk, false)
+ pQUIC := pineconeSessions.NewSessions(logrus.WithField("pinecone", "sessions"), pRouter, []string{"matrix"})
+ pMulticast := pineconeMulticast.NewMulticast(logrus.WithField("pinecone", "multicast"), pRouter)
+ pManager := pineconeConnections.NewConnectionManager(pRouter)
+ pMulticast.Start()
+ if instancePeer != nil && *instancePeer != "" {
+ pManager.AddPeer(*instancePeer)
+ }
go func() {
listener, err := net.Listen("tcp", *instanceListen)
@@ -119,36 +126,6 @@ func main() {
}
}()
- pQUIC := pineconeSessions.NewSessions(logrus.WithField("pinecone", "sessions"), pRouter, []string{"matrix"})
- pMulticast := pineconeMulticast.NewMulticast(logrus.WithField("pinecone", "multicast"), pRouter)
- pMulticast.Start()
-
- connectToStaticPeer := func() {
- connected := map[string]bool{} // URI -> connected?
- for _, uri := range strings.Split(*instancePeer, ",") {
- connected[strings.TrimSpace(uri)] = false
- }
- attempt := func() {
- for k := range connected {
- connected[k] = false
- }
- for _, info := range pRouter.Peers() {
- connected[info.URI] = true
- }
- for k, online := range connected {
- if !online {
- if err := conn.ConnectToPeer(pRouter, k); err != nil {
- logrus.WithError(err).Error("Failed to connect to static peer")
- }
- }
- }
- }
- for {
- attempt()
- time.Sleep(time.Second * 5)
- }
- }
-
cfg := &config.Dendrite{}
cfg.Defaults(true)
cfg.Global.ServerName = gomatrixserverlib.ServerName(hex.EncodeToString(pk))
@@ -268,7 +245,6 @@ func main() {
Handler: pMux,
}
- go connectToStaticPeer()
go func() {
pubkey := pRouter.PublicKey()
logrus.Info("Listening on ", hex.EncodeToString(pubkey[:]))
diff --git a/cmd/dendritejs-pinecone/main.go b/cmd/dendritejs-pinecone/main.go
index ba9edf23..211b3e13 100644
--- a/cmd/dendritejs-pinecone/main.go
+++ b/cmd/dendritejs-pinecone/main.go
@@ -22,7 +22,6 @@ import (
"encoding/hex"
"fmt"
"syscall/js"
- "time"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/appservice"
@@ -44,6 +43,7 @@ import (
_ "github.com/matrix-org/go-sqlite3-js"
+ pineconeConnections "github.com/matrix-org/pinecone/connections"
pineconeRouter "github.com/matrix-org/pinecone/router"
pineconeSessions "github.com/matrix-org/pinecone/sessions"
)
@@ -154,6 +154,8 @@ func startup() {
pRouter := pineconeRouter.NewRouter(logrus.WithField("pinecone", "router"), sk, false)
pSessions := pineconeSessions.NewSessions(logrus.WithField("pinecone", "sessions"), pRouter, []string{"matrix"})
+ pManager := pineconeConnections.NewConnectionManager(pRouter)
+ pManager.AddPeer("wss://pinecone.matrix.org/public")
cfg := &config.Dendrite{}
cfg.Defaults(true)
@@ -237,20 +239,4 @@ func startup() {
}
s.ListenAndServe("fetch")
}()
-
- // Connect to the static peer
- go func() {
- for {
- if pRouter.PeerCount(pineconeRouter.PeerTypeRemote) == 0 {
- if err := conn.ConnectToPeer(pRouter, publicPeer); err != nil {
- logrus.WithError(err).Error("Failed to connect to static peer")
- }
- }
- select {
- case <-base.ProcessContext.Context().Done():
- return
- case <-time.After(time.Second * 5):
- }
- }
- }()
}