Fix media API for demos and possibly Synapse (#1134)

* Fix media API for demos and possibly Synapse

* User API

* goimports
This commit is contained in:
Neil Alexander 2020-06-16 14:29:11 +01:00 committed by GitHub
parent 9c77022513
commit fc0e74ae0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 71 additions and 25 deletions

View file

@ -15,13 +15,16 @@
package yggconn
import (
"context"
"crypto/ed25519"
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net"
"os"
"strings"
"sync"
"github.com/matrix-org/dendrite/cmd/dendrite-demo-yggdrasil/convert"
@ -48,6 +51,21 @@ type Node struct {
incoming chan *yamux.Stream
}
func (n *Node) Dialer(_, 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) DialerContext(ctx context.Context, network, address string) (net.Conn, error) {
return n.Dialer(network, address)
}
// nolint:gocyclo
func Setup(instanceName, instancePeer string) (*Node, error) {
n := &Node{