aboutsummaryrefslogtreecommitdiff
path: root/cmd/dendrite-demo-yggdrasil/yggconn/node.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/dendrite-demo-yggdrasil/yggconn/node.go')
-rw-r--r--cmd/dendrite-demo-yggdrasil/yggconn/node.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/cmd/dendrite-demo-yggdrasil/yggconn/node.go b/cmd/dendrite-demo-yggdrasil/yggconn/node.go
index a625f8d8..b225e1cf 100644
--- a/cmd/dendrite-demo-yggdrasil/yggconn/node.go
+++ b/cmd/dendrite-demo-yggdrasil/yggconn/node.go
@@ -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{