mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-26 08:13:09 -06:00
Try to stay connected tto static peer
This commit is contained in:
parent
78075e8a12
commit
cb73e6e550
|
|
@ -59,6 +59,8 @@ type DendriteMonolith struct {
|
||||||
PineconeMulticast *pineconeMulticast.Multicast
|
PineconeMulticast *pineconeMulticast.Multicast
|
||||||
PineconeQUIC *pineconeSessions.QUIC
|
PineconeQUIC *pineconeSessions.QUIC
|
||||||
StorageDirectory string
|
StorageDirectory string
|
||||||
|
staticPeerURI string
|
||||||
|
staticPeerMutex sync.RWMutex
|
||||||
listener net.Listener
|
listener net.Listener
|
||||||
httpServer *http.Server
|
httpServer *http.Server
|
||||||
processContext *process.ProcessContext
|
processContext *process.ProcessContext
|
||||||
|
|
@ -89,6 +91,9 @@ func (m *DendriteMonolith) SetMulticastEnabled(enabled bool) {
|
||||||
func (m *DendriteMonolith) SetStaticPeer(uri string) {
|
func (m *DendriteMonolith) SetStaticPeer(uri string) {
|
||||||
m.DisconnectType(pineconeRouter.PeerTypeRemote)
|
m.DisconnectType(pineconeRouter.PeerTypeRemote)
|
||||||
if uri != "" {
|
if uri != "" {
|
||||||
|
m.staticPeerMutex.Lock()
|
||||||
|
m.staticPeerURI = uri
|
||||||
|
m.staticPeerMutex.Unlock()
|
||||||
go conn.ConnectToPeer(m.PineconeRouter, uri)
|
go conn.ConnectToPeer(m.PineconeRouter, uri)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -96,7 +101,7 @@ func (m *DendriteMonolith) SetStaticPeer(uri string) {
|
||||||
func (m *DendriteMonolith) DisconnectType(peertype int) {
|
func (m *DendriteMonolith) DisconnectType(peertype int) {
|
||||||
for _, p := range m.PineconeRouter.Peers() {
|
for _, p := range m.PineconeRouter.Peers() {
|
||||||
if peertype == p.PeerType {
|
if peertype == p.PeerType {
|
||||||
_ = m.PineconeRouter.Disconnect(types.SwitchPortID(p.Port))
|
_ = m.PineconeRouter.Disconnect(types.SwitchPortID(p.Port), nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -104,13 +109,13 @@ func (m *DendriteMonolith) DisconnectType(peertype int) {
|
||||||
func (m *DendriteMonolith) DisconnectZone(zone string) {
|
func (m *DendriteMonolith) DisconnectZone(zone string) {
|
||||||
for _, p := range m.PineconeRouter.Peers() {
|
for _, p := range m.PineconeRouter.Peers() {
|
||||||
if zone == p.Zone {
|
if zone == p.Zone {
|
||||||
_ = m.PineconeRouter.Disconnect(types.SwitchPortID(p.Port))
|
_ = m.PineconeRouter.Disconnect(types.SwitchPortID(p.Port), nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *DendriteMonolith) DisconnectPort(port int) error {
|
func (m *DendriteMonolith) DisconnectPort(port int) error {
|
||||||
return m.PineconeRouter.Disconnect(types.SwitchPortID(port))
|
return m.PineconeRouter.Disconnect(types.SwitchPortID(port), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *DendriteMonolith) Conduit(zone string, peertype int) (*Conduit, error) {
|
func (m *DendriteMonolith) Conduit(zone string, peertype int) (*Conduit, error) {
|
||||||
|
|
@ -245,6 +250,34 @@ func (m *DendriteMonolith) Start() {
|
||||||
m.PineconeQUIC = pineconeSessions.NewQUIC(logger, m.PineconeRouter)
|
m.PineconeQUIC = pineconeSessions.NewQUIC(logger, m.PineconeRouter)
|
||||||
m.PineconeMulticast = pineconeMulticast.NewMulticast(logger, m.PineconeRouter)
|
m.PineconeMulticast = pineconeMulticast.NewMulticast(logger, m.PineconeRouter)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-m.processContext.Context().Done():
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
if m.PineconeRouter == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
m.staticPeerMutex.RLock()
|
||||||
|
if m.staticPeerURI != "" {
|
||||||
|
found := false
|
||||||
|
for _, p := range m.PineconeRouter.Peers() {
|
||||||
|
if p.PeerType == pineconeRouter.PeerTypeRemote {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
conn.ConnectToPeer(m.PineconeRouter, m.staticPeerURI)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m.staticPeerMutex.RUnlock()
|
||||||
|
time.Sleep(time.Second * 5)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
cfg := &config.Dendrite{}
|
cfg := &config.Dendrite{}
|
||||||
cfg.Defaults()
|
cfg.Defaults()
|
||||||
cfg.Global.ServerName = gomatrixserverlib.ServerName(hex.EncodeToString(pk))
|
cfg.Global.ServerName = gomatrixserverlib.ServerName(hex.EncodeToString(pk))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue