gb vendor updates

gb vendor update github.com/matrix-org/gomatrixserverlib
gb vendor update github.com/matrix-org/util
main
Richard van der Hoff 2017-10-02 10:33:43 +01:00
parent b7687310fe
commit 831a76ae91
5 changed files with 23 additions and 6 deletions

4
vendor/manifest vendored
View File

@ -141,7 +141,7 @@
{ {
"importpath": "github.com/matrix-org/gomatrixserverlib", "importpath": "github.com/matrix-org/gomatrixserverlib",
"repository": "https://github.com/matrix-org/gomatrixserverlib", "repository": "https://github.com/matrix-org/gomatrixserverlib",
"revision": "27d214da42f51906c2038ad3ddcffac9103c8e8f", "revision": "fb17c27f65a0699b0d15f5311a530225b4aea5e0",
"branch": "master" "branch": "master"
}, },
{ {
@ -153,7 +153,7 @@
{ {
"importpath": "github.com/matrix-org/util", "importpath": "github.com/matrix-org/util",
"repository": "https://github.com/matrix-org/util", "repository": "https://github.com/matrix-org/util",
"revision": "53326ed5598b226681112cbd441f59f3cffc9c82", "revision": "cf7e2e3871b7ae39106a1763312deaaf0c139531",
"branch": "master" "branch": "master"
}, },
{ {

View File

@ -92,7 +92,13 @@ func (f *federationTripper) RoundTrip(r *http.Request) (*http.Response, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
if len(dnsResult.Addrs) == 0 {
return nil, fmt.Errorf("no address found for matrix host %v", serverName)
}
var resp *http.Response var resp *http.Response
// TODO: respect the priority and weight fields from the SRV record
for _, addr := range dnsResult.Addrs { for _, addr := range dnsResult.Addrs {
u := makeHTTPSURL(r.URL, addr) u := makeHTTPSURL(r.URL, addr)
r.URL = &u r.URL = &u
@ -100,8 +106,12 @@ func (f *federationTripper) RoundTrip(r *http.Request) (*http.Response, error) {
if err == nil { if err == nil {
return resp, nil return resp, nil
} }
util.GetLogger(r.Context()).Warnf("Error sending request to %s: %v",
u.String(), err)
} }
return nil, fmt.Errorf("no address found for matrix host %v", serverName)
// just return the most recent error
return nil, err
} }
// LookupUserInfo gets information about a user from a given matrix homeserver // LookupUserInfo gets information about a user from a given matrix homeserver
@ -253,9 +263,10 @@ func (fc *Client) CreateMediaDownloadRequest(
func (fc *Client) doHTTPRequest(ctx context.Context, req *http.Request) (*http.Response, error) { func (fc *Client) doHTTPRequest(ctx context.Context, req *http.Request) (*http.Response, error) {
reqID := util.RandomString(12) reqID := util.RandomString(12)
logger := util.GetLogger(ctx).WithField("server", req.URL.Host).WithField("out.req.ID", reqID) logger := util.GetLogger(ctx).WithField("server", req.URL.Host).WithField("out.req.ID", reqID)
newCtx := util.ContextWithLogger(ctx, logger)
logger.Infof("Outgoing request %s %s", req.Method, req.URL) logger.Infof("Outgoing request %s %s", req.Method, req.URL)
resp, err := fc.client.Do(req.WithContext(ctx)) resp, err := fc.client.Do(req.WithContext(newCtx))
if err != nil { if err != nil {
logger.Infof("Outgoing request %s %s failed with %v", req.Method, req.URL, err) logger.Infof("Outgoing request %s %s failed with %v", req.Method, req.URL, err)
return nil, err return nil, err

View File

@ -36,6 +36,7 @@ func NewFederationClient(
func (ac *FederationClient) doRequest(ctx context.Context, r FederationRequest, resBody interface{}) error { func (ac *FederationClient) doRequest(ctx context.Context, r FederationRequest, resBody interface{}) error {
reqID := util.RandomString(12) reqID := util.RandomString(12)
logger := util.GetLogger(ctx).WithField("server", r.fields.Destination).WithField("out.req.ID", reqID) logger := util.GetLogger(ctx).WithField("server", r.fields.Destination).WithField("out.req.ID", reqID)
newCtx := util.ContextWithLogger(ctx, logger)
if err := r.Sign(ac.serverName, ac.serverKeyID, ac.serverPrivateKey); err != nil { if err := r.Sign(ac.serverName, ac.serverKeyID, ac.serverPrivateKey); err != nil {
return err return err
@ -47,7 +48,7 @@ func (ac *FederationClient) doRequest(ctx context.Context, r FederationRequest,
} }
logger.Infof("Outgoing request %s %s", req.Method, req.URL) logger.Infof("Outgoing request %s %s", req.Method, req.URL)
res, err := ac.client.Do(req.WithContext(ctx)) res, err := ac.client.Do(req.WithContext(newCtx))
if res != nil { if res != nil {
defer res.Body.Close() // nolint: errcheck defer res.Body.Close() // nolint: errcheck
} }

View File

@ -35,3 +35,8 @@ func GetLogger(ctx context.Context) *log.Entry {
} }
return l.(*log.Entry) return l.(*log.Entry)
} }
// ContextWithLogger creates a new context, which will use the given logger.
func ContextWithLogger(ctx context.Context, l *log.Entry) context.Context {
return context.WithValue(ctx, ctxValueLogger, l)
}

View File

@ -99,7 +99,7 @@ func Protect(handler http.HandlerFunc) http.HandlerFunc {
func RequestWithLogging(req *http.Request) *http.Request { func RequestWithLogging(req *http.Request) *http.Request {
reqID := RandomString(12) reqID := RandomString(12)
// Set a Logger and request ID on the context // Set a Logger and request ID on the context
ctx := context.WithValue(req.Context(), ctxValueLogger, log.WithFields(log.Fields{ ctx := ContextWithLogger(req.Context(), log.WithFields(log.Fields{
"req.method": req.Method, "req.method": req.Method,
"req.path": req.URL.Path, "req.path": req.URL.Path,
"req.id": reqID, "req.id": reqID,