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
This commit is contained in:
parent
93942f8ab6
commit
6757b67a32
|
@ -76,9 +76,10 @@ func createFederationClient(
|
||||||
"matrix",
|
"matrix",
|
||||||
p2phttp.NewTransport(base.LibP2P, p2phttp.ProtocolOption("/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.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",
|
"matrix",
|
||||||
p2phttp.NewTransport(base.LibP2P, p2phttp.ProtocolOption("/matrix")),
|
p2phttp.NewTransport(base.LibP2P, p2phttp.ProtocolOption("/matrix")),
|
||||||
)
|
)
|
||||||
return gomatrixserverlib.NewClientWithTransport(tr)
|
return gomatrixserverlib.NewClient(
|
||||||
|
gomatrixserverlib.WithTransport(tr),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -33,7 +33,9 @@ func (n *Node) CreateClient(
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
return gomatrixserverlib.NewClientWithTransport(tr)
|
return gomatrixserverlib.NewClient(
|
||||||
|
gomatrixserverlib.WithTransport(tr),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) CreateFederationClient(
|
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.ServerName, base.Cfg.Global.KeyID,
|
||||||
base.Cfg.Global.PrivateKey, true, tr,
|
base.Cfg.Global.PrivateKey,
|
||||||
|
gomatrixserverlib.WithTransport(tr),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,16 +139,18 @@ func createFederationClient(cfg *config.Dendrite, node *go_http_js_libp2p.P2pLoc
|
||||||
tr := go_http_js_libp2p.NewP2pTransport(node)
|
tr := go_http_js_libp2p.NewP2pTransport(node)
|
||||||
|
|
||||||
fed := gomatrixserverlib.NewFederationClient(
|
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
|
return fed
|
||||||
}
|
}
|
||||||
|
|
||||||
func createClient(node *go_http_js_libp2p.P2pLocalNode) *gomatrixserverlib.Client {
|
func createClient(node *go_http_js_libp2p.P2pLocalNode) *gomatrixserverlib.Client {
|
||||||
tr := go_http_js_libp2p.NewP2pTransport(node)
|
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) {
|
func createP2PNode(privKey ed25519.PrivateKey) (serverName string, node *go_http_js_libp2p.P2pLocalNode) {
|
||||||
|
|
|
@ -54,7 +54,6 @@ func main() {
|
||||||
gomatrixserverlib.ServerName(*requestFrom),
|
gomatrixserverlib.ServerName(*requestFrom),
|
||||||
gomatrixserverlib.KeyID(keyBlock.Headers["Key-ID"]),
|
gomatrixserverlib.KeyID(keyBlock.Headers["Key-ID"]),
|
||||||
privateKey,
|
privateKey,
|
||||||
false,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
u, err := url.Parse(flag.Arg(0))
|
u, err := url.Parse(flag.Arg(0))
|
||||||
|
|
|
@ -36,7 +36,10 @@ func TestRoomsV3URLEscapeDoNot404(t *testing.T) {
|
||||||
defer cancel()
|
defer cancel()
|
||||||
serverName := gomatrixserverlib.ServerName(strings.TrimPrefix(baseURL, "https://"))
|
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 {
|
testCases := []struct {
|
||||||
roomVer gomatrixserverlib.RoomVersion
|
roomVer gomatrixserverlib.RoomVersion
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -22,7 +22,7 @@ require (
|
||||||
github.com/matrix-org/go-http-js-libp2p v0.0.0-20200518170932-783164aeeda4
|
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/go-sqlite3-js v0.0.0-20200522092705-bc8506ccbcf3
|
||||||
github.com/matrix-org/gomatrix v0.0.0-20200827122206-7dd5e2a05bcd
|
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/naffka v0.0.0-20200901083833-bcdd62999a91
|
||||||
github.com/matrix-org/util v0.0.0-20200807132607-55161520e1d4
|
github.com/matrix-org/util v0.0.0-20200807132607-55161520e1d4
|
||||||
github.com/mattn/go-sqlite3 v1.14.2
|
github.com/mattn/go-sqlite3 v1.14.2
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -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-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 h1:xVrqJK3xHREMNjwjljkAUaadalWc0rRbmVuQatzmgwg=
|
||||||
github.com/matrix-org/gomatrix v0.0.0-20200827122206-7dd5e2a05bcd/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
|
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-20210122154608-a38974bd8a37 h1:si2CZZpwOLWZfDXfgHPkaTlaAkdJvpJzr1zVqyKXd0I=
|
||||||
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/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 h1:HJ6U3S3ljJqNffYMcIeAncp5qT/i+ZMiJ2JC2F0aXP4=
|
||||||
github.com/matrix-org/naffka v0.0.0-20200901083833-bcdd62999a91/go.mod h1:sjyPyRxKM5uw1nD2cJ6O2OxI6GOqyVBfNXqKjBZTBZE=
|
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=
|
github.com/matrix-org/util v0.0.0-20190711121626-527ce5ddefc7 h1:ntrLa/8xVzeSs8vHFHK25k0C+NV74sYMJnNSg5NoSRo=
|
||||||
|
|
|
@ -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 {
|
func newFedClient(tripper func(*http.Request) (*http.Response, error)) *gomatrixserverlib.FederationClient {
|
||||||
_, pkey, _ := ed25519.GenerateKey(nil)
|
_, pkey, _ := ed25519.GenerateKey(nil)
|
||||||
fedClient := gomatrixserverlib.NewFederationClient(
|
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
|
return fedClient
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -266,15 +266,17 @@ func (b *BaseDendrite) CreateAccountsDB() accounts.Database {
|
||||||
// Should only be called once per component.
|
// Should only be called once per component.
|
||||||
func (b *BaseDendrite) CreateClient() *gomatrixserverlib.Client {
|
func (b *BaseDendrite) CreateClient() *gomatrixserverlib.Client {
|
||||||
if b.Cfg.Global.DisableFederation {
|
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 {
|
if b.Cfg.Global.DNSCache.Enabled {
|
||||||
opts = append(opts, gomatrixserverlib.WithDNSCache{DNSCache: b.DNSCache})
|
opts = append(opts, gomatrixserverlib.WithDNSCache(b.DNSCache))
|
||||||
}
|
}
|
||||||
client := gomatrixserverlib.NewClient(
|
client := gomatrixserverlib.NewClient(opts...)
|
||||||
b.Cfg.FederationSender.DisableTLSValidation, opts...,
|
|
||||||
)
|
|
||||||
client.SetUserAgent(fmt.Sprintf("Dendrite/%s", internal.VersionString()))
|
client.SetUserAgent(fmt.Sprintf("Dendrite/%s", internal.VersionString()))
|
||||||
return client
|
return client
|
||||||
}
|
}
|
||||||
|
@ -283,18 +285,21 @@ func (b *BaseDendrite) CreateClient() *gomatrixserverlib.Client {
|
||||||
// once per component.
|
// once per component.
|
||||||
func (b *BaseDendrite) CreateFederationClient() *gomatrixserverlib.FederationClient {
|
func (b *BaseDendrite) CreateFederationClient() *gomatrixserverlib.FederationClient {
|
||||||
if b.Cfg.Global.DisableFederation {
|
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.Global.ServerName, b.Cfg.Global.KeyID, b.Cfg.Global.PrivateKey,
|
||||||
b.Cfg.FederationSender.DisableTLSValidation, noOpHTTPTransport,
|
gomatrixserverlib.WithTransport(noOpHTTPTransport),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
opts := []gomatrixserverlib.ClientOption{}
|
opts := []gomatrixserverlib.ClientOption{
|
||||||
if b.Cfg.Global.DNSCache.Enabled {
|
gomatrixserverlib.WithTimeout(time.Minute * 5),
|
||||||
opts = append(opts, gomatrixserverlib.WithDNSCache{DNSCache: b.DNSCache})
|
gomatrixserverlib.WithSkipVerify(b.Cfg.FederationSender.DisableTLSValidation),
|
||||||
}
|
}
|
||||||
client := gomatrixserverlib.NewFederationClientWithTimeout(
|
if b.Cfg.Global.DNSCache.Enabled {
|
||||||
b.Cfg.Global.ServerName, b.Cfg.Global.KeyID, b.Cfg.Global.PrivateKey,
|
opts = append(opts, gomatrixserverlib.WithDNSCache(b.DNSCache))
|
||||||
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()))
|
client.SetUserAgent(fmt.Sprintf("Dendrite/%s", internal.VersionString()))
|
||||||
return client
|
return client
|
||||||
|
|
|
@ -87,8 +87,9 @@ func TestMain(m *testing.M) {
|
||||||
transport.RegisterProtocol("matrix", &MockRoundTripper{})
|
transport.RegisterProtocol("matrix", &MockRoundTripper{})
|
||||||
|
|
||||||
// Create the federation client.
|
// Create the federation client.
|
||||||
s.fedclient = gomatrixserverlib.NewFederationClientWithTransport(
|
s.fedclient = gomatrixserverlib.NewFederationClient(
|
||||||
s.config.Matrix.ServerName, serverKeyID, testPriv, true, transport,
|
s.config.Matrix.ServerName, serverKeyID, testPriv,
|
||||||
|
gomatrixserverlib.WithTransport(transport),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Finally, build the server key APIs.
|
// Finally, build the server key APIs.
|
||||||
|
|
Loading…
Reference in a new issue