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