2020-06-19 13:29:27 +01:00
|
|
|
package yggconn
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/matrix-org/dendrite/internal/setup"
|
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
|
|
|
)
|
|
|
|
|
|
|
|
type yggroundtripper struct {
|
|
|
|
inner *http.Transport
|
|
|
|
}
|
|
|
|
|
|
|
|
func (y *yggroundtripper) RoundTrip(req *http.Request) (*http.Response, error) {
|
|
|
|
req.URL.Scheme = "http"
|
|
|
|
return y.inner.RoundTrip(req)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Node) CreateClient(
|
|
|
|
base *setup.BaseDendrite,
|
|
|
|
) *gomatrixserverlib.Client {
|
|
|
|
tr := &http.Transport{}
|
|
|
|
tr.RegisterProtocol(
|
|
|
|
"matrix", &yggroundtripper{
|
|
|
|
inner: &http.Transport{
|
2020-08-06 16:00:42 +01:00
|
|
|
MaxIdleConns: -1,
|
|
|
|
MaxIdleConnsPerHost: -1,
|
|
|
|
TLSHandshakeTimeout: 10 * time.Second,
|
2020-07-10 16:28:18 +01:00
|
|
|
ResponseHeaderTimeout: 10 * time.Second,
|
2020-08-06 16:00:42 +01:00
|
|
|
IdleConnTimeout: 30 * time.Second,
|
2020-07-16 13:52:08 +01:00
|
|
|
DialContext: n.DialerContext,
|
2020-06-19 13:29:27 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
2020-08-07 17:25:31 +01:00
|
|
|
return gomatrixserverlib.NewClientWithTransport(true, tr)
|
2020-06-19 13:29:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Node) CreateFederationClient(
|
|
|
|
base *setup.BaseDendrite,
|
|
|
|
) *gomatrixserverlib.FederationClient {
|
|
|
|
tr := &http.Transport{}
|
|
|
|
tr.RegisterProtocol(
|
|
|
|
"matrix", &yggroundtripper{
|
|
|
|
inner: &http.Transport{
|
2020-08-06 16:00:42 +01:00
|
|
|
MaxIdleConns: -1,
|
|
|
|
MaxIdleConnsPerHost: -1,
|
|
|
|
TLSHandshakeTimeout: 10 * time.Second,
|
2020-07-10 16:28:18 +01:00
|
|
|
ResponseHeaderTimeout: 10 * time.Second,
|
2020-08-06 16:00:42 +01:00
|
|
|
IdleConnTimeout: 30 * time.Second,
|
2020-07-16 13:52:08 +01:00
|
|
|
DialContext: n.DialerContext,
|
|
|
|
TLSClientConfig: n.tlsConfig,
|
2020-06-19 13:29:27 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
return gomatrixserverlib.NewFederationClientWithTransport(
|
2020-08-07 17:25:31 +01:00
|
|
|
base.Cfg.Matrix.ServerName, base.Cfg.Matrix.KeyID,
|
|
|
|
base.Cfg.Matrix.PrivateKey, true, tr,
|
2020-06-19 13:29:27 +01:00
|
|
|
)
|
|
|
|
}
|