Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge branch 'develop' of github.com:matrix-org/synapse into erikj/st…
Browse files Browse the repository at this point in the history
…ateless_contexts_3
  • Loading branch information
erikjohnston committed Jul 20, 2018
2 parents 311950e + ff48ab8 commit 7350875
Show file tree
Hide file tree
Showing 74 changed files with 3,628 additions and 3,294 deletions.
2,470 changes: 2,470 additions & 0 deletions CHANGES.md

Large diffs are not rendered by default.

2,839 changes: 0 additions & 2,839 deletions CHANGES.rst

This file was deleted.

1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ include synctl
include LICENSE
include VERSION
include *.rst
include *.md
include demo/README
include demo/demo.tls.dh
include demo/*.py
Expand Down
16 changes: 8 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ We'd like to invite you to join #matrix:matrix.org (via
https://matrix.org/docs/projects/try-matrix-now.html), run a homeserver, take a look
at the `Matrix spec <https://matrix.org/docs/spec>`_, and experiment with the
`APIs <https://matrix.org/docs/api>`_ and `Client SDKs
<http://matrix.org/docs/projects/try-matrix-now.html#client-sdks>`_.
<https://matrix.org/docs/projects/try-matrix-now.html#client-sdks>`_.

Thanks for using Matrix!

Expand Down Expand Up @@ -283,7 +283,7 @@ Connecting to Synapse from a client

The easiest way to try out your new Synapse installation is by connecting to it
from a web client. The easiest option is probably the one at
http://riot.im/app. You will need to specify a "Custom server" when you log on
https://riot.im/app. You will need to specify a "Custom server" when you log on
or register: set this to ``https://domain.tld`` if you setup a reverse proxy
following the recommended setup, or ``https://localhost:8448`` - remember to specify the
port (``:8448``) if not ``:443`` unless you changed the configuration. (Leave the identity
Expand Down Expand Up @@ -329,7 +329,7 @@ Security Note
=============

Matrix serves raw user generated data in some APIs - specifically the `content
repository endpoints <http://matrix.org/docs/spec/client_server/latest.html#get-matrix-media-r0-download-servername-mediaid>`_.
repository endpoints <https://matrix.org/docs/spec/client_server/latest.html#get-matrix-media-r0-download-servername-mediaid>`_.

Whilst we have tried to mitigate against possible XSS attacks (e.g.
https://github.com/matrix-org/synapse/pull/1021) we recommend running
Expand All @@ -348,7 +348,7 @@ Platform-Specific Instructions
Debian
------

Matrix provides official Debian packages via apt from http://matrix.org/packages/debian/.
Matrix provides official Debian packages via apt from https://matrix.org/packages/debian/.
Note that these packages do not include a client - choose one from
https://matrix.org/docs/projects/try-matrix-now.html (or build your own with one of our SDKs :)

Expand Down Expand Up @@ -524,7 +524,7 @@ Troubleshooting Running
-----------------------

If synapse fails with ``missing "sodium.h"`` crypto errors, you may need
to manually upgrade PyNaCL, as synapse uses NaCl (http://nacl.cr.yp.to/) for
to manually upgrade PyNaCL, as synapse uses NaCl (https://nacl.cr.yp.to/) for
encryption and digital signatures.
Unfortunately PyNACL currently has a few issues
(https://github.com/pyca/pynacl/issues/53) and
Expand Down Expand Up @@ -672,8 +672,8 @@ useful just for development purposes. See `<demo/README>`_.
Using PostgreSQL
================

As of Synapse 0.9, `PostgreSQL <http://www.postgresql.org>`_ is supported as an
alternative to the `SQLite <http://sqlite.org/>`_ database that Synapse has
As of Synapse 0.9, `PostgreSQL <https://www.postgresql.org>`_ is supported as an
alternative to the `SQLite <https://sqlite.org/>`_ database that Synapse has
traditionally used for convenience and simplicity.

The advantages of Postgres include:
Expand All @@ -697,7 +697,7 @@ Using a reverse proxy with Synapse
It is recommended to put a reverse proxy such as
`nginx <https://nginx.org/en/docs/http/ngx_http_proxy_module.html>`_,
`Apache <https://httpd.apache.org/docs/current/mod/mod_proxy_http.html>`_ or
`HAProxy <http://www.haproxy.org/>`_ in front of Synapse. One advantage of
`HAProxy <https://www.haproxy.org/>`_ in front of Synapse. One advantage of
doing so is that it means that you can expose the default https port (443) to
Matrix clients without needing to run Synapse with root privileges.

Expand Down
1 change: 0 additions & 1 deletion changelog.d/3316.feature

This file was deleted.

1 change: 1 addition & 0 deletions changelog.d/3367.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove unnecessary event re-signing hacks
File renamed without changes.
File renamed without changes.
Empty file removed changelog.d/3464.misc
Empty file.
1 change: 0 additions & 1 deletion changelog.d/3496.feature

This file was deleted.

1 change: 0 additions & 1 deletion changelog.d/3497.feature

This file was deleted.

Empty file removed changelog.d/3498.misc
Empty file.
Empty file removed changelog.d/3499.misc
Empty file.
Empty file removed changelog.d/3501.misc
Empty file.
1 change: 0 additions & 1 deletion changelog.d/3505.feature

This file was deleted.

1 change: 1 addition & 0 deletions changelog.d/3514.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Don't generate TURN credentials if no TURN config options are set
1 change: 0 additions & 1 deletion changelog.d/3521.feature

This file was deleted.

Empty file removed changelog.d/3530.misc
Empty file.
1 change: 0 additions & 1 deletion changelog.d/3533.bugfix

This file was deleted.

1 change: 0 additions & 1 deletion changelog.d/3534.misc

This file was deleted.

Empty file removed changelog.d/3535.misc
Empty file.
1 change: 0 additions & 1 deletion changelog.d/3540.misc

This file was deleted.

1 change: 0 additions & 1 deletion changelog.d/3541.feature

This file was deleted.

Empty file removed changelog.d/3544.misc
Empty file.
1 change: 0 additions & 1 deletion changelog.d/3546.bugfix

This file was deleted.

1 change: 1 addition & 0 deletions changelog.d/3548.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Catch failures saving metrics captured by Measure, and instead log the faulty metrics information for further analysis.
1 change: 1 addition & 0 deletions changelog.d/3552.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Release notes are now in the Markdown format.
1 change: 1 addition & 0 deletions changelog.d/3553.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add metrics to track resource usage by background processes
1 change: 1 addition & 0 deletions changelog.d/3554.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `code` label to `synapse_http_server_response_time_seconds` prometheus metric
1 change: 1 addition & 0 deletions changelog.d/3556.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add metrics to track resource usage by background processes
1 change: 1 addition & 0 deletions changelog.d/3559.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add config for pep8
1 change: 1 addition & 0 deletions changelog.d/3570.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix potential stack overflow and deadlock under heavy load
1 change: 1 addition & 0 deletions changelog.d/3571.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Merge Linearizer and Limiter
1 change: 1 addition & 0 deletions changelog.d/3572.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Merge Linearizer and Limiter
63 changes: 63 additions & 0 deletions docs/admin_api/register_api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
Shared-Secret Registration
==========================

This API allows for the creation of users in an administrative and
non-interactive way. This is generally used for bootstrapping a Synapse
instance with administrator accounts.

To authenticate yourself to the server, you will need both the shared secret
(``registration_shared_secret`` in the homeserver configuration), and a
one-time nonce. If the registration shared secret is not configured, this API
is not enabled.

To fetch the nonce, you need to request one from the API::

> GET /_matrix/client/r0/admin/register

< {"nonce": "thisisanonce"}

Once you have the nonce, you can make a ``POST`` to the same URL with a JSON
body containing the nonce, username, password, whether they are an admin
(optional, False by default), and a HMAC digest of the content.

As an example::

> POST /_matrix/client/r0/admin/register
> {
"nonce": "thisisanonce",
"username": "pepper_roni",
"password": "pizza",
"admin": true,
"mac": "mac_digest_here"
}

< {
"access_token": "token_here",
"user_id": "@pepper_roni@test",
"home_server": "test",
"device_id": "device_id_here"
}

The MAC is the hex digest output of the HMAC-SHA1 algorithm, with the key being
the shared secret and the content being the nonce, user, password, and either
the string "admin" or "notadmin", each separated by NULs. For an example of
generation in Python::

import hmac, hashlib

def generate_mac(nonce, user, password, admin=False):

mac = hmac.new(
key=shared_secret,
digestmod=hashlib.sha1,
)

mac.update(nonce.encode('utf8'))
mac.update(b"\x00")
mac.update(user.encode('utf8'))
mac.update(b"\x00")
mac.update(password.encode('utf8'))
mac.update(b"\x00")
mac.update(b"admin" if admin else b"notadmin")

return mac.hexdigest()
29 changes: 27 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
[tool.towncrier]
package = "synapse"
filename = "CHANGES.rst"
filename = "CHANGES.md"
directory = "changelog.d"
issue_format = "`#{issue} <https://github.com/matrix-org/synapse/issues/{issue}>`_"
issue_format = "[\\#{issue}](https://github.com/matrix-org/synapse/issues/{issue}>)"

[[tool.towncrier.type]]
directory = "feature"
name = "Features"
showcontent = true

[[tool.towncrier.type]]
directory = "bugfix"
name = "Bugfixes"
showcontent = true

[[tool.towncrier.type]]
directory = "doc"
name = "Improved Documentation"
showcontent = true

[[tool.towncrier.type]]
directory = "removal"
name = "Deprecations and Removals"
showcontent = true

[[tool.towncrier.type]]
directory = "misc"
name = "Internal Changes"
showcontent = true
32 changes: 29 additions & 3 deletions scripts/register_new_matrix_user
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,37 @@ import yaml


def request_registration(user, password, server_location, shared_secret, admin=False):
req = urllib2.Request(
"%s/_matrix/client/r0/admin/register" % (server_location,),
headers={'Content-Type': 'application/json'}
)

try:
if sys.version_info[:3] >= (2, 7, 9):
# As of version 2.7.9, urllib2 now checks SSL certs
import ssl
f = urllib2.urlopen(req, context=ssl.SSLContext(ssl.PROTOCOL_SSLv23))
else:
f = urllib2.urlopen(req)
body = f.read()
f.close()
nonce = json.loads(body)["nonce"]
except urllib2.HTTPError as e:
print "ERROR! Received %d %s" % (e.code, e.reason,)
if 400 <= e.code < 500:
if e.info().type == "application/json":
resp = json.load(e)
if "error" in resp:
print resp["error"]
sys.exit(1)

mac = hmac.new(
key=shared_secret,
digestmod=hashlib.sha1,
)

mac.update(nonce)
mac.update("\x00")
mac.update(user)
mac.update("\x00")
mac.update(password)
Expand All @@ -40,10 +66,10 @@ def request_registration(user, password, server_location, shared_secret, admin=F
mac = mac.hexdigest()

data = {
"user": user,
"nonce": nonce,
"username": user,
"password": password,
"mac": mac,
"type": "org.matrix.login.shared_secret",
"admin": admin,
}

Expand All @@ -52,7 +78,7 @@ def request_registration(user, password, server_location, shared_secret, admin=F
print "Sending registration request..."

req = urllib2.Request(
"%s/_matrix/client/api/v1/register" % (server_location,),
"%s/_matrix/client/r0/admin/register" % (server_location,),
data=json.dumps(data),
headers={'Content-Type': 'application/json'}
)
Expand Down
12 changes: 9 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ ignore =
pylint.cfg
tox.ini

[flake8]
[pep8]
max-line-length = 90
# W503 requires that binary operators be at the end, not start, of lines. Erik doesn't like it.
# E203 is contrary to PEP8.
# W503 requires that binary operators be at the end, not start, of lines. Erik
# doesn't like it. E203 is contrary to PEP8.
ignore = W503,E203

[flake8]
# note that flake8 inherits the "ignore" settings from "pep8" (because it uses
# pep8 to do those checks), but not the "max-line-length" setting
max-line-length = 90

[isort]
line_length = 89
not_skip = __init__.py
Expand All @@ -31,3 +36,4 @@ known_compat = mock,six
known_twisted=twisted,OpenSSL
multi_line_output=3
include_trailing_comma=true
combine_as_imports=true
2 changes: 1 addition & 1 deletion synapse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
""" This is a reference implementation of a Matrix home server.
"""

__version__ = "0.32.2"
__version__ = "0.33.0"
4 changes: 2 additions & 2 deletions synapse/config/voip.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ def default_config(self, **kwargs):
## Turn ##
# The public URIs of the TURN server to give to clients
turn_uris: []
#turn_uris: []
# The shared secret used to compute passwords for the TURN server
turn_shared_secret: "YOUR_SHARED_SECRET"
#turn_shared_secret: "YOUR_SHARED_SECRET"
# The Username and password if the TURN server needs them and
# does not use a token
Expand Down
25 changes: 12 additions & 13 deletions synapse/federation/transaction_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
sent_edus_counter,
sent_transactions_counter,
)
from synapse.util import PreserveLoggingContext, logcontext
from synapse.metrics.background_process_metrics import run_as_background_process
from synapse.util import logcontext
from synapse.util.metrics import measure_func
from synapse.util.retryutils import NotRetryingDestination, get_retry_limiter

Expand Down Expand Up @@ -165,10 +166,11 @@ def notify_new_events(self, current_id):
if self._is_processing:
return

# fire off a processing loop in the background. It's likely it will
# outlast the current request, so run it in the sentinel logcontext.
with PreserveLoggingContext():
self._process_event_queue_loop()
# fire off a processing loop in the background
run_as_background_process(
"process_event_queue_for_federation",
self._process_event_queue_loop,
)

@defer.inlineCallbacks
def _process_event_queue_loop(self):
Expand Down Expand Up @@ -432,14 +434,11 @@ def _attempt_new_transaction(self, destination):

logger.debug("TX [%s] Starting transaction loop", destination)

# Drop the logcontext before starting the transaction. It doesn't
# really make sense to log all the outbound transactions against
# whatever path led us to this point: that's pretty arbitrary really.
#
# (this also means we can fire off _perform_transaction without
# yielding)
with logcontext.PreserveLoggingContext():
self._transaction_transmission_loop(destination)
run_as_background_process(
"federation_transaction_transmission_loop",
self._transaction_transmission_loop,
destination,
)

@defer.inlineCallbacks
def _transaction_transmission_loop(self, destination):
Expand Down
Loading

0 comments on commit 7350875

Please sign in to comment.