mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-29 12:42:46 +00:00
Pinecone demo updates
This commit is contained in:
parent
2c9a390fa6
commit
bd9dec8e06
4 changed files with 60 additions and 58 deletions
|
@ -23,7 +23,6 @@ import (
|
|||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -48,12 +47,11 @@ import (
|
|||
"github.com/matrix-org/dendrite/setup/config"
|
||||
"github.com/matrix-org/dendrite/userapi"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"go.uber.org/atomic"
|
||||
|
||||
pineconeMulticast "github.com/matrix-org/pinecone/multicast"
|
||||
"github.com/matrix-org/pinecone/router"
|
||||
pineconeRouter "github.com/matrix-org/pinecone/router"
|
||||
pineconeSessions "github.com/matrix-org/pinecone/sessions"
|
||||
pineconeTypes "github.com/matrix-org/pinecone/types"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
@ -123,27 +121,23 @@ func main() {
|
|||
pMulticast := pineconeMulticast.NewMulticast(logger, pRouter)
|
||||
pMulticast.Start()
|
||||
|
||||
var staticPeerAttempts atomic.Uint32
|
||||
var connectToStaticPeer func()
|
||||
connectToStaticPeer = func() {
|
||||
uri := *instancePeer
|
||||
if uri == "" {
|
||||
return
|
||||
connectToStaticPeer := func() {
|
||||
attempt := func() {
|
||||
if pRouter.PeerCount(router.PeerTypeRemote) == 0 {
|
||||
uri := *instancePeer
|
||||
if uri == "" {
|
||||
return
|
||||
}
|
||||
if err := conn.ConnectToPeer(pRouter, uri); err != nil {
|
||||
logrus.WithError(err).Error("Failed to connect to static peer")
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := conn.ConnectToPeer(pRouter, uri); err != nil {
|
||||
exp := time.Second * time.Duration(math.Exp2(float64(staticPeerAttempts.Inc())))
|
||||
time.AfterFunc(exp, connectToStaticPeer)
|
||||
} else {
|
||||
staticPeerAttempts.Store(0)
|
||||
for {
|
||||
attempt()
|
||||
time.Sleep(time.Second * 5)
|
||||
}
|
||||
}
|
||||
pRouter.SetDisconnectedCallback(func(port pineconeTypes.SwitchPortID, public pineconeTypes.PublicKey, peertype int, err error) {
|
||||
if peertype == pineconeRouter.PeerTypeRemote && err != nil {
|
||||
staticPeerAttempts.Store(0)
|
||||
time.AfterFunc(time.Second, connectToStaticPeer)
|
||||
}
|
||||
})
|
||||
go connectToStaticPeer()
|
||||
|
||||
cfg := &config.Dendrite{}
|
||||
cfg.Defaults()
|
||||
|
@ -257,6 +251,7 @@ func main() {
|
|||
Handler: pMux,
|
||||
}
|
||||
|
||||
go connectToStaticPeer()
|
||||
go func() {
|
||||
pubkey := pRouter.PublicKey()
|
||||
logrus.Info("Listening on ", hex.EncodeToString(pubkey[:]))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue