From b21fad92e57451e7a7186630c02214f23c1b9d03 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Tue, 7 Jul 2020 14:18:58 +0100 Subject: [PATCH] Tweaks to Dendrite Yggdrasil demo setup --- build/gobind/monolith.go | 4 +-- cmd/dendrite-demo-yggdrasil/main.go | 3 ++- cmd/dendrite-demo-yggdrasil/yggconn/node.go | 28 ++++++++------------- go.mod | 2 +- go.sum | 4 +-- 5 files changed, 18 insertions(+), 23 deletions(-) diff --git a/build/gobind/monolith.go b/build/gobind/monolith.go index d415143e..5bf097e8 100644 --- a/build/gobind/monolith.go +++ b/build/gobind/monolith.go @@ -55,7 +55,7 @@ func (m *DendriteMonolith) DisconnectMulticastPeers() { m.YggdrasilNode.DisconnectMulticastPeers() } -func (m *DendriteMonolith) Start(staticPeer string, enableMulticast bool) { +func (m *DendriteMonolith) Start() { logger := logrus.Logger{ Out: BindLogger{}, } @@ -67,7 +67,7 @@ func (m *DendriteMonolith) Start(staticPeer string, enableMulticast bool) { panic(err) } - ygg, err := yggconn.Setup("dendrite", staticPeer, m.StorageDirectory, enableMulticast) + ygg, err := yggconn.Setup("dendrite", m.StorageDirectory) if err != nil { panic(err) } diff --git a/cmd/dendrite-demo-yggdrasil/main.go b/cmd/dendrite-demo-yggdrasil/main.go index 9c8c5055..c9e0c58d 100644 --- a/cmd/dendrite-demo-yggdrasil/main.go +++ b/cmd/dendrite-demo-yggdrasil/main.go @@ -54,10 +54,11 @@ func main() { flag.Parse() internal.SetupPprof() - ygg, err := yggconn.Setup(*instanceName, *instancePeer, ".", true) + ygg, err := yggconn.Setup(*instanceName, ".") if err != nil { panic(err) } + ygg.SetMulticastEnabled(true) cfg := &config.Dendrite{} cfg.SetDefaults() diff --git a/cmd/dendrite-demo-yggdrasil/yggconn/node.go b/cmd/dendrite-demo-yggdrasil/yggconn/node.go index c89b0dc1..140e582c 100644 --- a/cmd/dendrite-demo-yggdrasil/yggconn/node.go +++ b/cmd/dendrite-demo-yggdrasil/yggconn/node.go @@ -80,7 +80,7 @@ func (n *Node) DialerContext(ctx context.Context, network, address string) (net. } // nolint:gocyclo -func Setup(instanceName, instancePeer, storageDirectory string, enableMulticast bool) (*Node, error) { +func Setup(instanceName, storageDirectory string) (*Node, error) { n := &Node{ core: &yggdrasil.Core{}, config: yggdrasilconfig.GenerateConfig(), @@ -102,17 +102,9 @@ func Setup(instanceName, instancePeer, storageDirectory string, enableMulticast } } - if instancePeer != "" { - n.config.Peers = []string{instancePeer} - } else { - n.config.Peers = []string{} - } + n.config.Peers = []string{} n.config.AdminListen = "none" - if enableMulticast { - n.config.MulticastInterfaces = []string{".*"} - } else { - n.config.MulticastInterfaces = []string{} - } + n.config.MulticastInterfaces = []string{} n.config.EncryptionPrivateKey = hex.EncodeToString(n.EncryptionPrivateKey()) n.config.EncryptionPublicKey = hex.EncodeToString(n.EncryptionPublicKey()) @@ -197,11 +189,9 @@ func (n *Node) PeerCount() int { func (n *Node) KnownNodes() []gomatrixserverlib.ServerName { nodemap := map[string]struct{}{} - /* - for _, peer := range n.core.GetSwitchPeers() { - nodemap[hex.EncodeToString(peer.SigningKey[:])] = struct{}{} - } - */ + for _, peer := range n.core.GetSwitchPeers() { + nodemap[hex.EncodeToString(peer.SigningKey[:])] = struct{}{} + } n.sessions.Range(func(_, v interface{}) bool { session, ok := v.(quic.Session) if !ok { @@ -262,7 +252,11 @@ func (n *Node) SetStaticPeer(uri string) error { if uri != "" { n.log.Infoln("Adding static peer", uri) if err := n.core.AddPeer(uri, ""); err != nil { - n.log.Infoln("Adding static peer failed:", err) + n.log.Warnln("Adding static peer failed:", err) + return err + } + if err := n.core.CallPeer(uri, ""); err != nil { + n.log.Warnln("Calling static peer failed:", err) return err } } diff --git a/go.mod b/go.mod index 00b9a9c6..4efd0bca 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,7 @@ require ( github.com/uber-go/atomic v1.3.0 // indirect github.com/uber/jaeger-client-go v2.15.0+incompatible github.com/uber/jaeger-lib v1.5.0 - github.com/yggdrasil-network/yggdrasil-go v0.3.15-0.20200706132141-82b2af2963bf + github.com/yggdrasil-network/yggdrasil-go v0.3.15-0.20200707124509-16343a00055c go.uber.org/atomic v1.4.0 golang.org/x/crypto v0.0.0-20200423211502-4bdfaf469ed5 gopkg.in/h2non/bimg.v1 v1.0.18 diff --git a/go.sum b/go.sum index dcc96c82..586fa39d 100644 --- a/go.sum +++ b/go.sum @@ -652,8 +652,8 @@ github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhe github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/yggdrasil-network/yggdrasil-extras v0.0.0-20200525205615-6c8a4a2e8855/go.mod h1:xQdsh08Io6nV4WRnOVTe6gI8/2iTvfLDQ0CYa5aMt+I= -github.com/yggdrasil-network/yggdrasil-go v0.3.15-0.20200706132141-82b2af2963bf h1:80RhF740jE7Rry2tg0UGnye95vBTZ/G6RNCBM7oiivE= -github.com/yggdrasil-network/yggdrasil-go v0.3.15-0.20200706132141-82b2af2963bf/go.mod h1:d+Nz6SPeG6kmeSPFL0cvfWfgwEql75fUnZiAONgvyBE= +github.com/yggdrasil-network/yggdrasil-go v0.3.15-0.20200707124509-16343a00055c h1:tK1FySfDA5xVT5sAK/3XjUCE9LEoandmVnrg4Hj0fXk= +github.com/yggdrasil-network/yggdrasil-go v0.3.15-0.20200707124509-16343a00055c/go.mod h1:d+Nz6SPeG6kmeSPFL0cvfWfgwEql75fUnZiAONgvyBE= go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.1/go.mod h1:Ap50jQcDJrx6rB6VgeeFPtuPIf3wMRvRfrfYDO6+BmA=