diff options
author | Neil Alexander <neilalexander@users.noreply.github.com> | 2020-07-10 16:28:18 +0100 |
---|---|---|
committer | Neil Alexander <neilalexander@users.noreply.github.com> | 2020-07-10 16:28:18 +0100 |
commit | 08e9d996b6e9f726425d815820e3857c12ebc0b3 (patch) | |
tree | 6202a6b0c68d0ba2b36688732ff899b91f157f15 /cmd/dendrite-demo-yggdrasil | |
parent | abf26c12f1a97fd2894a0509de9cf4a91c79d3ab (diff) |
Yggdrasil demo updates
Squashed commit of the following:
commit 6c2c48f862c1b6f8e741c57804282eceffe02487
Author: Neil Alexander <neilalexander@users.noreply.github.com>
Date: Fri Jul 10 16:28:09 2020 +0100
Add README.md
commit 5eeefdadf8e3881dd7a32559a92be49bd7ddaf47
Author: Neil Alexander <neilalexander@users.noreply.github.com>
Date: Fri Jul 10 10:18:50 2020 +0100
Fix wedge in federation sender
commit e2ebffbfba25cf82378393940a613ec32bfb909f
Merge: 0883ef88 abf26c12
Author: Neil Alexander <neilalexander@users.noreply.github.com>
Date: Fri Jul 10 09:51:23 2020 +0100
Merge branch 'master' into neilalexander/yggdrasil
commit 0883ef8870e340f2ae9a0c37ed939dc2ab9911f6
Author: Neil Alexander <neilalexander@users.noreply.github.com>
Date: Fri Jul 10 09:51:06 2020 +0100
Adjust timeouts
commit ba2d53199910f13b60cc892debe96a962e8c9acb
Author: Neil Alexander <neilalexander@users.noreply.github.com>
Date: Thu Jul 9 16:34:40 2020 +0100
Try to wake up from peers/sessions properly
commit 73f42eb494741ba5b0e0cef43654708e3c8eb399
Author: Neil Alexander <neilalexander@users.noreply.github.com>
Date: Thu Jul 9 15:43:38 2020 +0100
Use TransactionWriter to reduce database lock issues on SQLite
commit 08bfe63241a18c58c539c91b9f52edccda63a611
Author: Neil Alexander <neilalexander@users.noreply.github.com>
Date: Thu Jul 9 12:38:02 2020 +0100
Un-wedge federation
Squashed commit of the following:
commit aee933f8785e7a7998105f6090f514d18051a1bd
Author: Neil Alexander <neilalexander@users.noreply.github.com>
Date: Thu Jul 9 12:22:41 2020 +0100
Un-goroutine the goroutines
commit 478374e5d18a3056cac6682ef9095d41352d1295
Author: Neil Alexander <neilalexander@users.noreply.github.com>
Date: Thu Jul 9 12:09:31 2020 +0100
Reduce federation sender wedges
commit 40cc62c54d9e3a863868214c48b7c18e522a4772
Author: Neil Alexander <neilalexander@users.noreply.github.com>
Date: Thu Jul 9 10:02:52 2020 +0100
Handle switching in/out background more reliably
Diffstat (limited to 'cmd/dendrite-demo-yggdrasil')
-rw-r--r-- | cmd/dendrite-demo-yggdrasil/README.md | 22 | ||||
-rw-r--r-- | cmd/dendrite-demo-yggdrasil/main.go | 18 | ||||
-rw-r--r-- | cmd/dendrite-demo-yggdrasil/yggconn/client.go | 6 | ||||
-rw-r--r-- | cmd/dendrite-demo-yggdrasil/yggconn/node.go | 19 | ||||
-rw-r--r-- | cmd/dendrite-demo-yggdrasil/yggconn/session.go | 7 |
5 files changed, 50 insertions, 22 deletions
diff --git a/cmd/dendrite-demo-yggdrasil/README.md b/cmd/dendrite-demo-yggdrasil/README.md new file mode 100644 index 00000000..148b9a58 --- /dev/null +++ b/cmd/dendrite-demo-yggdrasil/README.md @@ -0,0 +1,22 @@ +# Yggdrasil Demo + +This is the Dendrite Yggdrasil demo! It's easy to get started - all you need is Go 1.13 or later. + +To run the homeserver, start at the root of the Dendrite repository and run: + +``` +go run ./cmd/dendrite-demo-yggdrasil +``` + +The following command line arguments are accepted: + +* `-peer tcp://a.b.c.d:e` to specify a static Yggdrasil peer to connect to - you will need to supply this if you do not have another Yggdrasil node on your network +* `-port 12345` to specify a port to listen on for client connections + +If you need to find an internet peer, take a look at [this list](https://publicpeers.neilalexander.dev/). + +Then point your favourite Matrix client to the homeserver URL`http://localhost:8008` (or whichever `-port` you specified), create an account and log in. + +If your peering connection is operational then you should see a `Connected TCP:` line in the log output. If not then try a different peer. + +Once logged in, you should be able to open the room directory or join a room by its ID.
\ No newline at end of file diff --git a/cmd/dendrite-demo-yggdrasil/main.go b/cmd/dendrite-demo-yggdrasil/main.go index 65747756..122d0266 100644 --- a/cmd/dendrite-demo-yggdrasil/main.go +++ b/cmd/dendrite-demo-yggdrasil/main.go @@ -17,6 +17,7 @@ package main import ( "context" "crypto/tls" + "encoding/hex" "flag" "fmt" "net" @@ -154,27 +155,28 @@ func main() { base.UseHTTPAPIs, ) - ygg.NotifySessionNew(func(boxPubKey crypto.BoxPubKey) { + ygg.NewSession = func(serverName gomatrixserverlib.ServerName) { + logrus.Infof("Found new session %q", serverName) req := &api.PerformServersAliveRequest{ - Servers: []gomatrixserverlib.ServerName{ - gomatrixserverlib.ServerName(boxPubKey.String()), - }, + Servers: []gomatrixserverlib.ServerName{serverName}, } res := &api.PerformServersAliveResponse{} if err := fsAPI.PerformServersAlive(context.TODO(), req, res); err != nil { logrus.WithError(err).Warn("Failed to notify server alive due to new session") } - }) + } - ygg.NotifyLinkNew(func(boxPubKey crypto.BoxPubKey, linkType, remote string) { + ygg.NotifyLinkNew(func(_ crypto.BoxPubKey, sigPubKey crypto.SigPubKey, linkType, remote string) { + serverName := hex.EncodeToString(sigPubKey[:]) + logrus.Infof("Found new peer %q", serverName) req := &api.PerformServersAliveRequest{ Servers: []gomatrixserverlib.ServerName{ - gomatrixserverlib.ServerName(boxPubKey.String()), + gomatrixserverlib.ServerName(serverName), }, } res := &api.PerformServersAliveResponse{} if err := fsAPI.PerformServersAlive(context.TODO(), req, res); err != nil { - logrus.WithError(err).Warn("Failed to notify server alive due to new link") + logrus.WithError(err).Warn("Failed to notify server alive due to new session") } }) diff --git a/cmd/dendrite-demo-yggdrasil/yggconn/client.go b/cmd/dendrite-demo-yggdrasil/yggconn/client.go index 399993e3..b74468db 100644 --- a/cmd/dendrite-demo-yggdrasil/yggconn/client.go +++ b/cmd/dendrite-demo-yggdrasil/yggconn/client.go @@ -46,7 +46,8 @@ func (n *Node) CreateClient( tr.RegisterProtocol( "matrix", &yggroundtripper{ inner: &http.Transport{ - ResponseHeaderTimeout: 15 * time.Second, + TLSHandshakeTimeout: 20 * time.Second, + ResponseHeaderTimeout: 10 * time.Second, IdleConnTimeout: 60 * time.Second, DialContext: n.yggdialerctx, }, @@ -62,7 +63,8 @@ func (n *Node) CreateFederationClient( tr.RegisterProtocol( "matrix", &yggroundtripper{ inner: &http.Transport{ - ResponseHeaderTimeout: 15 * time.Second, + TLSHandshakeTimeout: 20 * time.Second, + ResponseHeaderTimeout: 10 * time.Second, IdleConnTimeout: 60 * time.Second, DialContext: n.yggdialerctx, }, diff --git a/cmd/dendrite-demo-yggdrasil/yggconn/node.go b/cmd/dendrite-demo-yggdrasil/yggconn/node.go index 89fb69b5..2bc300c8 100644 --- a/cmd/dendrite-demo-yggdrasil/yggconn/node.go +++ b/cmd/dendrite-demo-yggdrasil/yggconn/node.go @@ -55,6 +55,7 @@ type Node struct { quicConfig *quic.Config sessions sync.Map // string -> quic.Session incoming chan QUICStream + NewSession func(remote gomatrixserverlib.ServerName) } func (n *Node) BuildName() string { @@ -137,7 +138,7 @@ func Setup(instanceName, storageDirectory string) (*Node, error) { MaxIncomingStreams: 0, MaxIncomingUniStreams: 0, KeepAlive: true, - MaxIdleTimeout: time.Second * 60, + MaxIdleTimeout: time.Minute * 15, HandshakeTimeout: time.Second * 15, } @@ -189,7 +190,9 @@ func (n *Node) PeerCount() int { } func (n *Node) KnownNodes() []gomatrixserverlib.ServerName { - nodemap := map[string]struct{}{} + nodemap := map[string]struct{}{ + "b5ae50589e50991dd9dd7d59c5c5f7a4521e8da5b603b7f57076272abc58b374": struct{}{}, + } for _, peer := range n.core.GetSwitchPeers() { nodemap[hex.EncodeToString(peer.SigningKey[:])] = struct{}{} } @@ -264,18 +267,10 @@ func (n *Node) SetStaticPeer(uri string) error { return nil } -func (n *Node) NotifyLinkNew(f func(boxPubKey crypto.BoxPubKey, linkType, remote string)) { +func (n *Node) NotifyLinkNew(f func(boxPubKey crypto.BoxPubKey, sigPubKey crypto.SigPubKey, linkType, remote string)) { n.core.NotifyLinkNew(f) } -func (n *Node) NotifyLinkGone(f func(boxPubKey crypto.BoxPubKey, linkType, remote string)) { +func (n *Node) NotifyLinkGone(f func(boxPubKey crypto.BoxPubKey, sigPubKey crypto.SigPubKey, linkType, remote string)) { n.core.NotifyLinkGone(f) } - -func (n *Node) NotifySessionNew(f func(boxPubKey crypto.BoxPubKey)) { - n.core.NotifySessionNew(f) -} - -func (n *Node) NotifySessionGone(f func(boxPubKey crypto.BoxPubKey)) { - n.core.NotifySessionGone(f) -} diff --git a/cmd/dendrite-demo-yggdrasil/yggconn/session.go b/cmd/dendrite-demo-yggdrasil/yggconn/session.go index 01cec813..ff77e64f 100644 --- a/cmd/dendrite-demo-yggdrasil/yggconn/session.go +++ b/cmd/dendrite-demo-yggdrasil/yggconn/session.go @@ -29,6 +29,7 @@ import ( "time" "github.com/lucas-clemente/quic-go" + "github.com/matrix-org/gomatrixserverlib" "github.com/yggdrasil-network/yggdrasil-go/src/crypto" ) @@ -56,6 +57,12 @@ func (n *Node) listenFromYgg() { func (n *Node) listenFromQUIC(session quic.Session) { n.sessions.Store(session.RemoteAddr().String(), session) defer n.sessions.Delete(session.RemoteAddr()) + if n.NewSession != nil { + if len(session.ConnectionState().PeerCertificates) == 1 { + subjectName := session.ConnectionState().PeerCertificates[0].Subject.CommonName + go n.NewSession(gomatrixserverlib.ServerName(subjectName)) + } + } for { st, err := session.AcceptStream(context.TODO()) if err != nil { |