Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Implement username availability checker #2183

Merged
merged 2 commits into from May 4, 2017

Conversation

Projects
None yet
2 participants
Contributor

lukebarnard1 commented May 3, 2017 edited

Outlined here: vector-im/riot-web#3605 (comment)

UPDATE: This API should have always been a POST API, I've updated the below to reflect that. (#2209)
ANOTHER UPDATE: @richvdh thinks (and I agree) that this should've been a GET with a query parameter all along! - #2213.

GET /_matrix/.../register/available?username=desiredlocalpart123

If available, the response looks like

HTTP/1.1 200 OK
{
    "available": true
}

Otherwise,

HTTP/1.1 429
{
    "errcode": "M_LIMIT_EXCEEDED",
    "error": "Too Many Requests",
    "retry_after_ms": 2000
}

or

HTTP/1.1 400
{
    "errcode": "M_USER_IN_USE",
    "error": "User ID already taken."
}

or

HTTP/1.1 400
{
    "errcode": "M_INVALID_USERNAME",
    "error": "Some reason for username being invalid"
}
Implement username availability checker
Outlined here: vector-im/riot-web#3605 (comment)

```HTTP
GET /_matrix/.../register/available
{
    "username": "desiredlocalpart123"
}
```

If available, the response looks like
```HTTP
HTTP/1.1 200 OK
{
    "available": true
}
```

Otherwise,
```HTTP
HTTP/1.1 429
{
    "errcode": "M_LIMIT_EXCEEDED",
    "error": "Too Many Requests",
    "retry_after_ms": 2000
}
```
or
```HTTP
HTTP/1.1 400
{
    "errcode": "M_USER_IN_USE",
    "error": "User ID already taken."
}

```
or
```HTTP
HTTP/1.1 400
{
    "errcode": "M_INVALID_USERNAME",
    "error": "Some reason for username being invalid"
}
```
synapse/rest/client/v2_alpha/register.py
+ self.ratelimiter = FederationRateLimiter(
+ hs.get_clock(),
+ window_size=2000, # Time window of 2s
+ sleep_limit=1, # Artificially delay requests if rate > sleep_limit/window_size
@erikjohnston

erikjohnston May 3, 2017

Owner

True here surely?

@lukebarnard1

lukebarnard1 May 3, 2017 edited

Contributor

Er, the docs say,
sleep_limit (int): The number of requests received...

synapse/rest/client/v2_alpha/register.py
+ sleep_limit=1, # Artificially delay requests if rate > sleep_limit/window_size
+ sleep_msec=1000, # Amount of artificial delay to apply
+ reject_limit=1, # Error with 429 if more than reject_limit requests are queued
+ concurrent_requests=1, # Allow 1 request at a time
Owner

erikjohnston commented May 3, 2017

$ flake8 synapse tests
synapse/rest/client/v2_alpha/register.py:132:30: E261 at least two spaces before inline comment
synapse/rest/client/v2_alpha/register.py:133:27: E261 at least two spaces before inline comment
synapse/rest/client/v2_alpha/register.py:134:29: E261 at least two spaces before inline comment
synapse/rest/client/v2_alpha/register.py:135:28: E261 at least two spaces before inline comment
synapse/rest/client/v2_alpha/register.py:136:35: E261 at least two spaces before inline comment

Lgtm

@lukebarnard1 lukebarnard1 merged commit 6aa423a into develop May 4, 2017

8 checks passed

Sytest Dendron (Commit) Build #2063 origin/luke/username-availability succeeded in 7 min 54 sec
Details
Sytest Dendron (Merged PR) Build finished.
Details
Sytest Postgres (Commit) Build #2896 origin/luke/username-availability succeeded in 9 min 13 sec
Details
Sytest Postgres (Merged PR) Build finished.
Details
Sytest SQLite (Commit) Build #2964 origin/luke/username-availability succeeded in 5 min 27 sec
Details
Sytest SQLite (Merged PR) Build finished.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

lukebarnard1 added a commit to matrix-org/matrix-js-sdk that referenced this pull request May 10, 2017

@lukebarnard1 lukebarnard1 referenced this pull request in matrix-org/matrix-js-sdk May 10, 2017

Merged

Implement API for username availability #432

lukebarnard1 added a commit to matrix-org/matrix-js-sdk that referenced this pull request May 11, 2017

psaavedra added a commit to psaavedra/synapse that referenced this pull request May 19, 2017

Merge tag 'v0.21.0' into v0.21.0_no_federate_by_default
Changes in synapse v0.21.0 (2017-05-18)
=======================================

No changes since v0.21.0-rc3

Changes in synapse v0.21.0-rc3 (2017-05-17)
===========================================

Features:

* Add per user rate-limiting overrides (PR #2208)
* Add config option to limit maximum number of events requested by ``/sync``
  and ``/messages`` (PR #2221) Thanks to @psaavedra!

Changes:

* Various small performance fixes (PR #2201, #2202, #2224, #2226, #2227, #2228,
  #2229)
* Update username availability checker API (PR #2209, #2213)
* When purging, don't de-delta state groups we're about to delete (PR #2214)
* Documentation to check synapse version (PR #2215) Thanks to @hamber-dick!
* Add an index to event_search to speed up purge history API (PR #2218)

Bug fixes:

* Fix API to allow clients to upload one-time-keys with new sigs (PR #2206)

Changes in synapse v0.21.0-rc2 (2017-05-08)
===========================================

Changes:

* Always mark remotes as up if we receive a signed request from them (PR #2190)

Bug fixes:

* Fix bug where users got pushed for rooms they had muted (PR #2200)

Changes in synapse v0.21.0-rc1 (2017-05-08)
===========================================

Features:

* Add username availability checker API (PR #2183)
* Add read marker API (PR #2120)

Changes:

* Enable guest access for the 3pl/3pid APIs (PR #1986)
* Add setting to support TURN for guests (PR #2011)
* Various performance improvements (PR #2075, #2076, #2080, #2083, #2108,
  #2158, #2176, #2185)
* Make synctl a bit more user friendly (PR #2078, #2127) Thanks @APwhitehat!
* Replace HTTP replication with TCP replication (PR #2082, #2097, #2098,
  #2099, #2103, #2014, #2016, #2115, #2116, #2117)
* Support authenticated SMTP (PR #2102) Thanks @DanielDent!
* Add a counter metric for successfully-sent transactions (PR #2121)
* Propagate errors sensibly from proxied IS requests (PR #2147)
* Add more granular event send metrics (PR #2178)

Bug fixes:

* Fix nuke-room script to work with current schema (PR #1927) Thanks
  @zuckschwerdt!
* Fix db port script to not assume postgres tables are in the public schema
  (PR #2024) Thanks @jerrykan!
* Fix getting latest device IP for user with no devices (PR #2118)
* Fix rejection of invites to unreachable servers (PR #2145)
* Fix code for reporting old verify keys in synapse (PR #2156)
* Fix invite state to always include all events (PR #2163)
* Fix bug where synapse would always fetch state for any missing event (PR #2170)
* Fix a leak with timed out HTTP connections (PR #2180)
* Fix bug where we didn't time out HTTP requests to ASes  (PR #2192)

Docs:

* Clarify doc for SQLite to PostgreSQL port (PR #1961) Thanks @benhylau!
* Fix typo in synctl help (PR #2107) Thanks @HarHarLinks!
* ``web_client_location`` documentation fix (PR #2131) Thanks @matthewjwolff!
* Update README.rst with FreeBSD changes (PR #2132) Thanks @feld!
* Clarify setting up metrics (PR #2149) Thanks @encks!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment