diff options
author | Till <2353100+S7evinK@users.noreply.github.com> | 2024-08-03 20:26:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-03 20:26:28 +0200 |
commit | 4d116ff0dbb3972228f798851fdf63d01cd3a3e9 (patch) | |
tree | c1a70524c1448e7411dca197958f2fb02158bdf1 /cmd | |
parent | c876790f0819026c061c1b6cc4d27fdfd3df2a4f (diff) |
Bump yggdrasil (#3407)
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/dendrite-demo-yggdrasil/main.go | 6 | ||||
-rw-r--r-- | cmd/dendrite-demo-yggdrasil/yggconn/node.go | 31 | ||||
-rw-r--r-- | cmd/dendrite-demo-yggdrasil/yggconn/session.go | 56 |
3 files changed, 16 insertions, 77 deletions
diff --git a/cmd/dendrite-demo-yggdrasil/main.go b/cmd/dendrite-demo-yggdrasil/main.go index 1e518634..b02f131a 100644 --- a/cmd/dendrite-demo-yggdrasil/main.go +++ b/cmd/dendrite-demo-yggdrasil/main.go @@ -59,7 +59,7 @@ var ( instanceName = flag.String("name", "dendrite-p2p-ygg", "the name of this P2P demo instance") instancePort = flag.Int("port", 8008, "the port that the client API will listen on") instancePeer = flag.String("peer", "", "the static Yggdrasil peers to connect to, comma separated-list") - instanceListen = flag.String("listen", "tcp://:0", "the port Yggdrasil peers can connect to") + instanceListen = flag.String("listen", "tls://:0", "the port Yggdrasil peers can connect to") instanceDir = flag.String("dir", ".", "the directory to store the databases in (if --config not specified)") ) @@ -134,6 +134,7 @@ func main() { cfg.RoomServer.Database.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-roomserver.db", filepath.Join(*instanceDir, *instanceName))) cfg.KeyServer.Database.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-keyserver.db", filepath.Join(*instanceDir, *instanceName))) cfg.FederationAPI.Database.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-federationapi.db", filepath.Join(*instanceDir, *instanceName))) + cfg.RelayAPI.Database.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-relayapi.db", filepath.Join(*instanceDir, *instanceName))) cfg.MSCs.MSCs = []string{"msc2836"} cfg.MSCs.Database.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-mscs.db", filepath.Join(*instanceDir, *instanceName))) cfg.ClientAPI.RegistrationDisabled = false @@ -216,14 +217,13 @@ func main() { fsAPI := federationapi.NewInternalAPI( processCtx, cfg, cm, &natsInstance, federation, rsAPI, caches, keyRing, true, ) + rsAPI.SetFederationAPI(fsAPI, keyRing) userAPI := userapi.NewInternalAPI(processCtx, cfg, cm, &natsInstance, rsAPI, federation, caching.EnableMetrics, fsAPI.IsBlacklistedOrBackingOff) asAPI := appservice.NewInternalAPI(processCtx, cfg, &natsInstance, userAPI, rsAPI) rsAPI.SetAppserviceAPI(asAPI) - rsAPI.SetFederationAPI(fsAPI, keyRing) - monolith := setup.Monolith{ Config: cfg, Client: ygg.CreateClient(), diff --git a/cmd/dendrite-demo-yggdrasil/yggconn/node.go b/cmd/dendrite-demo-yggdrasil/yggconn/node.go index 26c30e48..3c230f62 100644 --- a/cmd/dendrite-demo-yggdrasil/yggconn/node.go +++ b/cmd/dendrite-demo-yggdrasil/yggconn/node.go @@ -18,16 +18,15 @@ import ( "context" "crypto/ed25519" "encoding/hex" - "fmt" "net" "regexp" "strings" "github.com/matrix-org/gomatrixserverlib/spec" - "github.com/neilalexander/utp" "github.com/sirupsen/logrus" + "github.com/yggdrasil-network/yggquic" - ironwoodtypes "github.com/Arceliar/ironwood/types" + "github.com/yggdrasil-network/yggdrasil-go/src/config" "github.com/yggdrasil-network/yggdrasil-go/src/core" yggdrasilcore "github.com/yggdrasil-network/yggdrasil-go/src/core" "github.com/yggdrasil-network/yggdrasil-go/src/multicast" @@ -40,25 +39,23 @@ type Node struct { core *yggdrasilcore.Core multicast *yggdrasilmulticast.Multicast log *gologme.Logger - utpSocket *utp.Socket - incoming chan net.Conn + *yggquic.YggdrasilTransport } func (n *Node) DialerContext(ctx context.Context, _, 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) - } - pk := make(ironwoodtypes.Addr, ed25519.PublicKeySize) - copy(pk, raw[:]) - return n.utpSocket.DialAddrContext(ctx, pk) + return n.DialContext(ctx, "yggdrasil", tokens[0]) } func Setup(sk ed25519.PrivateKey, instanceName, storageDirectory, peerURI, listenURI string) (*Node, error) { n := &Node{ - log: gologme.New(logrus.StandardLogger().Writer(), "", 0), - incoming: make(chan net.Conn), + log: gologme.New(logrus.StandardLogger().Writer(), "", 0), + } + + cfg := config.GenerateConfig() + cfg.PrivateKey = config.KeyBytes(sk) + if err := cfg.GenerateSelfSignedCertificate(); err != nil { + panic(err) } n.log.EnableLevel("error") @@ -78,12 +75,12 @@ func Setup(sk ed25519.PrivateKey, instanceName, storageDirectory, peerURI, liste }) } } - if n.core, err = core.New(sk[:], n.log, options...); err != nil { + if n.core, err = core.New(cfg.Certificate, n.log, options...); err != nil { panic(err) } n.core.SetLogger(n.log) - if n.utpSocket, err = utp.NewSocketFromPacketConnNoClose(n.core); err != nil { + if n.YggdrasilTransport, err = yggquic.New(n.core, *cfg.Certificate, nil); err != nil { panic(err) } } @@ -106,8 +103,6 @@ func Setup(sk ed25519.PrivateKey, instanceName, storageDirectory, peerURI, liste } n.log.Printf("Public key: %x", n.core.PublicKey()) - go n.listenFromYgg() - return n, nil } diff --git a/cmd/dendrite-demo-yggdrasil/yggconn/session.go b/cmd/dendrite-demo-yggdrasil/yggconn/session.go deleted file mode 100644 index b35b4043..00000000 --- a/cmd/dendrite-demo-yggdrasil/yggconn/session.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2020 The Matrix.org Foundation C.I.C. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package yggconn - -import ( - "context" - "net" -) - -func (n *Node) listenFromYgg() { - for { - conn, err := n.utpSocket.Accept() - if err != nil { - n.log.Println("n.utpSocket.Accept:", err) - return - } - n.incoming <- conn - } -} - -// Implements net.Listener -func (n *Node) Accept() (net.Conn, error) { - return <-n.incoming, nil -} - -// Implements net.Listener -func (n *Node) Close() error { - return n.utpSocket.Close() -} - -// Implements net.Listener -func (n *Node) Addr() net.Addr { - return n.utpSocket.Addr() -} - -// Implements http.Transport.Dial -func (n *Node) Dial(network, address string) (net.Conn, error) { - return n.DialContext(context.TODO(), network, address) -} - -// Implements http.Transport.DialContext -func (n *Node) DialContext(ctx context.Context, network, address string) (net.Conn, error) { - return n.utpSocket.DialContext(ctx, network, address) -} |