mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-03 06:32:47 +00:00
Bare QUIC demo working
This commit is contained in:
parent
d3939b3d65
commit
8a5c2020b3
5 changed files with 25 additions and 62 deletions
|
@ -1,35 +1,13 @@
|
|||
package yggconn
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/ed25519"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/matrix-org/dendrite/cmd/dendrite-demo-yggdrasil/convert"
|
||||
"github.com/matrix-org/dendrite/internal/setup"
|
||||
"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 {
|
||||
inner *http.Transport
|
||||
}
|
||||
|
@ -48,7 +26,7 @@ func (n *Node) CreateClient(
|
|||
inner: &http.Transport{
|
||||
ResponseHeaderTimeout: 15 * time.Second,
|
||||
IdleConnTimeout: 60 * time.Second,
|
||||
DialContext: n.yggdialerctx,
|
||||
DialContext: n.DialerContext,
|
||||
},
|
||||
},
|
||||
)
|
||||
|
@ -64,7 +42,7 @@ func (n *Node) CreateFederationClient(
|
|||
inner: &http.Transport{
|
||||
ResponseHeaderTimeout: 15 * time.Second,
|
||||
IdleConnTimeout: 60 * time.Second,
|
||||
DialContext: n.yggdialerctx,
|
||||
DialContext: n.DialerContext,
|
||||
TLSClientConfig: n.tlsConfig,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"crypto/tls"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
@ -53,15 +54,10 @@ type Node struct {
|
|||
incoming chan QUICStream
|
||||
}
|
||||
|
||||
func (n *Node) BuildName() string {
|
||||
return "dendrite"
|
||||
}
|
||||
|
||||
func (n *Node) BuildVersion() string {
|
||||
return "dev"
|
||||
}
|
||||
|
||||
func (n *Node) Dialer(_, address string) (net.Conn, error) {
|
||||
if len(n.core.GetSwitchPeers()) == 0 {
|
||||
return nil, errors.New("no peer connections available")
|
||||
}
|
||||
tokens := strings.Split(address, ":")
|
||||
raw, err := hex.DecodeString(tokens[0])
|
||||
if err != nil {
|
||||
|
@ -85,7 +81,6 @@ func Setup(instanceName, storageDirectory string) (*Node, error) {
|
|||
log: gologme.New(os.Stdout, "YGG ", log.Flags()),
|
||||
incoming: make(chan QUICStream),
|
||||
}
|
||||
//n.core.SetBuildInfo(n)
|
||||
|
||||
yggfile := fmt.Sprintf("%s/%s-yggdrasil.conf", storageDirectory, instanceName)
|
||||
if _, err := os.Stat(yggfile); !os.IsNotExist(err) {
|
||||
|
|
|
@ -52,8 +52,8 @@ func (n *Node) listenFromYgg() {
|
|||
return
|
||||
}
|
||||
if len(session.ConnectionState().PeerCertificates) != 1 {
|
||||
session.CloseWithError(0, "expected a peer certificate")
|
||||
return
|
||||
_ = session.CloseWithError(0, "expected a peer certificate")
|
||||
continue
|
||||
}
|
||||
address := session.ConnectionState().PeerCertificates[0].Subject.CommonName
|
||||
n.log.Infoln("Accepted connection from", address)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue