diff options
author | Neil Alexander <neilalexander@users.noreply.github.com> | 2021-01-22 16:09:05 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-22 16:09:05 +0000 |
commit | 6757b67a321c684769ad022351541c7c6417c693 (patch) | |
tree | 261accd97b834dfb42b9bbade97a4e3c2067e3d2 | |
parent | 93942f8ab62ffdb55888d5d35adef6fe73e3ea59 (diff) |
NewClient and NewFederationClient updates (#1730)
* Use matrix-org/gomatrixserverlib#252
* Add missing WithSkipVerify to test
* Functions instead
* Update gomatrixserverlib to matrix-org/gomatrixserverlib#252
* Fix disabling TLS validation
-rw-r--r-- | cmd/dendrite-demo-libp2p/main.go | 9 | ||||
-rw-r--r-- | cmd/dendrite-demo-yggdrasil/yggconn/client.go | 9 | ||||
-rw-r--r-- | cmd/dendritejs/main.go | 8 | ||||
-rw-r--r-- | cmd/furl/main.go | 1 | ||||
-rw-r--r-- | federationapi/federationapi_test.go | 5 | ||||
-rw-r--r-- | go.mod | 2 | ||||
-rw-r--r-- | go.sum | 4 | ||||
-rw-r--r-- | keyserver/internal/device_list_update_test.go | 6 | ||||
-rw-r--r-- | setup/base.go | 31 | ||||
-rw-r--r-- | signingkeyserver/serverkeyapi_test.go | 5 |
10 files changed, 49 insertions, 31 deletions
diff --git a/cmd/dendrite-demo-libp2p/main.go b/cmd/dendrite-demo-libp2p/main.go index 3acec2fd..31e7739a 100644 --- a/cmd/dendrite-demo-libp2p/main.go +++ b/cmd/dendrite-demo-libp2p/main.go @@ -76,9 +76,10 @@ func createFederationClient( "matrix", p2phttp.NewTransport(base.LibP2P, p2phttp.ProtocolOption("/matrix")), ) - return gomatrixserverlib.NewFederationClientWithTransport( + return gomatrixserverlib.NewFederationClient( base.Base.Cfg.Global.ServerName, base.Base.Cfg.Global.KeyID, - base.Base.Cfg.Global.PrivateKey, true, tr, + base.Base.Cfg.Global.PrivateKey, + gomatrixserverlib.WithTransport(tr), ) } @@ -90,7 +91,9 @@ func createClient( "matrix", p2phttp.NewTransport(base.LibP2P, p2phttp.ProtocolOption("/matrix")), ) - return gomatrixserverlib.NewClientWithTransport(tr) + return gomatrixserverlib.NewClient( + gomatrixserverlib.WithTransport(tr), + ) } func main() { diff --git a/cmd/dendrite-demo-yggdrasil/yggconn/client.go b/cmd/dendrite-demo-yggdrasil/yggconn/client.go index ea51f4b1..157a9bf2 100644 --- a/cmd/dendrite-demo-yggdrasil/yggconn/client.go +++ b/cmd/dendrite-demo-yggdrasil/yggconn/client.go @@ -33,7 +33,9 @@ func (n *Node) CreateClient( }, }, ) - return gomatrixserverlib.NewClientWithTransport(tr) + return gomatrixserverlib.NewClient( + gomatrixserverlib.WithTransport(tr), + ) } func (n *Node) CreateFederationClient( @@ -53,8 +55,9 @@ func (n *Node) CreateFederationClient( }, }, ) - return gomatrixserverlib.NewFederationClientWithTransport( + return gomatrixserverlib.NewFederationClient( base.Cfg.Global.ServerName, base.Cfg.Global.KeyID, - base.Cfg.Global.PrivateKey, true, tr, + base.Cfg.Global.PrivateKey, + gomatrixserverlib.WithTransport(tr), ) } diff --git a/cmd/dendritejs/main.go b/cmd/dendritejs/main.go index 1ffb1667..b77d141d 100644 --- a/cmd/dendritejs/main.go +++ b/cmd/dendritejs/main.go @@ -139,16 +139,18 @@ func createFederationClient(cfg *config.Dendrite, node *go_http_js_libp2p.P2pLoc tr := go_http_js_libp2p.NewP2pTransport(node) fed := gomatrixserverlib.NewFederationClient( - cfg.Global.ServerName, cfg.Global.KeyID, cfg.Global.PrivateKey, true, + cfg.Global.ServerName, cfg.Global.KeyID, cfg.Global.PrivateKey, + gomatrixserverlib.WithTransport(tr), ) - fed.Client = *gomatrixserverlib.NewClientWithTransport(tr) return fed } func createClient(node *go_http_js_libp2p.P2pLocalNode) *gomatrixserverlib.Client { tr := go_http_js_libp2p.NewP2pTransport(node) - return gomatrixserverlib.NewClientWithTransport(tr) + return gomatrixserverlib.NewClient( + gomatrixserverlib.WithTransport(tr), + ) } func createP2PNode(privKey ed25519.PrivateKey) (serverName string, node *go_http_js_libp2p.P2pLocalNode) { diff --git a/cmd/furl/main.go b/cmd/furl/main.go index 3955ef0c..bec04f0a 100644 --- a/cmd/furl/main.go +++ b/cmd/furl/main.go @@ -54,7 +54,6 @@ func main() { gomatrixserverlib.ServerName(*requestFrom), gomatrixserverlib.KeyID(keyBlock.Headers["Key-ID"]), privateKey, - false, ) u, err := url.Parse(flag.Arg(0)) diff --git a/federationapi/federationapi_test.go b/federationapi/federationapi_test.go index 923cd0ec..b97876d3 100644 --- a/federationapi/federationapi_test.go +++ b/federationapi/federationapi_test.go @@ -36,7 +36,10 @@ func TestRoomsV3URLEscapeDoNot404(t *testing.T) { defer cancel() serverName := gomatrixserverlib.ServerName(strings.TrimPrefix(baseURL, "https://")) - fedCli := gomatrixserverlib.NewFederationClient(serverName, cfg.Global.KeyID, cfg.Global.PrivateKey, true) + fedCli := gomatrixserverlib.NewFederationClient( + serverName, cfg.Global.KeyID, cfg.Global.PrivateKey, + gomatrixserverlib.WithSkipVerify(true), + ) testCases := []struct { roomVer gomatrixserverlib.RoomVersion @@ -22,7 +22,7 @@ require ( github.com/matrix-org/go-http-js-libp2p v0.0.0-20200518170932-783164aeeda4 github.com/matrix-org/go-sqlite3-js v0.0.0-20200522092705-bc8506ccbcf3 github.com/matrix-org/gomatrix v0.0.0-20200827122206-7dd5e2a05bcd - github.com/matrix-org/gomatrixserverlib v0.0.0-20210122141547-5c2c047bfdcd + github.com/matrix-org/gomatrixserverlib v0.0.0-20210122154608-a38974bd8a37 github.com/matrix-org/naffka v0.0.0-20200901083833-bcdd62999a91 github.com/matrix-org/util v0.0.0-20200807132607-55161520e1d4 github.com/mattn/go-sqlite3 v1.14.2 @@ -567,8 +567,8 @@ github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26 h1:Hr3zjRsq2bh github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26/go.mod h1:3fxX6gUjWyI/2Bt7J1OLhpCzOfO/bB3AiX0cJtEKud0= github.com/matrix-org/gomatrix v0.0.0-20200827122206-7dd5e2a05bcd h1:xVrqJK3xHREMNjwjljkAUaadalWc0rRbmVuQatzmgwg= github.com/matrix-org/gomatrix v0.0.0-20200827122206-7dd5e2a05bcd/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s= -github.com/matrix-org/gomatrixserverlib v0.0.0-20210122141547-5c2c047bfdcd h1:SbWP7aHgACfAQpI2te6LzxK3l0+UqPOb8NOCOxzwV1c= -github.com/matrix-org/gomatrixserverlib v0.0.0-20210122141547-5c2c047bfdcd/go.mod h1:JsAzE1Ll3+gDWS9JSUHPJiiyAksvOOnGWF2nXdg4ZzU= +github.com/matrix-org/gomatrixserverlib v0.0.0-20210122154608-a38974bd8a37 h1:si2CZZpwOLWZfDXfgHPkaTlaAkdJvpJzr1zVqyKXd0I= +github.com/matrix-org/gomatrixserverlib v0.0.0-20210122154608-a38974bd8a37/go.mod h1:JsAzE1Ll3+gDWS9JSUHPJiiyAksvOOnGWF2nXdg4ZzU= github.com/matrix-org/naffka v0.0.0-20200901083833-bcdd62999a91 h1:HJ6U3S3ljJqNffYMcIeAncp5qT/i+ZMiJ2JC2F0aXP4= github.com/matrix-org/naffka v0.0.0-20200901083833-bcdd62999a91/go.mod h1:sjyPyRxKM5uw1nD2cJ6O2OxI6GOqyVBfNXqKjBZTBZE= github.com/matrix-org/util v0.0.0-20190711121626-527ce5ddefc7 h1:ntrLa/8xVzeSs8vHFHK25k0C+NV74sYMJnNSg5NoSRo= diff --git a/keyserver/internal/device_list_update_test.go b/keyserver/internal/device_list_update_test.go index 9c4cc116..eab2a78d 100644 --- a/keyserver/internal/device_list_update_test.go +++ b/keyserver/internal/device_list_update_test.go @@ -106,9 +106,11 @@ func (t *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) { func newFedClient(tripper func(*http.Request) (*http.Response, error)) *gomatrixserverlib.FederationClient { _, pkey, _ := ed25519.GenerateKey(nil) fedClient := gomatrixserverlib.NewFederationClient( - gomatrixserverlib.ServerName("example.test"), gomatrixserverlib.KeyID("ed25519:test"), pkey, true, + gomatrixserverlib.ServerName("example.test"), gomatrixserverlib.KeyID("ed25519:test"), pkey, + ) + fedClient.Client = *gomatrixserverlib.NewClient( + gomatrixserverlib.WithTransport(&roundTripper{tripper}), ) - fedClient.Client = *gomatrixserverlib.NewClientWithTransport(&roundTripper{tripper}) return fedClient } diff --git a/setup/base.go b/setup/base.go index 5f0431e8..c30e6910 100644 --- a/setup/base.go +++ b/setup/base.go @@ -266,15 +266,17 @@ func (b *BaseDendrite) CreateAccountsDB() accounts.Database { // Should only be called once per component. func (b *BaseDendrite) CreateClient() *gomatrixserverlib.Client { if b.Cfg.Global.DisableFederation { - return gomatrixserverlib.NewClientWithTransport(noOpHTTPTransport) + return gomatrixserverlib.NewClient( + gomatrixserverlib.WithTransport(noOpHTTPTransport), + ) + } + opts := []gomatrixserverlib.ClientOption{ + gomatrixserverlib.WithSkipVerify(b.Cfg.FederationSender.DisableTLSValidation), } - opts := []gomatrixserverlib.ClientOption{} if b.Cfg.Global.DNSCache.Enabled { - opts = append(opts, gomatrixserverlib.WithDNSCache{DNSCache: b.DNSCache}) + opts = append(opts, gomatrixserverlib.WithDNSCache(b.DNSCache)) } - client := gomatrixserverlib.NewClient( - b.Cfg.FederationSender.DisableTLSValidation, opts..., - ) + client := gomatrixserverlib.NewClient(opts...) client.SetUserAgent(fmt.Sprintf("Dendrite/%s", internal.VersionString())) return client } @@ -283,18 +285,21 @@ func (b *BaseDendrite) CreateClient() *gomatrixserverlib.Client { // once per component. func (b *BaseDendrite) CreateFederationClient() *gomatrixserverlib.FederationClient { if b.Cfg.Global.DisableFederation { - return gomatrixserverlib.NewFederationClientWithTransport( + return gomatrixserverlib.NewFederationClient( b.Cfg.Global.ServerName, b.Cfg.Global.KeyID, b.Cfg.Global.PrivateKey, - b.Cfg.FederationSender.DisableTLSValidation, noOpHTTPTransport, + gomatrixserverlib.WithTransport(noOpHTTPTransport), ) } - opts := []gomatrixserverlib.ClientOption{} + opts := []gomatrixserverlib.ClientOption{ + gomatrixserverlib.WithTimeout(time.Minute * 5), + gomatrixserverlib.WithSkipVerify(b.Cfg.FederationSender.DisableTLSValidation), + } if b.Cfg.Global.DNSCache.Enabled { - opts = append(opts, gomatrixserverlib.WithDNSCache{DNSCache: b.DNSCache}) + opts = append(opts, gomatrixserverlib.WithDNSCache(b.DNSCache)) } - client := gomatrixserverlib.NewFederationClientWithTimeout( - b.Cfg.Global.ServerName, b.Cfg.Global.KeyID, b.Cfg.Global.PrivateKey, - b.Cfg.FederationSender.DisableTLSValidation, time.Minute*5, opts..., + client := gomatrixserverlib.NewFederationClient( + b.Cfg.Global.ServerName, b.Cfg.Global.KeyID, + b.Cfg.Global.PrivateKey, opts..., ) client.SetUserAgent(fmt.Sprintf("Dendrite/%s", internal.VersionString())) return client diff --git a/signingkeyserver/serverkeyapi_test.go b/signingkeyserver/serverkeyapi_test.go index e59deb4d..bd6119aa 100644 --- a/signingkeyserver/serverkeyapi_test.go +++ b/signingkeyserver/serverkeyapi_test.go @@ -87,8 +87,9 @@ func TestMain(m *testing.M) { transport.RegisterProtocol("matrix", &MockRoundTripper{}) // Create the federation client. - s.fedclient = gomatrixserverlib.NewFederationClientWithTransport( - s.config.Matrix.ServerName, serverKeyID, testPriv, true, transport, + s.fedclient = gomatrixserverlib.NewFederationClient( + s.config.Matrix.ServerName, serverKeyID, testPriv, + gomatrixserverlib.WithTransport(transport), ) // Finally, build the server key APIs. |