Fix build

This commit is contained in:
Neil Alexander 2020-06-18 09:51:10 +01:00
parent b6762dd19a
commit e5def98e18
3 changed files with 46 additions and 59 deletions

View file

@ -15,8 +15,6 @@
package routing package routing
import ( import (
"encoding/json"
"fmt"
"net/http" "net/http"
"context" "context"
@ -47,7 +45,7 @@ type loginIdentifier struct {
User string `json:"user"` User string `json:"user"`
} }
type loginWithPasswordRequest struct { type passwordRequest struct {
Identifier loginIdentifier `json:"identifier"` Identifier loginIdentifier `json:"identifier"`
User string `json:"user"` // deprecated in favour of identifier User string `json:"user"` // deprecated in favour of identifier
Password string `json:"password"` Password string `json:"password"`
@ -57,11 +55,6 @@ type loginWithPasswordRequest struct {
DeviceID *string `json:"device_id"` DeviceID *string `json:"device_id"`
} }
type loginRequest struct {
Type string `json:"type"`
loginWithPasswordRequest
}
type loginResponse struct { type loginResponse struct {
UserID string `json:"user_id"` UserID string `json:"user_id"`
AccessToken string `json:"access_token"` AccessToken string `json:"access_token"`
@ -94,24 +87,12 @@ func Login(
if resErr != nil { if resErr != nil {
return *resErr return *resErr
} }
switch r.Identifier.Type {
j, _ := json.MarshalIndent(temp, "", " ") case "m.id.user":
fmt.Println(string(j)) if r.Identifier.User == "" {
return util.JSONResponse{
var r loginRequest Code: http.StatusBadRequest,
json.Unmarshal(j, &r) JSON: jsonerror.BadJSON("'user' must be supplied."),
switch r.Type {
case "m.login.password":
j, _ := json.MarshalIndent(r, "", " ")
fmt.Printf("LOGIN REQUEST: %+v\n", string(j))
switch r.Identifier.Type {
case "m.id.user":
if r.Identifier.User == "" {
return util.JSONResponse{
Code: http.StatusBadRequest,
JSON: jsonerror.BadJSON("'user' must be supplied."),
}
} }
} }
acc, errJSON = r.processUsernamePasswordLoginRequest(req, accountDB, cfg, r.Identifier.User) acc, errJSON = r.processUsernamePasswordLoginRequest(req, accountDB, cfg, r.Identifier.User)
@ -139,7 +120,7 @@ func Login(
return jsonerror.InternalServerError() return jsonerror.InternalServerError()
} }
dev, err := getDevice(req.Context(), r.loginWithPasswordRequest, deviceDB, acc, token) dev, err := getDevice(req.Context(), r, deviceDB, acc, token)
if err != nil { if err != nil {
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusInternalServerError, Code: http.StatusInternalServerError,
@ -166,7 +147,7 @@ func Login(
// getDevice returns a new or existing device // getDevice returns a new or existing device
func getDevice( func getDevice(
ctx context.Context, ctx context.Context,
r loginWithPasswordRequest, r passwordRequest,
deviceDB devices.Database, deviceDB devices.Database,
acc *api.Account, acc *api.Account,
token string, token string,

View file

@ -51,18 +51,6 @@ var (
func main() { func main() {
flag.Parse() flag.Parse()
// Build both ends of a HTTP multiplex.
httpServer := &http.Server{
Addr: ":0",
TLSNextProto: map[string]func(*http.Server, *tls.Conn, http.Handler){},
ReadTimeout: 15 * time.Second,
WriteTimeout: 45 * time.Second,
IdleTimeout: 60 * time.Second,
BaseContext: func(_ net.Listener) context.Context {
return context.Background()
},
}
ygg, err := yggconn.Setup(*instanceName, *instancePeer, ".") ygg, err := yggconn.Setup(*instanceName, *instancePeer, ".")
if err != nil { if err != nil {
panic(err) panic(err)
@ -131,7 +119,7 @@ func main() {
Config: base.Cfg, Config: base.Cfg,
AccountDB: accountDB, AccountDB: accountDB,
DeviceDB: deviceDB, DeviceDB: deviceDB,
Client: createClient(ygg), Client: ygg.CreateClient(base),
FedClient: federation, FedClient: federation,
KeyRing: keyRing, KeyRing: keyRing,
KafkaConsumer: base.KafkaConsumer, KafkaConsumer: base.KafkaConsumer,

View file

@ -11,10 +11,25 @@ import (
"time" "time"
"github.com/matrix-org/dendrite/cmd/dendrite-demo-yggdrasil/convert" "github.com/matrix-org/dendrite/cmd/dendrite-demo-yggdrasil/convert"
"github.com/matrix-org/dendrite/internal/basecomponent" "github.com/matrix-org/dendrite/internal/setup"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
) )
func (n *Node) yggdialer(_, address string) (net.Conn, error) {
tokens := strings.Split(address, ":")
raw, err := hex.DecodeString(tokens[0])
if err != nil {
return nil, fmt.Errorf("hex.DecodeString: %w", err)
}
converted := convert.Ed25519PublicKeyToCurve25519(ed25519.PublicKey(raw))
convhex := hex.EncodeToString(converted)
return n.Dial("curve25519", convhex)
}
func (n *Node) yggdialerctx(ctx context.Context, network, address string) (net.Conn, error) {
return n.yggdialer(network, address)
}
type yggroundtripper struct { type yggroundtripper struct {
inner *http.Transport inner *http.Transport
} }
@ -24,29 +39,32 @@ func (y *yggroundtripper) RoundTrip(req *http.Request) (*http.Response, error) {
return y.inner.RoundTrip(req) return y.inner.RoundTrip(req)
} }
func (n *Node) CreateFederationClient( func (n *Node) CreateClient(
base *basecomponent.BaseDendrite, base *setup.BaseDendrite,
) *gomatrixserverlib.FederationClient { ) *gomatrixserverlib.Client {
yggdialer := func(_, address string) (net.Conn, error) {
tokens := strings.Split(address, ":")
raw, err := hex.DecodeString(tokens[0])
if err != nil {
return nil, fmt.Errorf("hex.DecodeString: %w", err)
}
converted := convert.Ed25519PublicKeyToCurve25519(ed25519.PublicKey(raw))
convhex := hex.EncodeToString(converted)
return n.Dial("curve25519", convhex)
}
yggdialerctx := func(ctx context.Context, network, address string) (net.Conn, error) {
return yggdialer(network, address)
}
tr := &http.Transport{} tr := &http.Transport{}
tr.RegisterProtocol( tr.RegisterProtocol(
"matrix", &yggroundtripper{ "matrix", &yggroundtripper{
inner: &http.Transport{ inner: &http.Transport{
ResponseHeaderTimeout: 15 * time.Second, ResponseHeaderTimeout: 15 * time.Second,
IdleConnTimeout: 60 * time.Second, IdleConnTimeout: 60 * time.Second,
DialContext: yggdialerctx, DialContext: n.yggdialerctx,
},
},
)
return gomatrixserverlib.NewClientWithTransport(tr)
}
func (n *Node) CreateFederationClient(
base *setup.BaseDendrite,
) *gomatrixserverlib.FederationClient {
tr := &http.Transport{}
tr.RegisterProtocol(
"matrix", &yggroundtripper{
inner: &http.Transport{
ResponseHeaderTimeout: 15 * time.Second,
IdleConnTimeout: 60 * time.Second,
DialContext: n.yggdialerctx,
}, },
}, },
) )