Richard van der Hoff
5bdb189f86
Improve docstrings on MatrixFederationClient. ( #5332 )
2019-06-04 11:14:16 +01:00
Richard van der Hoff
8d92329214
Remove spurious debug from MatrixFederationHttpClient.get_json ( #5287 )
...
This is just unhelpful spam
2019-05-29 19:31:52 +01:00
Aaron Raimist
2d4853039f
Fix error code for invalid parameter
...
Signed-off-by: Aaron Raimist <aaron@raim.ist>
2019-05-24 17:13:16 -05:00
Andrew Morgan
5a4b328f52
Add ability to blacklist ip ranges for federation traffic ( #5043 )
2019-05-13 19:05:06 +01:00
Andrew Morgan
2f48c4e1ae
URL preview blacklisting fixes ( #5155 )
...
Prevents a SynapseError being raised inside of a IResolutionReceiver and instead opts to just return 0 results. This thus means that we have to lump a failed lookup and a blacklisted lookup together with the same error message, but the substitute should be generic enough to cover both cases.
2019-05-10 10:32:44 -07:00
Andrew Morgan
6824ddd93d
Config option for verifying federation certificates (MSC 1711) ( #4967 )
2019-04-25 14:22:49 +01:00
Andrew Morgan
4a125be138
Make federation endpoints more tolerant of trailing slashes v2 ( #4935 )
...
Redo of https://github.com/matrix-org/synapse/pull/4840
2019-03-26 11:35:29 +00:00
Andrew Morgan
b41c2eaadc
Clean up backoff_on_404 and metehod calls
2019-03-21 14:32:47 +00:00
Andrew Morgan
2150151abe
kwargs doesn't like commas on calling funcs either. TIL
2019-03-20 14:13:32 +00:00
Andrew Morgan
bb52a2e653
lint
2019-03-20 14:08:57 +00:00
Andrew Morgan
cd36a1283b
New test, fix issues
2019-03-20 14:00:39 +00:00
Andrew Morgan
c69df5d5d3
Fix comments. v0.99.2 -> v0.99.3
2019-03-20 11:27:18 +00:00
Andrew Morgan
551ea11559
Just return if not doing any trailing slash shennanigans
2019-03-20 11:07:36 +00:00
Andrew Morgan
a8ad39eec7
lint
2019-03-18 17:47:39 +00:00
Andrew Morgan
621e7f37f1
Better exception handling
2019-03-18 17:45:54 +00:00
Andrew Morgan
ecea5af491
Correct var name
2019-03-13 21:21:03 +00:00
Andrew Morgan
b2df0e8e2c
receiving a 400 caused an exception. handle it
2019-03-13 21:08:10 +00:00
Andrew Morgan
9a2e22fd41
is this what purgatory feels like
2019-03-13 20:29:38 +00:00
Andrew Morgan
45524f2f5e
i should have given up x2
2019-03-13 20:17:39 +00:00
Andrew Morgan
8d16ffaf7a
i should have given up
2019-03-13 20:03:10 +00:00
Andrew Morgan
26f8e2d099
there comes a time when you should give up. but you dont
2019-03-13 19:49:08 +00:00
Andrew Morgan
5ca857ad84
as above
2019-03-13 19:35:23 +00:00
Andrew Morgan
7c0295f13c
no kwargs today
2019-03-13 19:27:10 +00:00
Andrew Morgan
66cdb840a6
Or perhaps I was the one who was drunk
2019-03-13 19:18:25 +00:00
Andrew Morgan
bec313818c
go home python, you're drunk
2019-03-13 19:10:56 +00:00
Andrew Morgan
c991e7aec7
Syntax checker is bork
2019-03-13 19:08:08 +00:00
Andrew Morgan
c2d848b80d
Destructure again
2019-03-13 19:04:43 +00:00
Andrew Morgan
ee8ba397e8
Are you happy now
2019-03-13 18:48:31 +00:00
Andrew Morgan
9dd0e34679
Syntax test
2019-03-13 18:45:17 +00:00
Andrew Morgan
220607a618
Remove testing code
2019-03-13 18:43:40 +00:00
Andrew Morgan
660b77f362
Add missing docstring detail
2019-03-13 18:38:16 +00:00
Andrew Morgan
5526b054aa
Fix syntax issues
2019-03-13 18:35:21 +00:00
Andrew Morgan
09626bfd39
Switch to wrapper function around _send_request
2019-03-13 18:26:06 +00:00
Andrew Morgan
7d053cfe10
Retry on 400:M_UNRECOGNIZED
2019-03-13 12:10:33 +00:00
Andrew Morgan
7e75d9644b
Fix paranthesis indent
2019-03-13 11:15:23 +00:00
Andrew Morgan
cf301e37d8
Add workaround note
2019-03-13 11:14:43 +00:00
Andrew Morgan
0ea8582f8b
Cleaner way of implementing trailing slashes
2019-03-12 14:11:11 +00:00
Andrew Morgan
64ff11019e
Retry certain federation requests on 404
2019-03-08 18:22:47 +00:00
Andrew Morgan
ac61b45a75
Minor docstring fixes for MatrixFederationAgent ( #4765 )
2019-02-28 16:24:01 +00:00
Erik Johnston
c7b333c545
Log tracebacks correctly
2019-02-25 16:56:41 +00:00
Richard van der Hoff
c88bc53903
Fix TaskStopped exceptions when outbound requests time out ( #4690 )
2019-02-20 11:35:52 +00:00
Erik Johnston
fe725f7e45
Cleanup top level request exception logging
...
Firstly, we always logged that the request was being handled via
`JsonResource._async_render`, so we change that to use the servlet name
we add to the request.
Secondly, we pass the exception information to the logger rather than
formatting it manually. This makes it consistent with other exception
logging, allwoing logging hooks and formatters to access the exception
information.
2019-02-18 15:11:04 +00:00
Richard van der Hoff
5d27730a73
Move ClientTLSOptionsFactory init out of refresh_certificates ( #4611 )
...
It's nothing to do with refreshing the certificates. No idea why it was here.
2019-02-11 18:03:30 +00:00
Richard van der Hoff
ef43a03fc5
Merge pull request #4546 from matrix-org/rav/silence_critical_error_from_federation
...
Fix noisy "twisted.internet.task.TaskStopped" errors in logs
2019-02-01 14:37:22 +00:00
Richard van der Hoff
fa794980ec
Merge pull request #4544 from matrix-org/rav/skip_invalid_well_known
...
Treat an invalid .well-known the same as an absent one
2019-02-01 13:18:36 +00:00
Richard van der Hoff
e9779a6f8f
Fix b'ab' noise in logs
2019-02-01 12:34:31 +00:00
Richard van der Hoff
f0ba34f581
Fix noisy "twisted.internet.task.TaskStopped" errors in logs
...
Fixes #4003
2019-02-01 12:22:57 +00:00
Richard van der Hoff
8a21b03fba
Treat an invalid .well-known the same as an absent one
...
... basically, carry on and fall back to SRV etc.
2019-02-01 11:37:31 +00:00
Richard van der Hoff
3c8a41140e
Cache failures to parse .well-known
...
Also add a Measure block around the .well-known fetch
2019-02-01 00:37:52 +00:00
Richard van der Hoff
24d59c7568
better logging for federation connections
2019-01-31 23:18:20 +00:00
Richard van der Hoff
d428b46346
Update federation routing logic to check .well-known before SRV
2019-01-31 23:14:18 +00:00
Richard van der Hoff
a79034aedf
Merge pull request #4521 from matrix-org/rav/fed_routing/cleanups
...
Tiny .well-known fixes
2019-01-30 11:47:24 +00:00
Richard van der Hoff
c7b24ac3d0
Follow redirects on .well-known ( #4520 )
2019-01-30 11:43:33 +00:00
Richard van der Hoff
09a1a6b55e
fix exception text
2019-01-30 10:58:52 +00:00
Richard van der Hoff
928c50b59a
Also jitter the invalid cache period
2019-01-30 10:58:52 +00:00
Richard van der Hoff
bc5f6e1797
Add a caching layer to .well-known responses ( #4516 )
2019-01-30 10:55:25 +00:00
Richard van der Hoff
cc2d650ef7
Relax requirement for a content-type on .well-known ( #4511 )
2019-01-29 16:49:17 +00:00
Richard van der Hoff
99e36d5e24
Implement MSC1708 (.well-known lookups for server routing) ( #4489 )
2019-01-29 13:53:02 +00:00
Richard van der Hoff
3bd0f1a4a3
docstrings for _RoutingResult
2019-01-28 12:43:09 +00:00
Richard van der Hoff
0fd5b3b53e
Handle IP literals explicitly
...
We don't want to be doing .well-known lookups on these guys.
2019-01-28 10:34:30 +00:00
Richard van der Hoff
51958df766
MatrixFederationAgent: factor out routing logic
...
This is going to get too big and unmanageable.
2019-01-28 10:34:30 +00:00
Richard van der Hoff
d840019192
Fix idna and ipv6 literal handling in MatrixFederationAgent ( #4487 )
...
Turns out that the library does a better job of parsing URIs than our
reinvented wheel. Who knew.
There are two things going on here. The first is that, unlike
parse_server_name, URI.fromBytes will strip off square brackets from IPv6
literals, which means that it is valid input to ClientTLSOptionsFactory and
HostnameEndpoint.
The second is that we stay in `bytes` throughout (except for the argument to
ClientTLSOptionsFactory), which avoids the weirdness of (sometimes) ending up
with idna-encoded values being held in `unicode` variables. TBH it probably
would have been ok but it made the tests fragile.
2019-01-28 09:56:59 +00:00
Richard van der Hoff
8520bc3109
Fix Host header sent by MatrixFederationAgent ( #4468 )
...
Move the Host header logic down here so that (a) it is used if we reuse the
agent elsewhere, and (b) we can mess about with it with .well-known.
2019-01-25 12:38:16 +00:00
Richard van der Hoff
4a6e863843
Merge pull request #4464 from matrix-org/rav/fix_srv_lookup
...
MatrixFederationAgent: Look up the right SRV record
2019-01-24 13:57:51 +00:00
Richard van der Hoff
f4697b5ec1
Fix UnboundLocalError in post_urlencoded_get_json ( #4460 )
...
This could cause exceptions if the id server returned 4xx responses.
2019-01-24 13:38:29 +00:00
Richard van der Hoff
afd69a0920
Look up the right SRV record
2019-01-24 13:31:43 +00:00
Richard van der Hoff
7021784d46
put resolve_service in an object
...
this makes it easier to stub things out for tests.
2019-01-22 20:35:12 +00:00
Richard van der Hoff
53a327b4d5
Require that service_name be a byte string
...
it is only ever a bytes now, so let's enforce that.
2019-01-22 20:35:12 +00:00
Richard van der Hoff
fe212bbe4a
Kill off matrix_federation_endpoint
...
this thing is now redundant.
2019-01-22 20:34:35 +00:00
Richard van der Hoff
7871146667
Make MatrixFederationClient use MatrixFederationAgent
...
... instead of the matrix_federation_endpoint
2019-01-22 20:34:35 +00:00
Richard van der Hoff
44be7513bf
MatrixFederationAgent
...
Pull the magic that is currently in matrix_federation_endpoint and friends into
an agent-like thing
2019-01-22 20:34:35 +00:00
Richard van der Hoff
33a55289cb
Refactor and bugfix for resove_service ( #4427 )
2019-01-22 10:59:27 +00:00
Richard van der Hoff
de6888e7ce
Remove redundant WrappedConnection ( #4409 )
...
* Remove redundant WrappedConnection
The matrix federation client uses an HTTP connection pool, which times out its
idle HTTP connections, so there is no need for any of this business.
2019-01-18 23:07:38 +11:00
Richard van der Hoff
9feb5d0b71
sign_request -> build_auth_headers ( #4408 )
...
Just got very confused about the fact that the headers are only an output, not
an input.
2019-01-17 12:40:09 +00:00
Erik Johnston
34ea14139d
Fixup docstrings for matrixfederationclient
2019-01-09 09:25:59 +00:00
Erik Johnston
d422570e9b
Use RequestSendFailed when fail to parse content type headers
2019-01-08 14:22:18 +00:00
Erik Johnston
b970cb0e96
Refactor request sending to have better excpetions ( #4358 )
...
* Correctly retry and back off if we get a HTTPerror response
* Refactor request sending to have better excpetions
MatrixFederationHttpClient blindly reraised exceptions to the caller
without differentiating "expected" failures (e.g. connection timeouts
etc) versus more severe problems (e.g. programming errors).
This commit adds a RequestSendFailed exception that is raised when
"expected" failures happen, allowing the TransactionQueue to log them as
warnings while allowing us to log other exceptions as actual exceptions.
2019-01-08 11:04:28 +00:00
Amber Brown
ea6abf6724
Fix IP URL previews on Python 3 ( #4215 )
2018-12-22 01:56:13 +11:00
Richard van der Hoff
0a1fc52971
fix parse_string docstring
2018-11-08 11:12:29 +00:00
Amber Brown
b3708830b8
Fix URL preview bugs (type error when loading cache from db, content-type including quotes) ( #4157 )
2018-11-08 01:37:43 +11:00
Travis Ralston
43c3f0b02f
Merge pull request #3969 from turt2live/travis/fix-federated-group-requests
...
Handle HttpResponseException more safely for federated groups
2018-10-23 10:41:04 -06:00
Amber Brown
b69216f768
Make the metrics less racy ( #4061 )
2018-10-19 21:45:45 +11:00
Richard van der Hoff
b8a5b0097c
Various cleanups in the federation client code ( #4031 )
...
- Improve logging: log things in the right order, include destination and txids
in all log lines, don't log successful responses twice
- Fix the docstring on TransportLayerClient.send_transaction
- Don't use treq.request, which is overcomplicated for our purposes: just use a
twisted.web.client.Agent.
- simplify the logic for setting up the bodyProducer
- fix bytes/str confusions
2018-10-16 10:44:49 +01:00
Travis Ralston
e3586f7c06
Merge branch 'develop' into travis/fix-federated-group-requests
2018-10-12 14:49:58 -06:00
Erik Johnston
334e075dd8
Fix error when logging incomplete requests
...
If a connection is lost before a request is read from Request, Twisted
sets `method` (and `uri`) attributes to dummy values. These dummy values
have incorrect types (i.e. they're not bytes), and so things like
`__repr__` would raise an exception.
To fix this we had a helper method to return the method with a
consistent type.
2018-10-02 12:06:22 +01:00
Travis Ralston
219606a6ed
Fix exception documentation in matrixfederationclient.py
2018-09-26 13:26:27 -06:00
Richard van der Hoff
94f7befc31
Merge pull request #3925 from matrix-org/erikj/fix_producers_unregistered
...
Fix spurious exceptions when client closes conncetion
2018-09-25 11:52:06 +01:00
Erik Johnston
b28a7ed503
Fix spurious exceptions when client closes conncetion
...
If a HTTP handler throws an exception while processing a request we
automatically write a JSON error response. If the handler had already
started writing a response twisted throws an exception.
We should check for this case and simple abort the connection if there
was an error after the response had started being written.
2018-09-20 13:44:20 +01:00
Amber Brown
1f3f5fcf52
Fix client IPs being broken on Python 3 ( #3908 )
2018-09-20 20:14:34 +10:00
Amber Brown
aeca5a5ed5
Add a regression test for logging on failed connections ( #3912 )
2018-09-20 16:28:18 +10:00
Erik Johnston
a334e1cace
Update to use new timeout function everywhere.
...
The existing deferred timeout helper function (and the one into twisted)
suffer from a bug when a deferred's canceller throws an exception, #3842 .
The new helper function doesn't suffer from this problem.
2018-09-19 10:39:40 +01:00
Amber Brown
47c02e6332
Merge pull request #3909 from turt2live/travis/fix-logging-1
...
Fix matrixfederationclient.py logging: Destination is a string
2018-09-19 18:14:47 +10:00
Amber Brown
3d6b24fb1b
Merge pull request #3907 from matrix-org/rav/set_sni_to_server_name
...
Set SNI to the server_name, not whatever was in the SRV record
2018-09-19 17:59:33 +10:00
Travis Ralston
35aec19f0a
Destination is a string
2018-09-18 15:29:30 -06:00
Richard van der Hoff
31c15dcb80
Refactor matrixfederationclient to fix logging ( #3906 )
...
We want to wait until we have read the response body before we log the request
as complete, otherwise a confusing thing happens where the request appears to
have completed, but we later fail it.
To do this, we factor the salient details of a request out to a separate
object, which can then keep track of the txn_id, so that it can be logged.
2018-09-18 18:17:15 +01:00
Richard van der Hoff
b3097396e7
Set SNI to the server_name, not whatever was in the SRV record
...
Fixes #3843
2018-09-18 17:01:12 +01:00
Richard van der Hoff
ac80cb08fe
Fix more b'abcd' noise in metrics
2018-09-17 17:16:50 +01:00
Richard van der Hoff
f00a9d2636
Fix some b'abcd' noise in logs and metrics
...
Python 3 compatibility: make sure that we decode some byte sequences before we
use them to create log lines and metrics labels.
2018-09-17 16:15:42 +01:00
Erik Johnston
fcfe7a850d
Add an awful secondary timeout to fix wedged requests
...
This is an attempt to mitigate #3842 by adding yet-another-timeout
2018-09-14 19:23:07 +01:00
Erik Johnston
3e6e94fe9f
Merge pull request #3872 from matrix-org/hawkowl/timeouts-2
...
timeouts 2: electric boogaloo
2018-09-14 16:58:44 +01:00