|
16 | 16 | from typing import TYPE_CHECKING, Tuple |
17 | 17 |
|
18 | 18 | from synapse.api.errors import Codes, NotFoundError, SynapseError |
| 19 | +from synapse.federation.transport.server import Authenticator |
19 | 20 | from synapse.http.servlet import RestServlet, parse_integer, parse_string |
20 | 21 | from synapse.http.site import SynapseRequest |
21 | 22 | from synapse.rest.admin._base import admin_patterns, assert_requester_is_admin |
@@ -90,7 +91,7 @@ async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]: |
90 | 91 | return HTTPStatus.OK, response |
91 | 92 |
|
92 | 93 |
|
93 | | -class DestinationsRestServlet(RestServlet): |
| 94 | +class DestinationRestServlet(RestServlet): |
94 | 95 | """Get details of a destination. |
95 | 96 | This needs user to have administrator access in Synapse. |
96 | 97 |
|
@@ -145,3 +146,44 @@ async def on_GET( |
145 | 146 | } |
146 | 147 |
|
147 | 148 | return HTTPStatus.OK, response |
| 149 | + |
| 150 | + |
| 151 | +class DestinationResetConnectionRestServlet(RestServlet): |
| 152 | + """Reset destinations' connection timeouts and wake it up. |
| 153 | + This needs user to have administrator access in Synapse. |
| 154 | +
|
| 155 | + POST /_synapse/admin/v1/federation/destinations/<destination>/reset_connection |
| 156 | + {} |
| 157 | +
|
| 158 | + returns: |
| 159 | + 200 OK otherwise an error. |
| 160 | + """ |
| 161 | + |
| 162 | + PATTERNS = admin_patterns( |
| 163 | + "/federation/destinations/(?P<destination>[^/]+)/reset_connection$" |
| 164 | + ) |
| 165 | + |
| 166 | + def __init__(self, hs: "HomeServer"): |
| 167 | + self._auth = hs.get_auth() |
| 168 | + self._store = hs.get_datastore() |
| 169 | + self._authenticator = Authenticator(hs) |
| 170 | + |
| 171 | + async def on_POST( |
| 172 | + self, request: SynapseRequest, destination: str |
| 173 | + ) -> Tuple[int, JsonDict]: |
| 174 | + await assert_requester_is_admin(self._auth, request) |
| 175 | + |
| 176 | + if not await self._store.is_destination_known(destination): |
| 177 | + raise NotFoundError("Unknown destination") |
| 178 | + |
| 179 | + retry_timings = await self._store.get_destination_retry_timings(destination) |
| 180 | + if not (retry_timings and retry_timings.retry_last_ts): |
| 181 | + raise SynapseError( |
| 182 | + HTTPStatus.BAD_REQUEST, |
| 183 | + "The retry timing does not need to be reset for this destination.", |
| 184 | + ) |
| 185 | + |
| 186 | + # reset timings and wake up |
| 187 | + await self._authenticator.reset_retry_timings(destination) |
| 188 | + |
| 189 | + return HTTPStatus.OK, {} |
0 commit comments