mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-30 04:52:46 +00:00
Yggdrasil demo updates ("Bare QUIC")
Squashed commit of the following: commit 86c2388e13ffdbabdd50cea205652dccc40e1860 Merge:b0a3ee6c
f5e7e751
Author: Neil Alexander <neilalexander@users.noreply.github.com> Date: Thu Jul 16 13:47:10 2020 +0100 Merge branch 'master' into neilalexander/yggbarequic commitb0a3ee6c5c
Author: Neil Alexander <neilalexander@users.noreply.github.com> Date: Thu Jul 16 13:42:22 2020 +0100 Add support for broadcasting wake-up EDUs to known hosts commit8a5c2020b3
Author: Neil Alexander <neilalexander@users.noreply.github.com> Date: Thu Jul 16 13:42:10 2020 +0100 Bare QUIC demo working commitd3939b3d65
Author: Neil Alexander <neilalexander@users.noreply.github.com> Date: Wed Jul 15 11:42:43 2020 +0100 Support bare Yggdrasil sessions with encrypted QUIC
This commit is contained in:
parent
f5e7e7513c
commit
e5208c2ec9
16 changed files with 217 additions and 155 deletions
|
@ -3,7 +3,6 @@ package gobind
|
|||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
|
@ -25,7 +24,6 @@ import (
|
|||
"github.com/matrix-org/dendrite/userapi"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/crypto"
|
||||
"go.uber.org/atomic"
|
||||
)
|
||||
|
||||
|
@ -169,33 +167,6 @@ func (m *DendriteMonolith) Start() {
|
|||
base.UseHTTPAPIs,
|
||||
)
|
||||
|
||||
ygg.NewSession = func(serverName gomatrixserverlib.ServerName) {
|
||||
logrus.Infof("Found new session %q", serverName)
|
||||
time.Sleep(time.Second * 3)
|
||||
req := &api.PerformServersAliveRequest{
|
||||
Servers: []gomatrixserverlib.ServerName{serverName},
|
||||
}
|
||||
res := &api.PerformServersAliveResponse{}
|
||||
if err := fsAPI.PerformServersAlive(context.TODO(), req, res); err != nil {
|
||||
logrus.WithError(err).Warn("Failed to notify server alive due to new session")
|
||||
}
|
||||
}
|
||||
|
||||
ygg.NotifyLinkNew(func(_ crypto.BoxPubKey, sigPubKey crypto.SigPubKey, linkType, remote string) {
|
||||
serverName := hex.EncodeToString(sigPubKey[:])
|
||||
logrus.Infof("Found new peer %q", serverName)
|
||||
time.Sleep(time.Second * 3)
|
||||
req := &api.PerformServersAliveRequest{
|
||||
Servers: []gomatrixserverlib.ServerName{
|
||||
gomatrixserverlib.ServerName(serverName),
|
||||
},
|
||||
}
|
||||
res := &api.PerformServersAliveResponse{}
|
||||
if err := fsAPI.PerformServersAlive(context.TODO(), req, res); err != nil {
|
||||
logrus.WithError(err).Warn("Failed to notify server alive due to new session")
|
||||
}
|
||||
})
|
||||
|
||||
// Build both ends of a HTTP multiplex.
|
||||
m.httpServer = &http.Server{
|
||||
Addr: ":0",
|
||||
|
@ -209,28 +180,22 @@ func (m *DendriteMonolith) Start() {
|
|||
Handler: base.BaseMux,
|
||||
}
|
||||
|
||||
m.Resume()
|
||||
}
|
||||
|
||||
func (m *DendriteMonolith) Resume() {
|
||||
logrus.Info("Resuming monolith")
|
||||
if listener, err := net.Listen("tcp", "localhost:65432"); err == nil {
|
||||
m.listener = listener
|
||||
}
|
||||
if m.yggListening.CAS(false, true) {
|
||||
go func() {
|
||||
m.logger.Info("Listening on ", m.YggdrasilNode.DerivedServerName())
|
||||
m.logger.Fatal(m.httpServer.Serve(m.YggdrasilNode))
|
||||
m.yggListening.Store(false)
|
||||
}()
|
||||
}
|
||||
if m.httpListening.CAS(false, true) {
|
||||
go func() {
|
||||
m.logger.Info("Listening on ", m.BaseURL())
|
||||
m.logger.Fatal(m.httpServer.Serve(m.listener))
|
||||
m.httpListening.Store(false)
|
||||
}()
|
||||
}
|
||||
go func() {
|
||||
logger.Info("Listening on ", ygg.DerivedServerName())
|
||||
logger.Fatal(httpServer.Serve(ygg))
|
||||
}()
|
||||
go func() {
|
||||
logger.Info("Listening on ", m.BaseURL())
|
||||
logger.Fatal(httpServer.Serve(m.listener))
|
||||
}()
|
||||
go func() {
|
||||
logrus.Info("Sending wake-up message to known nodes")
|
||||
req := &api.PerformBroadcastEDURequest{}
|
||||
res := &api.PerformBroadcastEDUResponse{}
|
||||
if err := fsAPI.PerformBroadcastEDU(context.TODO(), req, res); err != nil {
|
||||
logrus.WithError(err).Error("Failed to send wake-up message to known nodes")
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (m *DendriteMonolith) Suspend() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue