2020-06-19 12:29:27 +00: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 15:00:42 +00:00
|
|
|
MaxIdleConns: -1,
|
|
|
|
MaxIdleConnsPerHost: -1,
|
|
|
|
TLSHandshakeTimeout: 10 * time.Second,
|
2020-07-10 15:28:18 +00:00
|
|
|
ResponseHeaderTimeout: 10 * time.Second,
|
2020-08-06 15:00:42 +00:00
|
|
|
IdleConnTimeout: 30 * time.Second,
|
2020-07-16 12:52:08 +00:00
|
|
|
DialContext: n.DialerContext,
|
2020-06-19 12:29:27 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
2020-10-09 16:08:32 +00:00
|
|
|
return gomatrixserverlib.NewClientWithTransport(tr)
|
2020-06-19 12:29:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Node) CreateFederationClient(
|
|
|
|
base *setup.BaseDendrite,
|
|
|
|
) *gomatrixserverlib.FederationClient {
|
|
|
|
tr := &http.Transport{}
|
|
|
|
tr.RegisterProtocol(
|
|
|
|
"matrix", &yggroundtripper{
|
|
|
|
inner: &http.Transport{
|
2020-08-06 15:00:42 +00:00
|
|
|
MaxIdleConns: -1,
|
|
|
|
MaxIdleConnsPerHost: -1,
|
|
|
|
TLSHandshakeTimeout: 10 * time.Second,
|
2020-07-10 15:28:18 +00:00
|
|
|
ResponseHeaderTimeout: 10 * time.Second,
|
2020-08-06 15:00:42 +00:00
|
|
|
IdleConnTimeout: 30 * time.Second,
|
2020-07-16 12:52:08 +00:00
|
|
|
DialContext: n.DialerContext,
|
|
|
|
TLSClientConfig: n.tlsConfig,
|
2020-06-19 12:29:27 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
return gomatrixserverlib.NewFederationClientWithTransport(
|
2020-08-10 13:18:04 +00:00
|
|
|
base.Cfg.Global.ServerName, base.Cfg.Global.KeyID,
|
|
|
|
base.Cfg.Global.PrivateKey, true, tr,
|
2020-06-19 12:29:27 +00:00
|
|
|
)
|
|
|
|
}
|