mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-26 08:13:09 -06:00
Tweaks
This commit is contained in:
parent
9af0913b3c
commit
9c4aa2d253
|
|
@ -3,6 +3,7 @@ package gobind
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/ed25519"
|
"crypto/ed25519"
|
||||||
|
"crypto/rand"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
@ -17,6 +18,7 @@ import (
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/hjson/hjson-go"
|
"github.com/hjson/hjson-go"
|
||||||
"github.com/matrix-org/dendrite/appservice"
|
"github.com/matrix-org/dendrite/appservice"
|
||||||
|
"github.com/matrix-org/dendrite/clientapi/userutil"
|
||||||
"github.com/matrix-org/dendrite/cmd/dendrite-demo-pinecone/conn"
|
"github.com/matrix-org/dendrite/cmd/dendrite-demo-pinecone/conn"
|
||||||
"github.com/matrix-org/dendrite/cmd/dendrite-demo-pinecone/rooms"
|
"github.com/matrix-org/dendrite/cmd/dendrite-demo-pinecone/rooms"
|
||||||
"github.com/matrix-org/dendrite/cmd/dendrite-demo-yggdrasil/signing"
|
"github.com/matrix-org/dendrite/cmd/dendrite-demo-yggdrasil/signing"
|
||||||
|
|
@ -95,8 +97,30 @@ func (m *DendriteMonolith) DisconnectMulticastPeers() {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *DendriteMonolith) Conduit(zone string) (*Conduit, error) {
|
||||||
|
l, r := net.Pipe()
|
||||||
|
go func() {
|
||||||
|
for i := 1; i <= 10; i++ {
|
||||||
|
logrus.Errorf("Attempting authenticated connect (attempt %d)", i)
|
||||||
|
p, err := m.PineconeRouter.AuthenticatedConnect(l, zone)
|
||||||
|
if err == nil {
|
||||||
|
logrus.Errorf("Authenticated connect succeeded, connected to port %d (attempt %d)", p, i)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
logrus.WithError(err).Errorf("Authenticated connect failed (attempt %d)", i)
|
||||||
|
}
|
||||||
|
_ = l.Close()
|
||||||
|
_ = r.Close()
|
||||||
|
}()
|
||||||
|
return &Conduit{conn: r}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (m *DendriteMonolith) RegisterUser(localpart, password string) (string, error) {
|
func (m *DendriteMonolith) RegisterUser(localpart, password string) (string, error) {
|
||||||
deviceID := "P2P"
|
pubkey := m.PineconeRouter.PublicKey()
|
||||||
|
userID := userutil.MakeUserID(
|
||||||
|
localpart,
|
||||||
|
gomatrixserverlib.ServerName(hex.EncodeToString(pubkey[:])),
|
||||||
|
)
|
||||||
userReq := &userapiAPI.PerformAccountCreationRequest{
|
userReq := &userapiAPI.PerformAccountCreationRequest{
|
||||||
AccountType: userapiAPI.AccountTypeUser,
|
AccountType: userapiAPI.AccountTypeUser,
|
||||||
Localpart: localpart,
|
Localpart: localpart,
|
||||||
|
|
@ -104,14 +128,21 @@ func (m *DendriteMonolith) RegisterUser(localpart, password string) (string, err
|
||||||
}
|
}
|
||||||
userRes := &userapiAPI.PerformAccountCreationResponse{}
|
userRes := &userapiAPI.PerformAccountCreationResponse{}
|
||||||
if err := m.userAPI.PerformAccountCreation(context.Background(), userReq, userRes); err != nil {
|
if err := m.userAPI.PerformAccountCreation(context.Background(), userReq, userRes); err != nil {
|
||||||
return "", fmt.Errorf("userAPI.PerformAccountCreation: %w", err)
|
return userID, fmt.Errorf("userAPI.PerformAccountCreation: %w", err)
|
||||||
}
|
}
|
||||||
if !userRes.AccountCreated {
|
return userID, nil
|
||||||
return "", fmt.Errorf("account was not created")
|
}
|
||||||
|
|
||||||
|
func (m *DendriteMonolith) RegisterDevice(localpart, deviceID string) (string, error) {
|
||||||
|
accessTokenBytes := make([]byte, 16)
|
||||||
|
n, err := rand.Read(accessTokenBytes)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("rand.Read: %w", err)
|
||||||
}
|
}
|
||||||
loginReq := &userapiAPI.PerformDeviceCreationRequest{
|
loginReq := &userapiAPI.PerformDeviceCreationRequest{
|
||||||
Localpart: localpart,
|
Localpart: localpart,
|
||||||
DeviceID: &deviceID,
|
DeviceID: &deviceID,
|
||||||
|
AccessToken: hex.EncodeToString(accessTokenBytes[:n]),
|
||||||
}
|
}
|
||||||
loginRes := &userapiAPI.PerformDeviceCreationResponse{}
|
loginRes := &userapiAPI.PerformDeviceCreationResponse{}
|
||||||
if err := m.userAPI.PerformDeviceCreation(context.Background(), loginReq, loginRes); err != nil {
|
if err := m.userAPI.PerformDeviceCreation(context.Background(), loginReq, loginRes); err != nil {
|
||||||
|
|
@ -182,7 +213,7 @@ func (m *DendriteMonolith) Start() {
|
||||||
logger := log.New(os.Stdout, "PINECONE: ", 0)
|
logger := log.New(os.Stdout, "PINECONE: ", 0)
|
||||||
m.PineconeRouter = pineconeRouter.NewRouter(logger, "dendrite", sk, pk, nil)
|
m.PineconeRouter = pineconeRouter.NewRouter(logger, "dendrite", sk, pk, nil)
|
||||||
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)
|
||||||
|
|
||||||
cfg := &config.Dendrite{}
|
cfg := &config.Dendrite{}
|
||||||
cfg.Defaults()
|
cfg.Defaults()
|
||||||
|
|
@ -314,3 +345,19 @@ func (m *DendriteMonolith) Suspend() {
|
||||||
m.logger.Warn("Error stopping HTTP server:", err)
|
m.logger.Warn("Error stopping HTTP server:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Conduit struct {
|
||||||
|
conn net.Conn
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Conduit) Read(b []byte) (int, error) {
|
||||||
|
return c.conn.Read(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Conduit) Write(b []byte) (int, error) {
|
||||||
|
return c.conn.Write(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Conduit) Close() error {
|
||||||
|
return c.conn.Close()
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue