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

Commit 6d1dea3

Browse files
committed
Merge branch 'release-v0.9.1' of github.com:matrix-org/synapse
2 parents ee49098 + 6cb3212 commit 6d1dea3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2527
-1280
lines changed

CHANGES.rst

+27
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
Changes in synapse v0.9.1 (2015-05-26)
2+
======================================
3+
4+
General:
5+
6+
* Add support for backfilling when a client paginates. This allows servers to
7+
request history for a room from remote servers when a client tries to
8+
paginate history the server does not have - SYN-36
9+
* Fix bug where you couldn't disable non-default pushrules - SYN-378
10+
* Fix ``register_new_user`` script - SYN-359
11+
* Improve performance of fetching events from the database, this improves both
12+
initialSync and sending of events.
13+
* Improve performance of event streams, allowing synapse to handle more
14+
simultaneous connected clients.
15+
16+
Federation:
17+
18+
* Fix bug with existing backfill implementation where it returned the wrong
19+
selection of events in some circumstances.
20+
* Improve performance of joining remote rooms.
21+
22+
Configuration:
23+
24+
* Add support for changing the bind host of the metrics listener via the
25+
``metrics_bind_host`` option.
26+
27+
128
Changes in synapse v0.9.0-r5 (2015-05-21)
229
=========================================
330

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Installing prerequisites on Mac OS X::
117117
118118
To install the synapse homeserver run::
119119

120-
$ virtualenv ~/.synapse
120+
$ virtualenv -p python2.7 ~/.synapse
121121
$ source ~/.synapse/bin/activate
122122
$ pip install --process-dependency-links https://github.com/matrix-org/synapse/tarball/master
123123

demo/start.sh

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ for port in 8080 8081 8082; do
3131
#rm $DIR/etc/$port.config
3232
python -m synapse.app.homeserver \
3333
--generate-config \
34+
--enable_registration \
3435
-H "localhost:$https_port" \
3536
--config-path "$DIR/etc/$port.config" \
3637

scripts-dev/convert_server_keys.py

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import psycopg2
2+
import yaml
3+
import sys
4+
import json
5+
import time
6+
import hashlib
7+
from syutil.base64util import encode_base64
8+
from syutil.crypto.signing_key import read_signing_keys
9+
from syutil.crypto.jsonsign import sign_json
10+
from syutil.jsonutil import encode_canonical_json
11+
12+
13+
def select_v1_keys(connection):
14+
cursor = connection.cursor()
15+
cursor.execute("SELECT server_name, key_id, verify_key FROM server_signature_keys")
16+
rows = cursor.fetchall()
17+
cursor.close()
18+
results = {}
19+
for server_name, key_id, verify_key in rows:
20+
results.setdefault(server_name, {})[key_id] = encode_base64(verify_key)
21+
return results
22+
23+
24+
def select_v1_certs(connection):
25+
cursor = connection.cursor()
26+
cursor.execute("SELECT server_name, tls_certificate FROM server_tls_certificates")
27+
rows = cursor.fetchall()
28+
cursor.close()
29+
results = {}
30+
for server_name, tls_certificate in rows:
31+
results[server_name] = tls_certificate
32+
return results
33+
34+
35+
def select_v2_json(connection):
36+
cursor = connection.cursor()
37+
cursor.execute("SELECT server_name, key_id, key_json FROM server_keys_json")
38+
rows = cursor.fetchall()
39+
cursor.close()
40+
results = {}
41+
for server_name, key_id, key_json in rows:
42+
results.setdefault(server_name, {})[key_id] = json.loads(str(key_json).decode("utf-8"))
43+
return results
44+
45+
46+
def convert_v1_to_v2(server_name, valid_until, keys, certificate):
47+
return {
48+
"old_verify_keys": {},
49+
"server_name": server_name,
50+
"verify_keys": {
51+
key_id: {"key": key}
52+
for key_id, key in keys.items()
53+
},
54+
"valid_until_ts": valid_until,
55+
"tls_fingerprints": [fingerprint(certificate)],
56+
}
57+
58+
59+
def fingerprint(certificate):
60+
finger = hashlib.sha256(certificate)
61+
return {"sha256": encode_base64(finger.digest())}
62+
63+
64+
def rows_v2(server, json):
65+
valid_until = json["valid_until_ts"]
66+
key_json = encode_canonical_json(json)
67+
for key_id in json["verify_keys"]:
68+
yield (server, key_id, "-", valid_until, valid_until, buffer(key_json))
69+
70+
71+
def main():
72+
config = yaml.load(open(sys.argv[1]))
73+
valid_until = int(time.time() / (3600 * 24)) * 1000 * 3600 * 24
74+
75+
server_name = config["server_name"]
76+
signing_key = read_signing_keys(open(config["signing_key_path"]))[0]
77+
78+
database = config["database"]
79+
assert database["name"] == "psycopg2", "Can only convert for postgresql"
80+
args = database["args"]
81+
args.pop("cp_max")
82+
args.pop("cp_min")
83+
connection = psycopg2.connect(**args)
84+
keys = select_v1_keys(connection)
85+
certificates = select_v1_certs(connection)
86+
json = select_v2_json(connection)
87+
88+
result = {}
89+
for server in keys:
90+
if not server in json:
91+
v2_json = convert_v1_to_v2(
92+
server, valid_until, keys[server], certificates[server]
93+
)
94+
v2_json = sign_json(v2_json, server_name, signing_key)
95+
result[server] = v2_json
96+
97+
yaml.safe_dump(result, sys.stdout, default_flow_style=False)
98+
99+
rows = list(
100+
row for server, json in result.items()
101+
for row in rows_v2(server, json)
102+
)
103+
104+
cursor = connection.cursor()
105+
cursor.executemany(
106+
"INSERT INTO server_keys_json ("
107+
" server_name, key_id, from_server,"
108+
" ts_added_ms, ts_valid_until_ms, key_json"
109+
") VALUES (%s, %s, %s, %s, %s, %s)",
110+
rows
111+
)
112+
connection.commit()
113+
114+
115+
if __name__ == '__main__':
116+
main()

scripts/register_new_matrix_user

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,18 @@ def request_registration(user, password, server_location, shared_secret):
3333
).hexdigest()
3434

3535
data = {
36-
"username": user,
36+
"user": user,
3737
"password": password,
3838
"mac": mac,
39+
"type": "org.matrix.login.shared_secret",
3940
}
4041

4142
server_location = server_location.rstrip("/")
4243

4344
print "Sending registration request..."
4445

4546
req = urllib2.Request(
46-
"%s/_matrix/client/v2_alpha/register" % (server_location,),
47+
"%s/_matrix/client/api/v1/register" % (server_location,),
4748
data=json.dumps(data),
4849
headers={'Content-Type': 'application/json'}
4950
)

synapse/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
""" This is a reference implementation of a Matrix home server.
1717
"""
1818

19-
__version__ = "0.9.0-r5"
19+
__version__ = "0.9.1"

synapse/app/homeserver.py

+26-6
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
from twisted.internet import reactor
3333
from twisted.application import service
3434
from twisted.enterprise import adbapi
35-
from twisted.web.resource import Resource
35+
from twisted.web.resource import Resource, EncodingResourceWrapper
3636
from twisted.web.static import File
37-
from twisted.web.server import Site
37+
from twisted.web.server import Site, GzipEncoderFactory
3838
from twisted.web.http import proxiedLogFormatter, combinedLogFormatter
3939
from synapse.http.server import JsonResource, RootRedirect
4040
from synapse.rest.media.v0.content_repository import ContentRepoResource
@@ -69,16 +69,26 @@
6969
logger = logging.getLogger("synapse.app.homeserver")
7070

7171

72+
class GzipFile(File):
73+
def getChild(self, path, request):
74+
child = File.getChild(self, path, request)
75+
return EncodingResourceWrapper(child, [GzipEncoderFactory()])
76+
77+
78+
def gz_wrap(r):
79+
return EncodingResourceWrapper(r, [GzipEncoderFactory()])
80+
81+
7282
class SynapseHomeServer(HomeServer):
7383

7484
def build_http_client(self):
7585
return MatrixFederationHttpClient(self)
7686

7787
def build_resource_for_client(self):
78-
return ClientV1RestResource(self)
88+
return gz_wrap(ClientV1RestResource(self))
7989

8090
def build_resource_for_client_v2_alpha(self):
81-
return ClientV2AlphaRestResource(self)
91+
return gz_wrap(ClientV2AlphaRestResource(self))
8292

8393
def build_resource_for_federation(self):
8494
return JsonResource(self)
@@ -87,9 +97,16 @@ def build_resource_for_web_client(self):
8797
import syweb
8898
syweb_path = os.path.dirname(syweb.__file__)
8999
webclient_path = os.path.join(syweb_path, "webclient")
100+
# GZip is disabled here due to
101+
# https://twistedmatrix.com/trac/ticket/7678
102+
# (It can stay enabled for the API resources: they call
103+
# write() with the whole body and then finish() straight
104+
# after and so do not trigger the bug.
105+
# return GzipFile(webclient_path) # TODO configurable?
90106
return File(webclient_path) # TODO configurable?
91107

92108
def build_resource_for_static_content(self):
109+
# This is old and should go away: not going to bother adding gzip
93110
return File("static")
94111

95112
def build_resource_for_content_repo(self):
@@ -260,9 +277,12 @@ def start_listening(self):
260277
config,
261278
metrics_resource,
262279
),
263-
interface="127.0.0.1",
280+
interface=config.metrics_bind_host,
281+
)
282+
logger.info(
283+
"Metrics now running on %s port %d",
284+
config.metrics_bind_host, config.metrics_port,
264285
)
265-
logger.info("Metrics now running on 127.0.0.1 port %d", config.metrics_port)
266286

267287
def run_startup_checks(self, db_conn, database_engine):
268288
all_users_native = are_all_users_on_domain(

synapse/appservice/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ def _matches_user(self, event, member_list):
148148
and self.is_interested_in_user(event.state_key)):
149149
return True
150150
# check joined member events
151-
for member in member_list:
152-
if self.is_interested_in_user(member.state_key):
151+
for user_id in member_list:
152+
if self.is_interested_in_user(user_id):
153153
return True
154154
return False
155155

@@ -173,7 +173,7 @@ def is_interested(self, event, restrict_to=None, aliases_for_event=None,
173173
restrict_to(str): The namespace to restrict regex tests to.
174174
aliases_for_event(list): A list of all the known room aliases for
175175
this event.
176-
member_list(list): A list of all joined room members in this room.
176+
member_list(list): A list of all joined user_ids in this room.
177177
Returns:
178178
bool: True if this service would like to know about this event.
179179
"""

synapse/config/metrics.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class MetricsConfig(Config):
2020
def read_config(self, config):
2121
self.enable_metrics = config["enable_metrics"]
2222
self.metrics_port = config.get("metrics_port")
23+
self.metrics_bind_host = config.get("metrics_bind_host", "127.0.0.1")
2324

2425
def default_config(self, config_dir_path, server_name):
2526
return """\
@@ -28,6 +29,9 @@ def default_config(self, config_dir_path, server_name):
2829
# Enable collection and rendering of performance metrics
2930
enable_metrics: False
3031
31-
# Separate port to accept metrics requests on (on localhost)
32+
# Separate port to accept metrics requests on
3233
# metrics_port: 8081
34+
35+
# Which host to bind the metric listener to
36+
# metrics_bind_host: 127.0.0.1
3337
"""

synapse/crypto/keyclient.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
from twisted.internet.protocol import Factory
1919
from twisted.internet import defer, reactor
2020
from synapse.http.endpoint import matrix_federation_endpoint
21-
from synapse.util.logcontext import PreserveLoggingContext
21+
from synapse.util.logcontext import (
22+
preserve_context_over_fn, preserve_context_over_deferred
23+
)
2224
import simplejson as json
2325
import logging
2426

@@ -40,11 +42,14 @@ def fetch_server_key(server_name, ssl_context_factory, path=KEY_API_V1):
4042

4143
for i in range(5):
4244
try:
43-
with PreserveLoggingContext():
44-
protocol = yield endpoint.connect(factory)
45-
server_response, server_certificate = yield protocol.remote_key
46-
defer.returnValue((server_response, server_certificate))
47-
return
45+
protocol = yield preserve_context_over_fn(
46+
endpoint.connect, factory
47+
)
48+
server_response, server_certificate = yield preserve_context_over_deferred(
49+
protocol.remote_key
50+
)
51+
defer.returnValue((server_response, server_certificate))
52+
return
4853
except SynapseKeyClientError as e:
4954
logger.exception("Error getting key for %r" % (server_name,))
5055
if e.status.startswith("4"):

0 commit comments

Comments
 (0)