2020-06-19 07:29:27 -05: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-07-10 10:28:18 -05:00
|
|
|
TLSHandshakeTimeout: 20 * time.Second,
|
|
|
|
ResponseHeaderTimeout: 10 * time.Second,
|
2020-06-19 07:29:27 -05:00
|
|
|
IdleConnTimeout: 60 * time.Second,
|
2020-07-16 07:52:08 -05:00
|
|
|
DialContext: n.DialerContext,
|
2020-06-19 07:29:27 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
return gomatrixserverlib.NewClientWithTransport(tr)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Node) CreateFederationClient(
|
|
|
|
base *setup.BaseDendrite,
|
|
|
|
) *gomatrixserverlib.FederationClient {
|
|
|
|
tr := &http.Transport{}
|
|
|
|
tr.RegisterProtocol(
|
|
|
|
"matrix", &yggroundtripper{
|
|
|
|
inner: &http.Transport{
|
2020-07-10 10:28:18 -05:00
|
|
|
TLSHandshakeTimeout: 20 * time.Second,
|
|
|
|
ResponseHeaderTimeout: 10 * time.Second,
|
2020-06-19 07:29:27 -05:00
|
|
|
IdleConnTimeout: 60 * time.Second,
|
2020-07-16 07:52:08 -05:00
|
|
|
DialContext: n.DialerContext,
|
|
|
|
TLSClientConfig: n.tlsConfig,
|
2020-06-19 07:29:27 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
return gomatrixserverlib.NewFederationClientWithTransport(
|
|
|
|
base.Cfg.Matrix.ServerName, base.Cfg.Matrix.KeyID, base.Cfg.Matrix.PrivateKey, tr,
|
|
|
|
)
|
|
|
|
}
|