2020-06-19 07:29:27 -05:00
|
|
|
package yggconn
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
2020-12-02 11:41:00 -06:00
|
|
|
"github.com/matrix-org/dendrite/setup"
|
2020-06-19 07:29:27 -05:00
|
|
|
"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 10:00:42 -05:00
|
|
|
MaxIdleConns: -1,
|
|
|
|
MaxIdleConnsPerHost: -1,
|
|
|
|
TLSHandshakeTimeout: 10 * time.Second,
|
2020-07-10 10:28:18 -05:00
|
|
|
ResponseHeaderTimeout: 10 * time.Second,
|
2020-08-06 10:00:42 -05:00
|
|
|
IdleConnTimeout: 30 * time.Second,
|
2020-07-16 07:52:08 -05:00
|
|
|
DialContext: n.DialerContext,
|
2020-06-19 07:29:27 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
2021-01-22 10:09:05 -06:00
|
|
|
return gomatrixserverlib.NewClient(
|
|
|
|
gomatrixserverlib.WithTransport(tr),
|
|
|
|
)
|
2020-06-19 07:29:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Node) CreateFederationClient(
|
|
|
|
base *setup.BaseDendrite,
|
|
|
|
) *gomatrixserverlib.FederationClient {
|
|
|
|
tr := &http.Transport{}
|
|
|
|
tr.RegisterProtocol(
|
|
|
|
"matrix", &yggroundtripper{
|
|
|
|
inner: &http.Transport{
|
2020-08-06 10:00:42 -05:00
|
|
|
MaxIdleConns: -1,
|
|
|
|
MaxIdleConnsPerHost: -1,
|
|
|
|
TLSHandshakeTimeout: 10 * time.Second,
|
2020-07-10 10:28:18 -05:00
|
|
|
ResponseHeaderTimeout: 10 * time.Second,
|
2020-08-06 10:00:42 -05:00
|
|
|
IdleConnTimeout: 30 * time.Second,
|
2020-07-16 07:52:08 -05:00
|
|
|
DialContext: n.DialerContext,
|
|
|
|
TLSClientConfig: n.tlsConfig,
|
2020-06-19 07:29:27 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
2021-01-22 10:09:05 -06:00
|
|
|
return gomatrixserverlib.NewFederationClient(
|
2020-08-10 08:18:04 -05:00
|
|
|
base.Cfg.Global.ServerName, base.Cfg.Global.KeyID,
|
2021-01-22 10:09:05 -06:00
|
|
|
base.Cfg.Global.PrivateKey,
|
|
|
|
gomatrixserverlib.WithTransport(tr),
|
2020-06-19 07:29:27 -05:00
|
|
|
)
|
|
|
|
}
|