2020-06-19 12:29:27 +00:00
|
|
|
package yggconn
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
2023-03-22 08:21:32 +00:00
|
|
|
"github.com/matrix-org/dendrite/setup/config"
|
2023-04-06 08:55:01 +00:00
|
|
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
2020-06-19 12:29:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2023-04-06 08:55:01 +00:00
|
|
|
func (n *Node) CreateClient() *fclient.Client {
|
2020-06-19 12:29:27 +00:00
|
|
|
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
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
2023-04-06 08:55:01 +00:00
|
|
|
return fclient.NewClient(
|
|
|
|
fclient.WithTransport(tr),
|
2021-01-22 16:09:05 +00:00
|
|
|
)
|
2020-06-19 12:29:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Node) CreateFederationClient(
|
2023-03-22 08:21:32 +00:00
|
|
|
cfg *config.Dendrite,
|
2023-04-24 16:23:25 +00:00
|
|
|
) fclient.FederationClient {
|
2020-06-19 12:29:27 +00:00
|
|
|
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
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
2023-04-06 08:55:01 +00:00
|
|
|
return fclient.NewFederationClient(
|
2023-03-22 08:21:32 +00:00
|
|
|
cfg.Global.SigningIdentities(),
|
2023-04-06 08:55:01 +00:00
|
|
|
fclient.WithTransport(tr),
|
2020-06-19 12:29:27 +00:00
|
|
|
)
|
|
|
|
}
|